views:

537

answers:

2

I am doing a dllImport on a C++ dll and I have the following signature. StackOverflow has been very helpful so far, so I thought I'd throw this one and see what I get.

Are there any gotchas that I should be worried about? This is my first time using dllimport.

I need to import the following to C#:

HANDLE FooInit(char* name); //name appears to be a string like "COM1"

int Foo1(HANDLE handle, const char** sentence); //sentence appears to be a string like "Hello World"

int Foo2(HANDLE handle, DWORD* val);

Thanks very much!

A: 

At first glance, I would expect you'd use IntPtr for all of your parameters and the HANDLE return type, and int for Foo1 and Foo2's return values.

Joe
HANDLE and DWORD*, I'm not too worried about, but I don't know where to begin with the const char** argument
MedicineMan
If the sentence variable is an [out] param, pass a StringBuilder reference. For char * you can just pass a string.
scottm
+2  A: 

Check out the P/Invoke Cheat Sheet (not complete, but a quick reference). char * usually becomes string. const char ** is trickier as I can't tell by looking at it whether it's a pointer to a single string or an array of strings.

plinth