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
Windows Service built with wxWidgets (no GUI)
Re: Windows Service built with wxWidgets (no GUI)
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.
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.
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
Re: Windows Service built with wxWidgets (no GUI)
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
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
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Windows Service built with wxWidgets (no GUI)
Do you plan to add ability to run it as *Nix daemon?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.
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?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: Windows Service built with wxWidgets (no GUI)
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.
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?
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
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
Gnawer
Re: Windows Service built with wxWidgets (no GUI)
Yes, I do! It seems like it shouldn't be that hard, after looking at this nicely written HOWTO:evstevemd wrote:Do you plan to add ability to run it as *Nix daemon?
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)
Thanks!Gnawer wrote:Great Code!
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?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.
Tim