简体   繁体   English

调用dll中的另一个函数会导致访问冲突

[英]call to another function in a dll causes access violation

okay so I'm starting to realize that dll arn't the simplest of things to understand, I'm trying to make a dll which is VC6 compatible, I got some code working in VS2010 but in trying to work out how to get that code to work for a VC6 project I've found the following issue: 好吧,所以我开始意识到dll并不是最简单的东西,我正在尝试制作一个与VC6兼容的dll,我在VS2010中使用了一些代码,但是试图找出如何获得该代码代码可用于VC6项目我发现了以下问题:

My call to the dll looks like this 我对dll的调用如下所示

MyDll::connect(); 

when i try and run a program which uses this function, it starts out fine but as soon as it gets to a function call ie 当我尝试运行一个使用此功能的程序时,它会很好地启动,但是一旦进入函数调用即

VOID connect()
{
hello();    //0xC0000005: access violation
}

VOID hello()
{
    int i = 1;
}

the disassembly looks like this: 拆卸看起来像这样:

->  00000000   ???
    00000001   ???
    00000002   ???
    00000003   ???
    00000004   ???
    00000005   ???
    00000006   ???
    00000007   ???
    00000008   ???
    00000009   ???
    etc...

you didn't exported the function .....a program is not permitted to access a function in a dll unless that function is registered as exported function. 您没有导出函数.....除非该函数被注册为导出函数,否则不允许程序访问dll中的函数。 to do that you should prototype it like this 为此,您应该像这样制作原型

to export a function inside a class this function should 1- be public member. 要在类内导出函数,此函数应为1-是公共成员。 2- be a static member 2-成为静态成员

class MyDll{
   public:
   static void connect();
}
//then redeclare it like this
#ifdef _cplusplus
extern "C"{
#endif
__declspec(dllexport) void  MyDll::connect(){
//TODO
}
#ifdef _cplusplus
}
#endif

do this for any class member function you want to export 对要导出的任何类成员函数执行此操作

this is an example 这是一个例子

Creating a simple Dynamic Link Library example 创建一个简单的动态链接库示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM