I am calling a DLL using PInvoke. The DLL’s function returns a C string in codepage 437.
Is there a way to have the .Net marshaling convert the string to unicode, or could someone suggest which parameters I should give to DllImport() and MarshalAs() and a conversion function to use in order to get an output in unicode?
For reference, this is the DllImport that I currently use:
[DllImport("name.dll", CharSet=CharSet.Unicode) ]
internal static extern int GetSweepParam(
int param_num,
[Out,MarshalAs(UnmanagedType.LPStr)]StringBuilder param_name,
[Out,MarshalAs(UnmanagedType.LPStr)]StringBuilder param_units,
double[] values,
[MarshalAs(UnmanagedType.LPStr)]StringBuilder error_string
);
ANSI string marshalling always uses the system default encoding. If you want to use some other encoding, then you can marshal those strings yourself.
If the string is allocated by the unmanaged function, then you can marshal it from an
IntPtr.