简体   繁体   中英

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:

My call to the dll looks like this

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. to do that you should prototype it like this

to export a function inside a class this function should 1- be public member. 2- be a static member

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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