Windows Services Help (C related)
#1
Scooby Regular
Thread Starter
Join Date: Apr 2003
Location: Sydney, Aust
Posts: 341
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://www.scoobynet.com/images/icons/icon1.gif)
I'm trying to compile a simple program using LCC Win32 to run as a windows service, but my compiler does not accept it, spitting all sorts of errors. Here is a quick template I took from Microsoft which wont even compile. I havent a clue what is wrong, it doesnt even understand what SERVICE_STATUS or SERVICE_STATUS_HANDLE, let alone compile.... what the hell am I doing wrong ?
This is but one example. It just doesnt like me.
Ultimately, trying to achieve something like a small program to creates a messagewindow "Hello World!" every 10 minutes, and runs as a service, with two threads
#include <stdio.h>
#include <windows.h>
SERVICE_STATUS MyServiceStatus;
SERVICE_STATUS_HANDLE MyServiceStatusHandle;
VOID SvcDebugOut(LPSTR String, DWORD Status);
VOID WINAPI MyServiceCtrlHandler (DWORD opcode);
VOID MyServiceStart (DWORD argc, LPTSTR *argv);
DWORD MyServiceInitialization (DWORD argc, LPTSTR *argv, DWORD *specificError);
void main( )
{
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ "MyService", MyServiceStart },
{ NULL, NULL }
};
if (StartServiceCtrlDispatcher( DispatchTable)==NULL)
{
SvcDebugOut(" [MY_SERVICE] StartServiceCtrlDispatcher (%d)\n",
GetLastError());
}
}
VOID SvcDebugOut(LPSTR String, DWORD Status)
{
CHAR Buffer[1024];
if (strlen(String) < 1000)
{
sprintf(Buffer, String, Status);
OutputDebugStringA(Buffer);
}
}
#include <windows.h>
SERVICE_STATUS MyServiceStatus;
SERVICE_STATUS_HANDLE MyServiceStatusHandle;
VOID SvcDebugOut(LPSTR String, DWORD Status);
VOID WINAPI MyServiceCtrlHandler (DWORD opcode);
VOID MyServiceStart (DWORD argc, LPTSTR *argv);
DWORD MyServiceInitialization (DWORD argc, LPTSTR *argv, DWORD *specificError);
void main( )
{
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ "MyService", MyServiceStart },
{ NULL, NULL }
};
if (StartServiceCtrlDispatcher( DispatchTable)==NULL)
{
SvcDebugOut(" [MY_SERVICE] StartServiceCtrlDispatcher (%d)\n",
GetLastError());
}
}
VOID SvcDebugOut(LPSTR String, DWORD Status)
{
CHAR Buffer[1024];
if (strlen(String) < 1000)
{
sprintf(Buffer, String, Status);
OutputDebugStringA(Buffer);
}
}
Ultimately, trying to achieve something like a small program to creates a messagewindow "Hello World!" every 10 minutes, and runs as a service, with two threads
#2
Scooby Regular
Thread Starter
Join Date: Apr 2003
Location: Sydney, Aust
Posts: 341
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://www.scoobynet.com/images/icons/icon1.gif)
Just a bit more info, it doesnt have a clue of the declaration type "SERVICE_STATUS_HANDLE" or "SERVICE_STATUS " and it doesnt know "StartServiceCtrlDispatcher" so I am gathering that I am missing a core library file to support WIndows Services.
#3
Scooby Regular
Join Date: Sep 1999
Location: Bedfordshire
Posts: 4,037
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://www.scoobynet.com/images/icons/icon1.gif)
Its likely that SERVICE_STATUS and SERVICE_STATUS_HANDLE are just DWORDs or int values but are probably defined in a header file that you are not linking in. Best bet is to find where they are defined (search google groups is best bet) and get all your file dependancies sorted.
If your end result is that you need to create windows service app then you might be better off using a tool which shields you from the complexities of creating the service wrapper, Delphi lets you create service and service controller apps real easy and I would be surprised if c#.net didnt also.
Gary
If your end result is that you need to create windows service app then you might be better off using a tool which shields you from the complexities of creating the service wrapper, Delphi lets you create service and service controller apps real easy and I would be surprised if c#.net didnt also.
Gary
#6
Scooby Regular
Thread Starter
Join Date: Apr 2003
Location: Sydney, Aust
Posts: 341
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://www.scoobynet.com/images/icons/icon1.gif)
Well this may come in handy for someone else in the future.
Yes, the correct service to include was winsvc.h. However, you should also remember that winsvc.h requires windows.h before the include winsvc.h or it will fail. Its a dependancy.
After that, all errors disappeared. Thanks GaryK and Molko
Yes, the correct service to include was winsvc.h. However, you should also remember that winsvc.h requires windows.h before the include winsvc.h or it will fail. Its a dependancy.
After that, all errors disappeared. Thanks GaryK and Molko
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM