I have a method I want to import from a DLL and it has a signature of:
BOOL GetDriveLetter(OUT char* DriveLetter)
I’ve tried
[DllImport("mydll.dll")]
public static extern bool GetDriveLetter(byte[] DriveLetter);
and
[DllImport("mydll.dll")]
public static extern bool GetDriveLetter(StringBuilder DriveLetter);
but neither returned anything in the DriveLetter variable.
It appears the function
GetDriveLetteris expecting achar*which points to sufficient memory to contain the drive letter.I think the easiest way to approach this problem is to pass a raw
IntPtrand wrap the calls toGetDriveLetterin an API which takes care of the resource management and conversion to astring.