Creating A DLL Of An Application
From WxWiki
Contents[hide] |
Creating a wxWidgets DLL application
Basically you need to define:
- dllmain()
wxInitialize()(instead of wxEntry)
- wxTheApp->OnExit()
wxUninitialize()
These functions may be found in app.cpp. There are 2 definitions based on the _WINDLL ifdef. Information may also be found by reading:
- wx2/src/makefile.vc
- wx2/src/makevc.env
- wx2/src/msw/makefile.vc
Remember to use a .def-file or WXEXPORT with the classes/functions you need to export.
This did not work for me (mimo_at_gn.apc.org). Maybe you can add some more. I am trying to get hold of this guy -> Slavek who seems to have found a work around and planned to write a HOWTO. An example in this place would be very helpful.
Examples
wxjs is said to be a good example of how to make a wxWidgets DLL
A simple example is available here: fromdll.zip
The fromdll.zip example above is compatible with wxWidgets versions up to and excluding 2.5.4, follow the link below for an example of a DLL application which links to more recent versions of wxWidgets:
http://wxforum.shadonet.com/viewtopic.php?p=5964#5964
Problems
Problems are reported with wxThread internal initialisation.
Also the 2.5.2 release has wxEntry decleration issues. Get the fixed app.h files from CVS for now.
This appear to be broken in 2.5.3, could someone do a update with the proper way to do this now.
Creating a wxWidgets DLL application with wxWidgets 2.6.2, with GUI support
Here is a simple example which allows you to store some dialogs in a wxWidgets DLL application the 2.6.2 way, and use that DLL in any other language. That code is directly insipired from fromdll.zip example above.
Header file : wxWidgetsDLL.h
#ifndef wxWidgetsDLLH #define wxWidgetsDLLH #pragma once /*This is the method i use to link the libs to my DLL project in c++ builder 6, not used with eg. mingw32/dev-cpp if anybody has a hint on c++ builder 6 linking, just tell me */ #ifdef CBUILDER #pragma link "wxzlib.lib" #pragma link "wxmsw26.lib" #endif #include "wx/wx.h" #include <windows.h> #include <process.h> HANDLE ThreadId; class wxDLLApp : public wxApp { bool OnInit(); }; #endif wxWidgetsDLLH
Source file : wxWidgetsDLL.cpp
Creating A DLL Of An Application
From WxWiki
Jump to: navigation, search
Contents [hide]
1 Creating a wxWidgets DLL application
2 Examples
3 Problems
4 Creating a wxWidgets DLL application with wxWidgets 2.6 . 2 , with GUI support
[edit]Creating a wxWidgets DLL application
Basically you need to define:
dllmain()
wxInitialize()(instead of wxEntry)
wxTheApp -> OnExit()
wxUninitialize()
These functions may be found in app.cpp. There are 2 definitions based on the _WINDLL ifdef. Information may also be found by reading:
wx2 / src / makefile.vc
wx2 / src / makevc.env
wx2 / src / msw / makefile.vc
Remember to use a .def - file or WXEXPORT with the classes / functions you need to export.
This did not work for me (mimo_at_gn.apc.org). Maybe you can add some more. I am trying to get hold of this guy -> Slavek who seems to have found a work around and planned to write a HOWTO. An example in this place would be very helpful.
[edit]Examples
wxjs is said to be a good example of how to make a wxWidgets DLL
A simple example is available here: fromdll.zip
The fromdll.zip example above is compatible with wxWidgets versions up to and excluding 2.5 . 4 , follow the link below for an example of a DLL application which links to more recent versions of wxWidgets:
http: // wxforum.shadonet.com/viewtopic.php?p=5964#5964
[edit]Problems
Problems are reported with wxThread internal initialisation.
Also the 2.5 . 2 release has wxEntry decleration issues. Get the fixed app.h files from CVS for now.
This appear to be broken in 2.5 . 3 , could someone do a update with the proper way to do this now.
[edit]Creating a wxWidgets DLL application with wxWidgets 2.6 . 2 , with GUI support
Here is a simple example which allows you to store some dialogs in a wxWidgets DLL application the 2.6 . 2 way, and use that DLL in any other language. That code is directly insipired from fromdll.zip example above.
Header file : wxWidgetsDLL.h
#ifndef wxWidgetsDLLH
#define wxWidgetsDLLH
#pragma once
/* This is the method i use to link the libs to my DLL project in c++ builder 6, not used with eg. mingw32/dev-cpp
if anybody has a hint on c++ builder 6 linking, just tell me
*/
#ifdef CBUILDER
#pragma link "wxzlib.lib"
#pragma link "wxmsw26.lib"
#endif
#include " wx/wx.h "
#include < windows.h >
#include < process.h >
HANDLE ThreadId;
class wxDLLApp : public wxApp
{
bool OnInit();
};
#endif wxWidgetsDLLH
Source file : wxWidgetsDLL.cpp
#include " wx/wx.h "
#include < process.h >
#include " Unit1.h "
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
wxApp::SetInstance( new wxDLLApp());
wxEntry(GetModuleHandle(NULL),NULL,NULL,SW_SHOW);
return true ;
}
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
ThreadId = CreateThread(NULL, 0 ,ThreadProc,NULL, 0 ,NULL);
break ;
case DLL_THREAD_ATTACH: break ;
case DLL_THREAD_DETACH: break ;
case DLL_PROCESS_DETACH:
wxEntryCleanup();
break ;
}
return TRUE;
}
// I could have #define MYEXPORT __stdcall __declspec(dllexport) but it works that way too...
extern " C " __stdcall __declspec(dllexport) void DLLFunction(HWND handle)
{
wxDialog * dlg = new wxDialog(NULL, - 1 , " Hello World From DLL " ,wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE,wxDialogNameStr);
dlg -> Show();
}
bool wxDLLApp::OnInit()
{
return true ;
}
I hope this helps, actually it worked for me, i ran some tests with the dll linked with a Delphi application, and the dialog box shows up. But please note that there are some issues when linking your DLL statically with wxWidgets. What i did is linking my DLL dynamically with wxWidgets, it seemed to solve all application initialization errors, so don ' t forget to define WXUSINGDLL in your compiler ' s settings, and compile your wxWidgets libs dynamically, at least for making wxWidgets DLLs.
Any feedback / comments : tomprod at wanadoo dot fr
Retrieved from " http://www.wxwidgets.org/wiki/index.php/Creating_A_DLL_Of_An_Application "
I hope this helps, actually it worked for me, i ran some tests with the dll linked with a Delphi application, and the dialog box shows up. But please note that there are some issues when linking your DLL statically with wxWidgets. What i did is linking my DLL dynamically with wxWidgets, it seemed to solve all application initialization errors, so don't forget to define WXUSINGDLL in your compiler's settings, and compile your wxWidgets libs dynamically, at least for making wxWidgets DLLs.
Any feedback/comments : tomprod at wanadoo dot fr