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 11 April 2006, 12:50 PM
  #1  
prana
Scooby Regular
Thread Starter
 
prana's Avatar
 
Join Date: Apr 2003
Location: Sydney, Aust
Posts: 341
Likes: 0
Received 0 Likes on 0 Posts
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
Old 11 April 2006, 01:08 PM
  #2  
prana
Scooby Regular
Thread Starter
 
prana's Avatar
 
Join Date: Apr 2003
Location: Sydney, Aust
Posts: 341
Likes: 0
Received 0 Likes on 0 Posts
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.
Old 11 April 2006, 01:26 PM
  #3  
GaryK
Scooby Regular
 
GaryK's Avatar
 
Join Date: Sep 1999
Location: Bedfordshire
Posts: 4,037
Likes: 0
Received 0 Likes on 0 Posts
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
Old 11 April 2006, 07:58 PM
  #4  
molko
Scooby Regular
 
molko's Avatar
 
Join Date: Jun 2004
Location: UK
Posts: 638
Likes: 0
Received 0 Likes on 0 Posts
Default

#include "Winsvc.h" //Header file for Services.
Old 11 April 2006, 10:39 PM
  #5  
prana
Scooby Regular
Thread Starter
 
prana's Avatar
 
Join Date: Apr 2003
Location: Sydney, Aust
Posts: 341
Likes: 0
Received 0 Likes on 0 Posts
Default

thanks a million lads. Will report back when I get a chance ...
Old 12 April 2006, 10:51 PM
  #6  
prana
Scooby Regular
Thread Starter
 
prana's Avatar
 
Join Date: Apr 2003
Location: Sydney, Aust
Posts: 341
Likes: 0
Received 0 Likes on 0 Posts
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
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
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
FuZzBoM
Wheels, Tyres & Brakes
16
04 October 2015 09:49 PM
Ganz1983
Subaru
5
02 October 2015 09:22 AM



Quick Reply: Windows Services Help (C related)



All times are GMT +1. The time now is 12:59 PM.