0

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 i.e.

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...
Perry Ward
  • 15
  • 4
  • Build debug versions of both the DLL and the program using the DLL, and run in a debugger. – Some programmer dude Aug 18 '14 at 09:46
  • Both are built in debug not sure what you mean by run in a debugger exactly other than the debug you get when it falls over... – Perry Ward Aug 18 '14 at 09:52
  • Are you building a DLL in one version of VC++ and then calling it from a programme written in another version? I think that's what I've understood. The problem is likely to be that they are using different versions of the Visual C++ Runtime. – Tom Aug 18 '14 at 10:17
  • Nope they are both VC6, I had originally started writing the dll in VS2010 but in my quest to track down the access violation, I wrote it in VC6 instead. – Perry Ward Aug 18 '14 at 10:24

1 Answers1

1

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