wxWidgets independednt static library

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
In need of some credit
In need of some credit
Posts: 1
Joined: Tue Apr 13, 2021 9:18 pm

wxWidgets independednt static library

Post by LPVOID » Wed Apr 14, 2021 4:05 pm

Hello folks :)

Basically I'm trying to make a universal and independent library with a Login() function which will create a modal windoow and return bool value whether login succeeded or not


This is minimal basic code of what I've attempted

The library consists of roughly this structure

Code: Select all

#include "wx/wx.h"

class LoginMain: public wxFrame {

LoginMain::LoginMain() : wxFrame(
	nullptr, // The parent window, which is null in this case because it's the master window
	-1, // The window's ID; -1 is shorthand for "no ID required"
	"Login", // The title of the window
	wxPoint(30, 30), // The coordinates the window should appear at; (0, 0) is the top-left corner of the screen
	wxSize(800, 600) // The size (width, height) of the window
) {}

class LoginApp: public wxApp {
	bool OnInit();
	LoginMain* m_frame1 = nullptr;


bool LoginApp::OnInit() {
	m_frame1 = new LoginMain();

	return true;

Code: Select all

bool Login()
    wxAppBase* loginApp = new LoginApp();
    wxEntry(GetModuleHandle(NULL), NULL, NULL, SW_SHOW);
    if (loginApp.isSuccess())
        return true;
        return false;
And I just statically link this library to whatever app I make and use it at runtime

It works so far with this setup

But I have a strong feeling that I'm doing it utterly wrong way, and eventually I will run into great issues with this approach

Just wanted to know some expert opinions about this case and maybe get some suggestions/advices/critics


User avatar
Posts: 16022
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWidgets independednt static library

Post by doublemax » Wed Apr 14, 2021 10:48 pm

I'm not sure it's going to work that way. All the main applications will have their own event loop which will collide with the wxWidgets event loop in your library. Especially in case 2 where the host application does also use wxWidgets. But in that case you could provide a dedicated call in the library which just opens a dialog without initializing wxWidgets again (because that already happened in the main application). So that might be the easiest case to solve.

For the other cases you might have to move the wxWidgets initialization, and with it its event loop, in a separate thread. The "DLL" sample that comes with wxWidgets demonstrates this.
Use the source, Luke!

Part Of The Furniture
Part Of The Furniture
Posts: 5156
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxWidgets independednt static library

Post by ONEEYEMAN » Wed Apr 21, 2021 7:19 pm

Also, why do you link wxWidgets statically to your DLL?
You already have a DLL which should run its won everything - why not link dynamically?

That way only one wx instance will be in memory and there will be no breakage with updating and everything.

Thank you.

Post Reply