-
July 7th, 2014, 03:27 AM
#1
PInvoke a C++ unsigned char [][] to C#?
The C++ structure like that:
typedef struct d_setting
{
unsigned short setting1;
unsigned char name[100][200];
}D_SETTING;
typedef struct d_config
{
unsigned short data;
D_SETTING setting;
}D_CONFIG;
And i tried to call the C++ function by creating the corresponding structure in C# like:
[StructLayout(LayoutKind.Sequential)]
public struct D_SETTING
{
public ushort setting1;
public byte[][] name;
}
[StructLayout(LayoutKind.Sequential)]
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++??
Thanks.
-
July 8th, 2014, 09:55 PM
#2
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
anyways
you might be able to find a example here that already does it.
or something close enough you can use to do it.
http://www.pinvoke.net/search.aspx?search=array&namespace=[All]
this is a pretty tough question. here is a similar one
http://social.msdn.microsoft.com/For...-jagged-arrays
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 10:48 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|