Page 1 of 1

Windows Service built with wxWidgets (no GUI)

Posted: Fri Oct 09, 2015 12:24 am
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

Re: Windows Service built with wxWidgets (no GUI)

Posted: Sun Oct 11, 2015 9:50 am
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.

Re: Windows Service built with wxWidgets (no GUI)

Posted: Mon Oct 12, 2015 3:40 pm
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

Re: Windows Service built with wxWidgets (no GUI)

Posted: Tue Oct 20, 2015 12:17 pm
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?

Re: Windows Service built with wxWidgets (no GUI)

Posted: Wed Oct 21, 2015 2:30 pm
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?

Re: Windows Service built with wxWidgets (no GUI)

Posted: Wed Oct 28, 2015 3:26 pm
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

Re: Windows Service built with wxWidgets (no GUI)

Posted: Wed Oct 28, 2015 5:49 pm
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