dll工程中导出函数的问题

chenxiaoguo chenxiaoguo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Q1:

sha()函数在sha.cpp中
Lib.cpp中
void callsha(unsigned char *buf, int len, unsigned char *hash);
Lib.h中
#include "sha.h"
__declspec(dllexport)
void callsha(unsigned char *buf, int len, unsigned char *hash);

这样写对不对?有什么问题吗?


Q2:

在C#中调用该函数
[DllImport("Lib.dll", EntryPoint = "callsha", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void callsha(ref byte[] buf, int len, ref byte[] hash);
使用时:
byte[] P = new byte[64];
byte[] hash = new byte[32];
sha1(P, 64, ref hash);

运行时出现以下错误:
The runtime has encountered a fatal error. The address of the error was at 0x79e7c5eb, on thread 0x964. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

是C#代码的原因还是因为上面的dll有问题?

谢谢各位
...全文

相关推荐

评论 18
收藏 已收藏
分享
返回顶部
chenxiaoguo
进程/线程/DLL 15,466 成员 49,169 内容