Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
此C函数的正确C#PInvoke签名_C#_C++_Windows Mobile_Pinvoke - Fatal编程技术网

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

此C函数的正确C#PInvoke签名,c#,c++,windows-mobile,pinvoke,C#,C++,Windows Mobile,Pinvoke,我已经使用PInvoke互操作助手生成了一个C#PInvoke签名。我想确认一下。调用DLL时,我收到“找不到PInvoke DLL”消息。我正在导出函数。DLL与可执行文件一起存在。消息和密文是原始字节的输入/输出blob,并且是相同的缓冲区 extern "C" int __declspec(dllexport) EncryptDeviceName(uint8 *message, uint8 *ciphertext, uint64 msglength) { ... retu

我已经使用PInvoke互操作助手生成了一个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);
我将遵循下面的建议并提供更新

更新


我的签名在Windows CE 6上使用marshal alloc/dealloc确实有效。Tergiver的签名也适用于Windows CE 6,它不需要封送alloc/dealloc。

有许多方法可以编写p/Invoke声明。给定的一个可以使用,但是它需要您为它执行封送拆收器的工作(分配非托管内存、复制和执行字符编码转换)

该本机声明没有提供足够的信息来猜测所需的编组,这可能就是它不存在的原因

本机函数在
消息中需要什么字符编码?
ciphertext
是一块原始字节还是也有字符编码(输入和输出)

已更新

如果
消息
密文
都是原始字节数组,我们可以将它们编组为

[DllImport("HC128.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "EncryptDeviceName")]
 public static extern int EncryptDeviceName([In] byte[] message, [In, Out] byte[] ciphertext, ulong msglength);

[Attribute]
中的
和[Attribute]
中的
告诉封送员执行复制的方式
[In,Out]
是默认值,我希望是显式的。

您缺少调用Convention.Cdecl的
。或者在C端使用
\uu stdcall

您检查过这些链接吗?消息和密文是一团原始字节更新:我的签名在WindowsCE6上使用封送alloc/dealloc确实有效。此外,你的签名也很有效。但是,您的签名是否仍然需要marshal alloc/dealloc?@PeterArandorenko否,alloc/dealloc是自动为您处理的,这就是为什么它是一个“更好”的签名。