2 * Win32 waitable timers
4 * Copyright 1999 Alexandre Julliard
11 #include "wine/unicode.h"
12 #include "file.h" /* for FILETIME routines */
13 #include "wine/server.h"
16 /***********************************************************************
17 * CreateWaitableTimerA (KERNEL32.@)
19 HANDLE WINAPI
CreateWaitableTimerA( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCSTR name
)
21 WCHAR buffer
[MAX_PATH
];
23 if (!name
) return CreateWaitableTimerW( sa
, manual
, NULL
);
25 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
27 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
30 return CreateWaitableTimerW( sa
, manual
, buffer
);
34 /***********************************************************************
35 * CreateWaitableTimerW (KERNEL32.@)
37 HANDLE WINAPI
CreateWaitableTimerW( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCWSTR name
)
40 DWORD len
= name
? strlenW(name
) : 0;
43 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
46 SERVER_START_REQ( create_timer
)
49 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
50 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
52 wine_server_call_err( req
);
60 /***********************************************************************
61 * OpenWaitableTimerA (KERNEL32.@)
63 HANDLE WINAPI
OpenWaitableTimerA( DWORD access
, BOOL inherit
, LPCSTR name
)
65 WCHAR buffer
[MAX_PATH
];
67 if (!name
) return OpenWaitableTimerW( access
, inherit
, NULL
);
69 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
71 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
74 return OpenWaitableTimerW( access
, inherit
, buffer
);
78 /***********************************************************************
79 * OpenWaitableTimerW (KERNEL32.@)
81 HANDLE WINAPI
OpenWaitableTimerW( DWORD access
, BOOL inherit
, LPCWSTR name
)
84 DWORD len
= name
? strlenW(name
) : 0;
87 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
90 SERVER_START_REQ( open_timer
)
93 req
->inherit
= inherit
;
94 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
95 wine_server_call_err( req
);
103 /***********************************************************************
104 * SetWaitableTimer (KERNEL32.@)
106 BOOL WINAPI
SetWaitableTimer( HANDLE handle
, const LARGE_INTEGER
*when
, LONG period
,
107 PTIMERAPCROUTINE callback
, LPVOID arg
, BOOL resume
)
110 LARGE_INTEGER exp
= *when
;
112 if (exp
.s
.HighPart
< 0) /* relative time */
115 NtQuerySystemTime( &now
);
116 exp
.QuadPart
= RtlLargeIntegerSubtract( now
.QuadPart
, exp
.QuadPart
);
119 SERVER_START_REQ( set_timer
)
121 if (!exp
.s
.LowPart
&& !exp
.s
.HighPart
)
123 /* special case to start timeout on now+period without too many calculations */
130 req
->sec
= DOSFS_FileTimeToUnixTime( (FILETIME
*)&exp
, &remainder
);
131 req
->usec
= remainder
/ 10; /* convert from 100-ns to us units */
133 req
->handle
= handle
;
134 req
->period
= period
;
135 req
->callback
= callback
;
137 if (resume
) SetLastError( ERROR_NOT_SUPPORTED
); /* set error but can still succeed */
138 ret
= !wine_server_call_err( req
);
145 /***********************************************************************
146 * CancelWaitableTimer (KERNEL32.@)
148 BOOL WINAPI
CancelWaitableTimer( HANDLE handle
)
151 SERVER_START_REQ( cancel_timer
)
153 req
->handle
= handle
;
154 ret
= !wine_server_call_err( req
);