Y
Yannick S.
Hi all,
I want to re-use what I have written in C/C++ in a C# projet (Compact
framework).
In the C/C++ project :
I have a dll : myDll.dll
I have a struct : myStruct
I have a function : myFunction
typedef struct myStruct
{
char* a;
char* b;
} myStruct;
extern "C" MYDLL_DLL_API int myFunction(myStruct *pMyStruct){
pMyStrunct.a = new char[36];
return 1;
}
How do I do to make it work in my C# programm ?
I have try several way but the only I found is to use unsafe code:
[StructLayout(Layout.Sequential)]
public unsafe class MyStruct
{
char *a;
char *b
}
[DllImport("MyDll.dll")]
public static extern int myFunc([In,Out] ref MyStruct);
but when I call myFunc in a C# prog :
MyStruct ms = new MyStruct();
myFunc(ref ms);
after that ms value null.
How is it possible ? How can I make to call a dll function that take a
structure in parameters and that structure has a string field. It is for the
compact framework, so the MarshalAs does not exit, and the Charset param in
the Structlayout does not exist.
thx for your help.
I want to re-use what I have written in C/C++ in a C# projet (Compact
framework).
In the C/C++ project :
I have a dll : myDll.dll
I have a struct : myStruct
I have a function : myFunction
typedef struct myStruct
{
char* a;
char* b;
} myStruct;
extern "C" MYDLL_DLL_API int myFunction(myStruct *pMyStruct){
pMyStrunct.a = new char[36];
return 1;
}
How do I do to make it work in my C# programm ?
I have try several way but the only I found is to use unsafe code:
[StructLayout(Layout.Sequential)]
public unsafe class MyStruct
{
char *a;
char *b
}
[DllImport("MyDll.dll")]
public static extern int myFunc([In,Out] ref MyStruct);
but when I call myFunc in a C# prog :
MyStruct ms = new MyStruct();
myFunc(ref ms);
after that ms value null.
How is it possible ? How can I make to call a dll function that take a
structure in parameters and that structure has a string field. It is for the
compact framework, so the MarshalAs does not exit, and the Charset param in
the Structlayout does not exist.
thx for your help.