我使用 PInvoke Interop Assistant 生成 C# PInvoke 签名。我想确认这一点。我在调用 DLL 时收到“找不到 PInvoke DLL”消息。我正在导出该函数。 DLL 与可执行文件一起存在。消息和密文是原始字节的输入/输出 blob,并且是相同的缓冲区。
extern "C" int __declspec(dllexport) EncryptDeviceName(uint8 *message, uint8 *ciphertext, uint64 msglength)
{
...
return 0;
}
它生成了以下 C# PInvoke 签名:
/// Return Type: int
///message: UINT8*
///ciphertext: UINT8*
///msglength: UINT64->unsigned __int64
[DllImport("HC128.dll", EntryPoint = "EncryptDeviceName")]
public static extern int EncryptDeviceName(System.IntPtr message, System.IntPtr ciphertext, ulong msglength);
我将遵循以下建议 similar question并提供更新。
更新
我的签名确实可以在 Windows CE 6 上使用 marshal alloc/dealloc 运行。 Tergiver 的签名也适用于 Windows CE 6,并且不需要 marshal alloc/dealloc。
最佳答案
您缺少CallingConvention.Cdecl
。或者使用__stdcall
在C端。
关于c# - 此 C 函数的正确 C# PInvoke 签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11639680/