嗨,我有一个DLL,我需要调用一个函数.签名是:
const char* callMethod(const char* key, const char* inParams);
Run Code Online (Sandbox Code Playgroud)
如果我使用ruby一切正常:
attach_function :callMethod, [:string, :string], :string
Run Code Online (Sandbox Code Playgroud)
如果我使用C++或C#,我会得到堆栈溢出!
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
Run Code Online (Sandbox Code Playgroud)
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) …Run Code Online (Sandbox Code Playgroud)