dll工程中导出函数的问题
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有问题?
谢谢各位
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有问题?
谢谢各位
...全文
相关推荐
DLL中的函数查看工具
用于查看DLL中的函数,解析DLL中的函数!
dllexportviewer:动态链接库导出函数分析工具详解
动态链接库(Dynamic Link Library,简称 DLL)是 Windows 操作系统中实现模块化编程、代码共享和资源复用的核心机制之一。与静态链接将所有依赖代码在编译期打包进可执行文件不同,动态链接通过在运行时按需加载共享库的方式,实现了更高的内存利用率、更灵活的更新策略以及更强的组件解耦能力。本章将系统性地阐述动态链接的基本原理,深入剖析 DLL 的生成方式、导出机制、加载流程及其依赖管理,并探讨其在工程实践中的价值与潜在挑战。除了使用__declspec,还可通过.def。
查看dll中导出函数的工具
超有用的查看dll中导出函数的工具,该工具比C++自带Depends更好用,可以帮助你查询其中的函数,绝对超值!
dll查看器,查看dll中函数名称等
dll查看器,dllexp,方便查看低利率名称
DLL Export Viewer v1.11
DLL 函数 查看器


进程/线程/DLL
