Problem with Marshalling char* in c#
Posted
by chrmue
on Stack Overflow
See other posts from Stack Overflow
or by chrmue
Published on 2010-04-24T17:45:58Z
Indexed on
2010/04/24
17:53 UTC
Read the original article
Hit count: 383
I have a problem calling this function from a c++ DLL in c#
INT32 WINAPI PM_COM_GetText(INT32 TextId, char* pBuf, INT32 BufSize);
It writes a Text in a buffer for a given text id. I try to call it with the following c# code, but I constantly get an access violation and don't undrestand why:
public string GetText(Int32 TextId)
{
Int32 BufSize = 256;
StringBuilder Str = new StringBuilder(BufSize);
PM_COM_GetText(TextId, Str, BufSize);
return Str.ToString();
}
[DllImport("ComDll.dll", CharSet = CharSet.Ansi)]
private static extern Int32 PM_COM_GetText(Int32 TextId, StringBuilder Str, Int32 BufSize);
I don't see what's wrong, it looks to me like many other code snippets I found in the web.
Any ideas? Thanks in advance!
© Stack Overflow or respective owner