July 7th, 2014, 04:27 AM
PInvoke a C++ unsigned char  to C#?
The C++ structure like that:
typedef struct d_setting
unsigned short setting1;
unsigned char name;
typedef struct d_config
unsigned short data;
And i tried to call the C++ function by creating the corresponding structure in C# like:
public struct D_SETTING
public ushort setting1;
public byte name;
public struct D_CONFIG
public ushort data;
public D_SETTING setting;
But the name is not correct, the program crash..
How could i create the structure for unsigned char in C++??
July 8th, 2014, 10:55 PM
Re: PInvoke a C++ unsigned char  to C#?
well i normally stay away from pinvoke questions
as i in general i don't really like to use it.
and though its been a very long time since i played around with c++
don't you have define at least one dimension not 100% on that
are you sure that code actually compiles in c c++.
cause wouldn't you be calling a undeclared 2d array of uninitialized references
you might be able to find a example here that already does it.
or something close enough you can use to do it.
this is a pretty tough question. here is a similar one
and if you read to the bottom of that link, you should also note.
Please note the "char" type in C takes 1 byte, "char" in C# takes two bytes, therefore you need to use byte in C#
Last edited by willmotil; July 8th, 2014 at 11:48 PM.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!