I know this has already been discussed but after 3days I haven't figured out why I keep getting a blank string after calling a C function wrapped in a DLL in C# :
[DllImport(DllName, CharSet = CharSet.Ansi)]
public static extern int QA_FormatExample(int viHandle, int viExample [MarshalAs(UnmanagedType.LPStr)]StringBuilder rsComment)
In Main :
StringBuilder rsComment = new StringBuilder(256);
apiWrap.QA_FormatExample(currentInstance, viExample, rsComment);
System.Diagnostics.Debug.WriteLine(rsComment);
Function's signature :
int __stdcall QA_FormatExample(int, int, char*);
The function QA_FormatExample initializes rsComment once called but I keep getting rsComment blank. Any suggestion would be really appreciated, thank you.
cdeclcalling convention, C# defaults tostdcall-- If you haven't specified__stdcallas the calling convention in the C function then you have to specifyCallingConvention.Cdeclin theDllImportdecoration.