Passing parameter from VB .Net to C (structure) -


i'm trying pass 1 structure vb c.

this structure has 2 members. problem first member maintain value.

i guess that's problem size of each member, don't know how solve.

example , code:

vb .net code:

<dllimport("usermode_c.dll")> _ shared sub someexample(byval handleofsomething intptr, byref filter __structure) end sub   <structlayout(layoutkind.sequential)> _     structure __structure         <marshalas(unmanagedtype.u8)> public usbserial ulong         <marshalas(unmanagedtype.u8)> public usbtype ulong end structure  dim buffer new __structure buffer.usbserial = 123456 buffer.usbtype = 8  device = 123456  someexample(device, buffer) 

c code:

typedef struct __structure{       ulong  usbserial;       ulong  usbtype; }__structure, *__structure;  #define dllexport __declspec(dllexport)   extern_c {        dllexport void someexample(handle handleofsomething, __structure* filter)       {            //            // here have            //   filter.usbserial = 123456            //   filter.usbtype = 0        <<<--- wrong! sent 8.            /* ... */       } } 

the ulong type in vb.net 64-bit (8-byte) unsigned integer. on windows, ulong type in c 32-bit (4-byte) unsigned integer (half size of vb.net data type).

to fix it, change structure to, use uinteger type unmanagedtype.u4, this:

<structlayout(layoutkind.sequential)> structure __structure     <marshalas(unmanagedtype.u4)> public usbserial uinteger     <marshalas(unmanagedtype.u4)> public usbtype uinteger end structure 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -