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.
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.
It's a class, not a struct. Try removing "ref". Also instead are you sure
your unmanaged code uses ANSI (vs Unicode)?
--
Alex Feinman
---
Visit http://www.opennetcf.org
"Yannick S." <y.schmieder_nospam@swinnovation_nospam.com> wrote in message
news:eaCoKg2uEHA.2804@TK2MSFTNGP14.phx.gbl...
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
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.
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.
Yannick S.
you are right, that was the ref. I am sure I use ANSI.
The real function of myFunc is to get a array of myStruct generated in the dll. myStruct contains several field like variable size char.
PS: Alex I use you CFLauncher and it is very usefull ;)
"Alex Feinman [MVP]" a écrit dans le message de news:
It's a class, not a struct. Try removing "ref". Also instead are you sure your unmanaged code uses ANSI (vs Unicode)?
-- Alex Feinman --- Visit http://www.opennetcf.org "Yannick S." wrote in message news:
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
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.
you are right, that was the ref.
I am sure I use ANSI.
The real function of myFunc is to get a array of myStruct generated in the
dll. myStruct contains several field like variable size char.
PS: Alex I use you CFLauncher and it is very usefull ;)
"Alex Feinman [MVP]" <public_news@alexfeinman.com> a écrit dans le message
de news: O0QyAJ7uEHA.1300@TK2MSFTNGP14.phx.gbl...
It's a class, not a struct. Try removing "ref". Also instead are you sure
your unmanaged code uses ANSI (vs Unicode)?
--
Alex Feinman
---
Visit http://www.opennetcf.org
"Yannick S." <y.schmieder_nospam@swinnovation_nospam.com> wrote in message
news:eaCoKg2uEHA.2804@TK2MSFTNGP14.phx.gbl...
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
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.
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.