L
Lcubed
Does anyone know of any good ways at all to pass strings from a C++
DLL to a C# app using .NET CF??
I've tried several things, One of my attempts was this:
// EXTREMELY simplified C++ function in DLL
LPWSTR CInterfaceLayerApp::SendAStringToCSharp()
{
return (LPWSTR) "String for C#";
}
// C# app - again simplified
[DllImport("InterfaceLayer.dll")]
[return: MarshalAs(UnmanagedType.LPWStr)]
static extern String SendAStringToCSharp();
// as called from C# function
String GetTheString = SendAStringToCSharp(); // function returns null
// if the DLL sends a char * then I receive the first char only
I need to have several functions that return strings so was hoping for
a safe, efficient way to do this.
Is there a best way (fastest, most efficient, least likely to cause
memory leakage) to pass strings from the unmanaged C++ DLL to the C#
application?
The strings can be in any format on the C++ side (char *, LPWSTR, even
ATL CString, etc), but I will need them to be Strings in the C# app.
I'm working with .NETCF 2.0.
I see a lot of PInvoke information but very little seems to be
available on how to handle return strings from unmanaged DLLs.
Any input or ideas sincerely and very much appreciated.
DLL to a C# app using .NET CF??
I've tried several things, One of my attempts was this:
// EXTREMELY simplified C++ function in DLL
LPWSTR CInterfaceLayerApp::SendAStringToCSharp()
{
return (LPWSTR) "String for C#";
}
// C# app - again simplified
[DllImport("InterfaceLayer.dll")]
[return: MarshalAs(UnmanagedType.LPWStr)]
static extern String SendAStringToCSharp();
// as called from C# function
String GetTheString = SendAStringToCSharp(); // function returns null
// if the DLL sends a char * then I receive the first char only
I need to have several functions that return strings so was hoping for
a safe, efficient way to do this.
Is there a best way (fastest, most efficient, least likely to cause
memory leakage) to pass strings from the unmanaged C++ DLL to the C#
application?
The strings can be in any format on the C++ side (char *, LPWSTR, even
ATL CString, etc), but I will need them to be Strings in the C# app.
I'm working with .NETCF 2.0.
I see a lot of PInvoke information but very little seems to be
available on how to handle return strings from unmanaged DLLs.
Any input or ideas sincerely and very much appreciated.