Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Windows Services Help (C related)

Thread Tools
 
Search this Thread
 
Old Apr 11, 2006 | 12:50 PM
  #1  
prana's Avatar
prana
Thread Starter
Scooby Regular
 
Joined: Apr 2003
Posts: 341
Likes: 0
From: Sydney, Aust
Default Windows Services Help (C related)

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 ?

#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);
}
}
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
Reply
Old Apr 11, 2006 | 01:08 PM
  #2  
prana's Avatar
prana
Thread Starter
Scooby Regular
 
Joined: Apr 2003
Posts: 341
Likes: 0
From: Sydney, Aust
Default

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.
Reply
Old Apr 11, 2006 | 01:26 PM
  #3  
GaryK's Avatar
GaryK
Scooby Regular
 
Joined: Sep 1999
Posts: 4,037
Likes: 0
From: Bedfordshire
Default

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
Reply
Old Apr 11, 2006 | 07:58 PM
  #4  
molko's Avatar
molko
Scooby Regular
 
Joined: Jun 2004
Posts: 638
Likes: 0
From: UK
Default

#include "Winsvc.h" //Header file for Services.
Reply
Old Apr 11, 2006 | 10:39 PM
  #5  
prana's Avatar
prana
Thread Starter
Scooby Regular
 
Joined: Apr 2003
Posts: 341
Likes: 0
From: Sydney, Aust
Default

thanks a million lads. Will report back when I get a chance ...
Reply
Old Apr 12, 2006 | 10:51 PM
  #6  
prana's Avatar
prana
Thread Starter
Scooby Regular
 
Joined: Apr 2003
Posts: 341
Likes: 0
From: Sydney, Aust
Default

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
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
Nov 4, 2021 07:12 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
Dec 28, 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
Nov 18, 2015 07:03 AM
FuZzBoM
Wheels, Tyres & Brakes
16
Oct 4, 2015 09:49 PM
Ganz1983
Subaru
5
Oct 2, 2015 09:22 AM




All times are GMT +1. The time now is 06:33 PM.