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.
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)

Postby tdhoward » Fri Oct 09, 2015 12:24 am

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-wxwidgets-windows-service

I hope someone finds it useful!

Tim

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

Re: Windows Service built with wxWidgets (no GUI)

Postby iwbnwif » Sun Oct 11, 2015 9:50 am

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.10, TDM MinGW64 5.1.0, g++ 4.8.2, Ubuntu 16.04LTS, 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)

Postby tdhoward » Mon Oct 12, 2015 3:40 pm

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

evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2072
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Windows Service built with wxWidgets (no GUI)

Postby evstevemd » Tue Oct 20, 2015 12:17 pm

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?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

Gnawer
Experienced Solver
Experienced Solver
Posts: 51
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

Re: Windows Service built with wxWidgets (no GUI)

Postby Gnawer » Wed Oct 21, 2015 2:30 pm

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)

Postby tdhoward » Wed Oct 28, 2015 3:26 pm

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/linux-daemon-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)

Postby tdhoward » Wed Oct 28, 2015 5:49 pm

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


Return to “Announcements and Discoveries”

Who is online

Users browsing this forum: No registered users and 2 guests