Passing a System::String* to a win32 API

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can pass a System::String* variable to a Win32 API? how can I convert the System::String* to LPCSTR ????
 
Nadav said:
Use
const wchar_t __pin* pUnmanagedString = PtrToStringChars(pManagedString);

Nadav.

This is only suitable *IF* the string is temporarily referenced (and then
unreferenced and released). Otherwise, the string is 'pinned' in the heap, and
can lead to sandbar and similar fragmentation issues in the GC heap.
 
Heres an example prototype to call a Windows API function

[DllImport("kernel32", CharSet=CharSet::Auto)
Int32 WritePrivateProfileString(String* pAppName, String* pKeyName, String* pString, String *pFilename);
 
Back
Top