I am trying to write C # code that calls a method from an unmanaged DLL. The prototype of the function in the dll is:
extern "C" __declspec(dllexport) char *foo(void);
In C #, I first used:
[DllImport(_dllLocation)] public static extern string foo();
It seems to work on the surface, but at runtime I get errors in memory corruption. I think that I am pointing to a memory that is correct, but already freed.
I tried using the PInvoke code utility called "P / Invoke Interop Assistant". This gave me the result:
[System.Runtime.InteropServices.DLLImportAttribute(_dllLocation, EntryPoint = "foo")] public static extern System.IntPtr foo();
It is right? If so, how do I convert this IntPtr to a string in C #?
c # pinvoke
Brandon Dec 15 '08 at 23:42 2008-12-15 23:42
source share