Hi I have a DLL with a function that I need to call. The signature is:
const char* callMethod(const char* key, const char* inParams);
If I use ruby everything works fine:
attach_function :callMethod, [:string, :string], :string
If I use C++ or C# I get stack overflow!?
C#:
[DllImport("DeviceHub.dll", CallingConvention = CallingConvention.Cdecl)]
private unsafe static extern IntPtr callMethod(
[MarshalAs(UnmanagedType.LPArray)] byte[] key,
[MarshalAs(UnmanagedType.LPArray)] byte[] inParams
);
System.Text.UTF8Encoding encoding = new UTF8Encoding();
IntPtr p = callMethod(encoding.GetBytes(key), encoding.GetBytes(args)); // <- stack overflow here
c++:
extern "C"
{
typedef DllImport const char* ( *pICFUNC) (const char*, const char*);
}
HINSTANCE hGetProcIDDLL = LoadLibrary(TEXT("C:\\JOAO\\Temp\\testedll\\Debug\\DeviceHub.dll"));
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"callMethod");* pICFUNC callMethod;
callMethod = (pICFUNC) lpfnGetProcessID;
const char * ptr = callMethod("c", "{}");
I have tried lots of variations for function calling : WINAPI, PASCAL, stdcall, fastcall,... nothing works.
The DLL has not been made by me and I have no control on it.
Can anyone help me with any suggestion!?