小编Joa*_*oao的帖子

从C++,C#和ruby调用ac dll

嗨,我有一个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)

c# c++ ruby

10
推荐指数
1
解决办法
688
查看次数

标签 统计

c# ×1

c++ ×1

ruby ×1