Passing a System::String* to a win32 API

G

Guest

How can pass a System::String* variable to a Win32 API? how can I convert the System::String* to LPCSTR ????
 
J

Julie

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.
 
G

Guest

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top