3 #include <wine/debug.h>
6 #define CR_SUCCESS 0x00000000
7 #define CR_OUT_OF_MEMORY 0x00000002
8 #define CR_INVALID_POINTER 0x00000003
9 #define CR_INVALID_DATA 0x0000001F
12 typedef DWORD (WINAPI
*CMP_REGNOTIFY
) (HANDLE
, LPVOID
, DWORD
, PULONG
);
13 typedef DWORD (WINAPI
*CMP_UNREGNOTIFY
) (ULONG
);
15 /* FIXME: Currently IsBadWritePtr is implemented using VirtualQuery which
16 does not seem to work properly for stack address space. */
17 /* kill `left-hand operand of comma expression has no effect' warning */
18 #define IsBadWritePtr(lp, n) ((DWORD)lp==n?0:0)
21 static HINSTANCE hSetupApi
= NULL
;
25 * @implemented (Synced with Wine 08.01.2009)
29 LoadStringA(HINSTANCE instance
, UINT resource_id
, LPSTR buffer
, INT buflen
)
35 if (!buflen
) return -1;
37 /* Use loword (incremented by 1) as resourceid */
38 if ((hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
39 (LPWSTR
)RT_STRING
)) &&
40 (hmem
= LoadResource( instance
, hrsrc
)))
42 const WCHAR
*p
= LockResource(hmem
);
43 unsigned int id
= resource_id
& 0x000f;
45 while (id
--) p
+= *p
+ 1;
47 RtlUnicodeToMultiByteN( buffer
, buflen
- 1, &retval
, (PWSTR
)(p
+ 1), *p
* sizeof(WCHAR
) );
55 * @implemented (Synced with Wine 08.01.2009)
59 LoadStringW(HINSTANCE instance
, UINT resource_id
, LPWSTR buffer
, INT buflen
)
70 /* Use loword (incremented by 1) as resourceid */
71 hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
74 hmem
= LoadResource( instance
, hrsrc
);
77 p
= LockResource(hmem
);
78 string_num
= resource_id
& 0x000f;
79 for (i
= 0; i
< string_num
; i
++)
82 /*if buflen == 0, then return a read-only pointer to the resource itself in buffer
83 it is assumed that buffer is actually a (LPWSTR *) */
86 *((LPWSTR
*)buffer
) = p
+ 1;
90 i
= min(buflen
- 1, *p
);
92 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
110 RegisterDeviceNotificationW(HANDLE hRecipient
,
111 LPVOID NotificationFilter
,
115 CMP_REGNOTIFY RegNotify
= NULL
;
116 HDEVNOTIFY hDevNotify
= NULL
;
118 if (hSetupApi
== NULL
) hSetupApi
= LoadLibraryA("SETUPAPI.DLL");
119 if (hSetupApi
== NULL
) return NULL
;
121 RegNotify
= (CMP_REGNOTIFY
) GetProcAddress(hSetupApi
, "CMP_RegisterNotification");
122 if (RegNotify
== NULL
)
124 FreeLibrary(hSetupApi
);
129 ConfigRet
= RegNotify(hRecipient
, NotificationFilter
, Flags
, (PULONG
) &hDevNotify
);
130 if (ConfigRet
!= CR_SUCCESS
)
134 case CR_OUT_OF_MEMORY
:
135 SetLastError (ERROR_NOT_ENOUGH_MEMORY
);
138 case CR_INVALID_POINTER
:
139 SetLastError (ERROR_INVALID_PARAMETER
);
142 case CR_INVALID_DATA
:
143 SetLastError (ERROR_INVALID_DATA
);
147 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR
);
161 UnregisterDeviceNotification(HDEVNOTIFY Handle
)
164 CMP_UNREGNOTIFY UnRegNotify
= NULL
;
166 if (hSetupApi
== NULL
) hSetupApi
= LoadLibraryA("SETUPAPI.DLL");
167 if (hSetupApi
== NULL
) return FALSE
;
169 UnRegNotify
= (CMP_UNREGNOTIFY
) GetProcAddress(hSetupApi
, "CMP_UnregisterNotification");
170 if (UnRegNotify
== NULL
)
172 FreeLibrary(hSetupApi
);
177 ConfigRet
= UnRegNotify((ULONG
) Handle
);
178 if (ConfigRet
!= CR_SUCCESS
)
182 case CR_INVALID_POINTER
:
183 SetLastError (ERROR_INVALID_PARAMETER
);
186 case CR_INVALID_DATA
:
187 SetLastError (ERROR_INVALID_DATA
);
191 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR
);