I'm having a huge problem trying to learn how to export classes from a DLL.
I can do some functions just fine but the classes are mangled :S
I've tried from .def file, I've used extern "C" but when I did, it threw errors and won't export the class at all.
In codeblocks it won't create a .lib file so I tried linking the .a file but that still doesn't work. I'm not sure what to do. I'd probably prefer either loadlibrary or .lib but I want to learn how to do it via a .def file.
Exports.hpp
#ifndef EXPORTS_HPP_INCLUDED
#define EXPORTS_HPP_INCLUDED
#define EXPORT __declspec(dllexport)
class EXPORT Point; //Forward declaration of a class I want to export. This is all I did.
#endif // EXPORTS_HPP_INCLUDED
Systems.hpp
#ifndef SYSTEM_HPP_INCLUDED
#define SYSTEM_HPP_INCLUDED
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0500
#include <Windows.h>
#include <TlHelp32.h>
#include <iostream>
#include "Strings.hpp"
#include <Time.h>
#include <vector>
#include "Exports.hpp"
EXPORT DWORD SystemTime();
EXPORT DWORD GetTimeRunning();
EXPORT DWORD TimeFromMark(int TimeMarker);
EXPORT std::string TheTime();
EXPORT int AddOnTermination(void(*function)(void));
EXPORT std::string GetEnvironmentVariables(const std::string Variable);
EXPORT void SetTransparency(HWND hwnd, BYTE Transperancy = 0);
#endif // SYSTEM_HPP_INCLUDED
Then in the CPP file I just have the definitions of each of those functions. They don't have the EXPORT infront of them.
For classes I just forward declare them in the Exports header and put export betwee class and the classname.
My Main file looks like:
#include "System.hpp" //File that includes the exports.
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
I have around 200 classes to export and about 300 functions. I don't mind exporting the functions one by one or using a def file with ordinal exportation but I have no clue how to do the classes.
Any idea? How do I write the typedef for a class? Am I exporting them right?