c# - 此 C 函数的正确 C# PInvoke 签名

标签 c# c++ windows-mobile pinvoke

我使用 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/

相关文章:

c# - C#和C++ dll-编码字符串

c# - 将 byte[] 转换为字符串并再次返回

c++ - 为什么 Visual Studio 2013 会发出 C4996 错误?

c++ - 在 C++ 中递增和递减全局变量时的竞争条件

jquery - Windows Mobile cordova/phonegap 样式和事件

windows-mobile - 宽度=设备宽度在移动 IE 中不起作用

c# - 使用 MvcMailer 发送电子邮件表单

c++ - 在编译期间初始化 static const std::map?

c# - ffmpeg 在 Windows Mobile 上使用 C#

c# - 修改 XmlDocument 时出现 InvalidOperationException