我正在编写一个必须与 Unity3D (C#) 交互的 C 库,并且在编写我的 PInvoke 调用之一时遇到了问题。
我有以下 c 结构
typedef struct TestStruct
{
const char* Method;
const char* Url;
} TestStruct;
和 C 函数签名
__declspec(dllexport) void __cdecl TestMethod(TestStruct* args)
{
// Do stuff with Method and URL
}
在 C# 中,我像这样创建了结构
[StructLayout(LayoutKind.Sequential)]
public struct TestStruct
{
public string Method;
public string Url;
}
和 PInvoke 签名一样
[DllImport("Test", CallingConvention = CallingConvention.Cdecl)]
private static extern void TestMethod(TestStruct args);
现在,当我在 Win64 上的 Unity 编辑器中运行它时,它工作得很好。但是,当我将它部署到我的 android 设备(我认为是 32 位 ARM 架构的 Nexus 6)时,当它们到达 C 库时,我的测试结构中的 Method 和 Url 属性为空。
奇怪的是,如果我更改我的函数签名以采用完全避免结构的原始参数,它就可以正常工作。
__declspec(dllexport) void __cdecl TestMethod(const char* Method, const char* Url)
{
// Do stuff with Method and URL
}
和
[DllImport("Test", CallingConvention = CallingConvention.Cdecl)]
private static extern void TestMethod(string method, string url);
工作得很好。有谁知道我可能做错了什么?
吃鸡游戏
相关分类