This is windows related stuff, as you don't need these cryptic export definitions on linux (unix?) systems. There you even can overwrite the malloc function to debug memory allocation...
.pro file:
TARGET = mydll
TEMPLATE = lib
CONFIG += dll
win32 {
DEFINES += MYDLL_EXPORTS _MBCS _USRDLL
# would be better to have an rc file to add some descriptions shown in the explorer
# but without win, I do not have an example :p
# RC_FILE = MYDLL.rc
}
SOURCES += mydll.cpp
HEADERS += mydll.h
TARGET = mydll
TEMPLATE = lib
CONFIG += dll
win32 {
DEFINES += MYDLL_EXPORTS _MBCS _USRDLL
# would be better to have an rc file to add some descriptions shown in the explorer
# but without win, I do not have an example :p
# RC_FILE = MYDLL.rc
}
SOURCES += mydll.cpp
HEADERS += mydll.h
To copy to clipboard, switch view to plain text mode
mydll.h:
#ifndef MYDLL_H
#define MYDLL_H
// to know the OS...
#include <QString>
#if( defined Q_OS_WIN32 )
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif
#else
#define MYDLL_API
#endif
#endif
#ifndef MYDLL_H
#define MYDLL_H
// to know the OS...
#include <QString>
#if( defined Q_OS_WIN32 )
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif
#else
#define MYDLL_API
#endif
#endif
To copy to clipboard, switch view to plain text mode
mydll.cpp:
#include "mydll.h"
#ifdef Q_OS_WIN32
#include <windows.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif
#include "mydll.h"
#ifdef Q_OS_WIN32
#include <windows.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif
To copy to clipboard, switch view to plain text mode
Any other header class:
#ifndef EXTENDER_H
#define EXTENDER_H
#include "mydll.h"
class MYDLL_API TMyDllExtender
{
};
#endif
#ifndef EXTENDER_H
#define EXTENDER_H
#include "mydll.h"
class MYDLL_API TMyDllExtender
{
};
#endif
To copy to clipboard, switch view to plain text mode
Program which uses this class:
#include "extender.h"
void main()
{
TMyDllExtender ext;
...
}
#include "extender.h"
void main()
{
TMyDllExtender ext;
...
}
To copy to clipboard, switch view to plain text mode
pro file of this program:
LIBS += -lmydll
LIBS += -lmydll
To copy to clipboard, switch view to plain text mode
Bookmarks