C# Interface for Win32 DLL functions with pointers?

F

Fred West

I am building a C# interface to a 3rd party win32 dll. The win32 function
has the following definition:

extern "C" int __declspec(dllimport) _stdcall w32func(unsigned char id, char
*pname);

Now in my C# class how do I declare the function. So far from the
documentation, I have come up with the following:

[DllImport("theapi.dll", EntryPoint="w32func")]
private static extern unsafe int W32Func(byte board id,
[MarshalAs(UnmanagedType.LPStr)] string name);

Any comments or suggestions are greatly appreciated,

Fred W.
 
N

Nicholas Paldino [.NET/C# MVP]

Fred,

That's the way I would do it. I am curious about is the first parameter
with the name of "board id". That space is going to give you a syntax
error.

Also, you don't need the unsafe modifier. There is nothing about that
declaration that is unsafe.

Hope this helps.
 
F

Fred West

That was just a typo, it should just be "byte id". Thanks

- Fred


Nicholas Paldino said:
Fred,

That's the way I would do it. I am curious about is the first
parameter with the name of "board id". That space is going to give you a
syntax error.

Also, you don't need the unsafe modifier. There is nothing about that
declaration that is unsafe.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Fred West said:
I am building a C# interface to a 3rd party win32 dll. The win32 function
has the following definition:

extern "C" int __declspec(dllimport) _stdcall w32func(unsigned char id,
char *pname);

Now in my C# class how do I declare the function. So far from the
documentation, I have come up with the following:

[DllImport("theapi.dll", EntryPoint="w32func")]
private static extern unsafe int W32Func(byte board id,
[MarshalAs(UnmanagedType.LPStr)] string name);

Any comments or suggestions are greatly appreciated,

Fred W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top