I am learning about data marshalling right now while doing some programming for work.
I have an unmanaged C++ DLL that I need to use in my C# project...so I am creating a wrapper dll that import all the functions I need to use
One function, lets say called myFunc takes in a struct myStruct with a String as a member function
------------------------C++------------------
struct myStruct {
char* hello;
};
void myFunc (myStruct inVariable);
-----------------------------------------------
now in my C# wrapper, I've done:
-----------------------C#--------------------
[StructLayout(LayoutKind.Sequential)]
public struct myStruct {
[MarshalAs(UnamanagedType.LPStr)] String hello;
}
[DllImport("my_dll.dll")]
public static extern void myFunc(myStruct inVariable);
------------------------------------------------
My question is that I've only seen examples where the MarshalAs attribute is used on the dll imported function parameters....since hello is inside of myStruct, is this the proper way to do it?
Will teh strings get converted to LPStr when sent hrough the imported dll?
Thanks for any help
David
I have an unmanaged C++ DLL that I need to use in my C# project...so I am creating a wrapper dll that import all the functions I need to use
One function, lets say called myFunc takes in a struct myStruct with a String as a member function
------------------------C++------------------
struct myStruct {
char* hello;
};
void myFunc (myStruct inVariable);
-----------------------------------------------
now in my C# wrapper, I've done:
-----------------------C#--------------------
[StructLayout(LayoutKind.Sequential)]
public struct myStruct {
[MarshalAs(UnamanagedType.LPStr)] String hello;
}
[DllImport("my_dll.dll")]
public static extern void myFunc(myStruct inVariable);
------------------------------------------------
My question is that I've only seen examples where the MarshalAs attribute is used on the dll imported function parameters....since hello is inside of myStruct, is this the proper way to do it?
Will teh strings get converted to LPStr when sent hrough the imported dll?
Thanks for any help
David