Windows Service built with wxWidgets (no GUI)

Do you like to promote your wxWidgets based application or component!? Post it here and let's see what the critics have to say. Also, if you found that ONE wx component the world needs to know about, put it here for future reference.
Post Reply
tdhoward
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Oct 09, 2015 12:11 am

Windows Service built with wxWidgets (no GUI)

Post by tdhoward »

Since wxWidgets provides lots of very helpful functionality that doesn't require a GUI, it seems reasonable that someone might choose to write a Windows service using wxWidgets.

Here is a sample wxWidgets service, using wxWidgets 3.0 and tested on Windows 7 that I put together in a (hopefully) usable way. When installed, it will start the service on startup without waiting for the user to log in.

https://github.com/tdhoward/sample-wxwi ... ws-service

I hope someone finds it useful!

Tim
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: Windows Service built with wxWidgets (no GUI)

Post by iwbnwif »

Thank you for such an interesting project.

This should also be a reminder when sometimes there is talk to remove some of the non-GUI wxWidgets functionality that services are an important (and very useful) non-GUI class of application.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
tdhoward
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Oct 09, 2015 12:11 am

Re: Windows Service built with wxWidgets (no GUI)

Post by tdhoward »

Glad you find it interesting!

My particular use case started out as a full GUI wxWidgets application, about 20,000 lines of code. Then we needed it to start automatically on boot on a virtual machine without a user logged in... So I really needed something that could take the existing core program and run it as a service without completely replacing everything to do with wxWidgets.

In this service I am using timers, sockets, event handlers, file access, windows registry access, wxString, and probably many other classes that aren't part of a GUI.

Tim
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Windows Service built with wxWidgets (no GUI)

Post by evstevemd »

tdhoward wrote:Since wxWidgets provides lots of very helpful functionality that doesn't require a GUI, it seems reasonable that someone might choose to write a Windows service using wxWidgets.
Do you plan to add ability to run it as *Nix daemon?
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Gnawer
Experienced Solver
Experienced Solver
Posts: 65
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

Re: Windows Service built with wxWidgets (no GUI)

Post by Gnawer »

Great Code!
It solves my Problem to receive an Event when an Admin stops Service in Service Control Manager.
But now I want to extend code for catching socket Events. First of all I added 2 "Binds" in your "BIND EVENT HANDLERS" section.

Code: Select all

enum {
  ID_THREAD = 42,
  ID_SERVER,
  ID_SOCKET
 };
// ...
// BIND EVENT HANDLERS
Bind(wxEVT_THREAD, &MainApp::OnThreadEvent, this, ID_THREAD);
Bind(wxEVT_SOCKET, &MainApp::OnServerEvent, this, ID_SERVER);   // added
Bind(wxEVT_SOCKET, &MainApp::OnSocketEvent, this, ID_SOCKET);  // added
Next I added OnServerEvent() and OnSocketEvent() to my app, almost unmodified from server.cpp (wx sample directory).
Now - after starting - application hangs. It can neither be stopped nor receive socket Events.
Can you give me a hint to add sockets?
Best regards
Gnawer
tdhoward
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Oct 09, 2015 12:11 am

Re: Windows Service built with wxWidgets (no GUI)

Post by tdhoward »

evstevemd wrote:Do you plan to add ability to run it as *Nix daemon?
Yes, I do! It seems like it shouldn't be that hard, after looking at this nicely written HOWTO:
http://www.netzmafia.de/skripten/unix/l ... howto.html

However, my need for that likely won't be until the middle of 2016, so feel free to contribute code in the meantime. :)

Tim
tdhoward
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Oct 09, 2015 12:11 am

Re: Windows Service built with wxWidgets (no GUI)

Post by tdhoward »

Gnawer wrote:Great Code!
Thanks!
Gnawer wrote:...I want to extend code for catching socket Events...
...Next I added OnServerEvent() and OnSocketEvent() to my app, almost unmodified from server.cpp (wx sample directory).
Now - after starting - application hangs. It can neither be stopped nor receive socket Events.
I would suggest calling wxSocketBase::Initialize() and making sure it returns true before using any sockets. I'm guessing that's not the problem, but it would be good to make sure. Also, are you writing to a debug log file so you can determine exactly where you are hanging?

Tim
Post Reply