hello,
i'm working on a way to load a dll i made in C into C#. I made a simple function that returns a string "hello" and C# calls this function and gets the string just fine. I then tried to pass a structure to C#, but this causes errors.
my C code structure
my C# structureCode:typedef struct _MY_STRUCT { int sName; int sPhone; }MY_STRUCT, *LPMY_STRUCT;
Code:public struct MY_STRUCT { public int sName; public int sPhone; }
whenever I call
I get a runtime error: "The structure must not be a value class.Code:MY_STRUCT MyStruct = new MY_STRUCT(); //MessageBox.Show(Marshal.SizeOf(MyStruct).ToString()); //compiler doesnt like this line... Marshal.PtrToStructure(GetString(), MyStruct); MessageBox.Show(MyStruct.sName.ToString()); MessageBox.Show(MyStruct.sPhone.ToString());
Parameter name: structure"
I've also just tried doing this:
but all i get is a runtime error saying type signiture is not compatibleCode:MyStruct = GetString(); //GetString is just the name of the function
by using sizeof, I know that both the C structure and the C# structure are 8 bytes long, but I dont know what else to do (and ive tried everything I could think of)
Please, could someone help me?




Reply With Quote