Hi,
I have created a win32 dll with an exported method.
extern "C" __declspec(dllexport) void LocateAddress(struct stLocateAddressParam arrAddressParam,int nClientType, LPTSTR outptr);
In this method i try to copy some value to the lpstr
strcpy(outptr,ptrTemp);
When I call this method from C++, it works fine. But when I try to call it from
C# using this syntax
[DllImport("xxx.dll", SetLastError = false)]
public static extern void LocateAddress(stLocateAddressParam locatAddressParam, int nClientType,StringBuilder s);
StringBuilder s = new StringBuilder(256);
LocateAddress(stLctAddrParam, 1, s);
the dll crashes at the point of copy( I found after debugging). I do pass other variables like a struct
but they are only input parameters and work well. If I comment the copy line
it works fine. I need to pass the output in a string to C#. From what I know,
it can be done either returning a string or passing a buffer as indicated at
http://msdn2.microsoft.com/en-us/library/s9ts558h.aspx
Am I missing something?
Thanks,
Peeyush