C++ DLL's in a nutshell
Few points...
[list=1][*]Your Dll code is not exporting ...it is trying to import[*]If you use extern "C", you are losing all the namemangling that allows C++ to work.....therefore forget it if you are working with classes in C++ Dlls[*]Your class functions are private by default....therefore you wouldnt be able to call them anyway![/list=1]
Ok......here's and example of how to export a class under VC++
1. The Dll itself
Code:
//MyDll.h
#include <iostream>
using namespace std;
#ifdef IMPORT_DLL
#define DLL_LINK __declspec(dllimport)
#else
#define DLL_LINK __declspec(dllexport)
#endif
class DLL_LINK MyClass
{
public:
void sing();
};
Code:
//MyDll.cpp (short & sweet :))
#include "MyDll.h"
void MyClass::sing(){cout << "Hello Dll!!";}
Now....create that project as a standard Dll prjoject.......In the output, you will get MyDll.lib and MyDll.dll.....now copy the dll, the MyDll.h and the lib to a new standard workspace and use the following code...
2. The App
Code:
//CallMyDllApp.cpp
#pragma comment(lib,"MyDll.lib")//quick way of including libs...
#define IMPORT_DLL //Define this to allow the header to act as an import header
#include "MyDll.h"//From the other project
int main(void){
MyClass mc;
mc.sing();
return 0;
}
This is the way I do it.....works, but you can have your own little tricks to do things too.......it should give you an idea