Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2004

Tip: Looking for answers? Try searching our database.

newbie trying to call into C DLL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Mollaghan - 21 Dec 2004 22:38 GMT
I am trying to call into a C DLL (fglove.dll) using C#.

I would like to call the fdOpen and fdClose methods. I have included
some of the header file.

I am really new to this, so any help would be great.

typedef struct
{
// The contents of this struct are platform-dependent and subject to
// change. You should not manipulate the contents of this struct
directly.
void           *m_pStuff;
} fdGlove;
/*--------------------------------------------------------------------------*/
fdGlove *fdOpen(char *pPort);
int   fdClose(fdGlove *pFG);

Thanks,

John
Alessandro Angeli [MVP::DigitalMedia] - 21 Dec 2004 23:57 GMT
> typedef struct
> {
[quoted text clipped - 3 lines]
> void           *m_pStuff;
> } fdGlove;

/*----------------------------------------------------------
----------------*/
> fdGlove *fdOpen(char *pPort);
> int   fdClose(fdGlove *pFG);

Did you even try to read the documentation on P/Invoke and
the samples in the SDK? This should be what you need:

using System;
using System.Runtime.InteropServices;

public class fglove
{
   [
       DllImport(
           "fglove.dll",
           CallingConvention=CallingConvention.Cdecl,
           ExactSpelling=true,
           CharSet=CharSet.Ansi)
   ]
   public static extern IntPtr fdOpen(string pPort);

   [
       DllImport(
           "fglove.dll",
           CallingConvention=CallingConvention.Cdecl,
           ExactSpelling=true,
           CharSet=CharSet.Ansi)
   ]
   public static extern int fdClose(IntPtr pFG);
}

Since the .h you posted states that you should not know
what's inside an fdGlove struct, you can just reference it
through an opaque pointer.

Signature

// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.