Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the first time for me in this application. link library is only for VC++, so I wrapped it into a library that can use in c#, and then import in c#, I 've tested the function in VC++ it works fine.but in C#, although the return value is 0, I can read nothing, the result is null. hope somebody can help me. thanks in advance.

here is the function in original library header file.

LONG WINAPI mdReceiveEx( LONG, LONG, LONG, LONG, LONG, LPLONG, LPVOID );

and I wrapped in C++

MELFUNC_API long MmdReceiveEx(long path,long netno,long stno,long devtyp,long devno,long size,short *data); long MmdReceiveEx(long path,long netno,long stno,long devtyp,long devno,long size,short *data)// {
long result=mdReceiveEx(path,netno,stno,devtyp,devno,&size,data);
return result; }

and import in c#

[DllImport(@dllname, CallingConvention = CallingConvention.Cdecl)]

static extern int MmdReceiveEx(int path, int netno, int stno, int devtyp, int devno, int size, out short[] data);

and the function be called

int retval2 = MmdReceiveEx(151, 1, 2, 23, 0x00, sizetst, ref buf1);

the retval2 will be 0 and buf1 be null after executed. can anybody help me?
Posted

1 solution

This is the easiest way to make p/invoke declaration: https://visualstudiogallery.msdn.microsoft.com/9CA9D544-05D2-487B-AB49-31851483C1CC[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900