Hi,
I am a C/C++ programmer, but I was asked to update a program that was written in C# to communicate with a device. My knowledge of C# is very basic. The previous version was totally written in C#, but now the API that in fact access the device was changed to C. I found out that I can import the C function APIs by using:
[DllImport("myapi.dll")]
public static extern int myfunct(
[MarshalAs(UnmanagedType.LPTStr)] string lpDeviceName,
IntPtr hpDevice);
In C this function prototype is:
int myFunct( LPTStr lpDeviceName, HANDLE* hpDevice );
Where HANDLE is defined as :
typedef void *HANDLE;
However this function does not work as expected. In fact, in the C# code call what kind of type I should declare and pass to the C# method?
// Later edit I aplogize for the fake answer.
I am facing a new problem now. I have a C structure like:
struct MyStruct
{ unsigned char* ptr;
int ptr_size;}
This pointer filled with values by a C API function, thus in C I only pass to the function a buffer large enough to hold the data.
To convert this to C# way I can do:
[StructLayout(LayoutKind.Sequential)]
public class MyStruct
{ IntPtr ptr;
int size;
};
Now, the odd part comes in. I have a simple C# array as :
byte[] RESET = new byte[]{ 0x00, 0x00, 0x80, 0x00};
OK, now ptr must point to RESET, so how could this be done? Ptr needs to hold the address it self....
Thanks a lot for the help!