2 * Win32 waitable timers
4 * Copyright 1999 Alexandre Julliard
10 #include "file.h" /* for FILETIME routines */
14 /***********************************************************************
15 * CreateWaitableTimerA (KERNEL32.861)
17 HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
19 struct create_timer_request *req = get_req_buffer();
22 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
23 server_strcpyAtoW( req->name, name );
25 server_call( REQ_CREATE_TIMER );
26 if (req->handle == -1) return 0;
31 /***********************************************************************
32 * CreateWaitableTimerW (KERNEL32.862)
34 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
36 struct create_timer_request *req = get_req_buffer();
39 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
40 server_strcpyW( req->name, name );
42 server_call( REQ_CREATE_TIMER );
43 if (req->handle == -1) return 0;
48 /***********************************************************************
49 * OpenWaitableTimerA (KERNEL32.881)
51 HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
53 struct open_timer_request *req = get_req_buffer();
56 req->inherit = inherit;
57 server_strcpyAtoW( req->name, name );
58 server_call( REQ_OPEN_TIMER );
59 if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
64 /***********************************************************************
65 * OpenWaitableTimerW (KERNEL32.882)
67 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
69 struct open_timer_request *req = get_req_buffer();
72 req->inherit = inherit;
73 server_strcpyW( req->name, name );
74 server_call( REQ_OPEN_TIMER );
75 if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
80 /***********************************************************************
81 * SetWaitableTimer (KERNEL32.894)
83 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
84 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
88 struct set_timer_request *req = get_req_buffer();
90 if (when->s.HighPart < 0) /* relative time */
92 DWORD low = ft.dwLowDateTime;
93 GetSystemTimeAsFileTime( &ft );
94 ft.dwLowDateTime -= when->s.LowPart;
95 ft.dwHighDateTime -= when->s.HighPart;
96 if (low < ft.dwLowDateTime) ft.dwHighDateTime--; /* overflow */
98 else /* absolute time */
100 ft.dwLowDateTime = when->s.LowPart;
101 ft.dwHighDateTime = when->s.HighPart;
103 req->handle = handle;
104 req->sec = DOSFS_FileTimeToUnixTime( &ft, &remainder );
105 req->usec = remainder / 10; /* convert from 100-ns to us units */
106 req->period = period;
107 req->callback = callback;
109 if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
110 return !server_call( REQ_SET_TIMER );
114 /***********************************************************************
115 * CancelWaitableTimer (KERNEL32.857)
117 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
119 struct cancel_timer_request *req = get_req_buffer();
120 req->handle = handle;
121 return !server_call( REQ_CANCEL_TIMER );