LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating NT service

I wrote next sample code, but it can't compile.
What's wrong?
---------
#include
#include
#include


SERVICE_STATUS MyServiceStatus;
SERVICE_STATUS_HANDLE MyServiceStatusHandle;

VOID MyServiceStart (DWORD argc, LPTSTR *argv);
VOID MyServiceCtrlHandler (DWORD opcode);
DWORD MyServiceInitialization (DWORD argc, LPTSTR *argv,
DWORD *specificError);

VOID SvcDebugOut(LPSTR String, DWORD Status)
{
CHAR Buffer[1024];
if (strlen(String) < 1000)
{
sprintf(Buffer, String, Status);
OutputDebugStringA(Buffer);
}
}


void main( )
{
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ "MyService", MyServiceStart }
,
{ NULL, NULL }
};

if (!StartServiceCtrlDispatcher( DispatchTable))
{
SvcDebugOut(" [MY_SERVICE] StartServiceCtrlDispatcher error = %d\n", GetLastError());
}
}
0 Kudos
Message 1 of 2
(3,521 Views)
Does it works better that way

.....
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow) {

SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ "MyService", (LPSERVICE_MAIN_FUNCTION)MyServiceStart},
{ NULL, NULL }
};

if (!StartServiceCtrlDispatcher( DispatchTable))
{
SvcDebugOut(" [MY_SERVICE] StartServiceCtrlDispatcher error = %d\n",
GetLastError());
}

return 0;
}


--
Philippe
Feel free to visit : http://perso.wanadoo.fr/philippe.baucour



"Ville" a écrit dans le message de news:
50650000000800000097810000-1042324653000@exchange.ni.com...
> I wrote next sample code, but it can't compile.
> What's wrong?
> ---------
>
#include
> #include
> #include
>
>
> SERVICE_STATUS MyServiceStatus;
> SERVICE_STATUS_HANDLE MyServiceStatusHandle;
>
> VOID MyServiceStart (DWORD argc, LPTSTR *argv);
> VOID MyServiceCtrlHandler (DWORD opcode);
> DWORD MyServiceInitialization (DWORD argc, LPTSTR *argv,
> DWORD *specificError);
>
> VOID SvcDebugOut(LPSTR String, DWORD Status)
> {
> CHAR Buffer[1024];
> if (strlen(String) < 1000)
> {
> sprintf(Buffer, String, Status);
> OutputDebugStringA(Buffer);
> }
> }
>
>
> void main( )
> {
> SERVICE_TABLE_ENTRY DispatchTable[] =
> {
> { "MyService", MyServiceStart },
> { NULL, NULL }
> };
>
> if (!StartServiceCtrlDispatcher( DispatchTable))
> {
> SvcDebugOut(" [MY_SERVICE] StartServiceCtrlDispatcher error =
> %d\n", GetLastError());
> }
> }
0 Kudos
Message 2 of 2
(3,521 Views)