widl: Properly align name table entries.
[wine.git] / dlls / scardsvr / scardsvr.c
blob5c4e26f536270e351470e90828ea41e5e5df8ff9
1 /*
2 * Smart card service
4 * Copyright 2014 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winsvc.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(winscard);
29 static SERVICE_STATUS_HANDLE service_handle;
30 static HANDLE stop_event;
32 static DWORD WINAPI service_handler(DWORD ctrl, DWORD event_type, void *event_data, void *context)
34 SERVICE_STATUS status;
36 status.dwServiceType = SERVICE_WIN32;
37 status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
38 status.dwWin32ExitCode = 0;
39 status.dwServiceSpecificExitCode = 0;
40 status.dwCheckPoint = 0;
41 status.dwWaitHint = 0;
43 switch(ctrl)
45 case SERVICE_CONTROL_STOP:
46 case SERVICE_CONTROL_SHUTDOWN:
47 TRACE("Shutting down.\n");
48 status.dwCurrentState = SERVICE_STOP_PENDING;
49 status.dwControlsAccepted = 0;
50 SetServiceStatus(service_handle, &status);
51 SetEvent(stop_event);
52 return ERROR_SUCCESS;
54 default:
55 FIXME("Got unknown control %#lx.\n", ctrl);
56 status.dwCurrentState = SERVICE_RUNNING;
57 SetServiceStatus(service_handle, &status);
58 return ERROR_SUCCESS;
62 void WINAPI CalaisMain(DWORD argc, WCHAR **argv)
64 SERVICE_STATUS status;
66 TRACE("Starting service.\n");
68 stop_event = CreateEventW(NULL, TRUE, FALSE, NULL);
70 if (!(service_handle = RegisterServiceCtrlHandlerExW(L"scardsvr", service_handler, NULL)))
71 return;
73 status.dwServiceType = SERVICE_WIN32;
74 status.dwCurrentState = SERVICE_RUNNING;
75 status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
76 status.dwWin32ExitCode = 0;
77 status.dwServiceSpecificExitCode = 0;
78 status.dwCheckPoint = 0;
79 status.dwWaitHint = 10000;
80 SetServiceStatus(service_handle, &status);
82 WaitForSingleObject(stop_event, INFINITE);
84 status.dwCurrentState = SERVICE_STOPPED;
85 status.dwControlsAccepted = 0;
86 SetServiceStatus(service_handle, &status);
87 TRACE("Service stopped.\n");