3 WINE_DEFAULT_DEBUG_CHANNEL(resource
);
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 static HINSTANCE hSetupApi
= NULL
;
17 /**********************************************************************
18 * LoadStringW (USER32.@)
19 * Synced with Wine Staging 1.7.55
21 INT WINAPI
LoadStringW( HINSTANCE instance
, UINT resource_id
,
22 LPWSTR buffer
, INT buflen
)
30 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
31 instance
, resource_id
, buffer
, buflen
);
36 /* Use loword (incremented by 1) as resourceid */
37 hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
40 hmem
= LoadResource( instance
, hrsrc
);
43 p
= LockResource(hmem
);
44 string_num
= resource_id
& 0x000f;
45 for (i
= 0; i
< string_num
; i
++)
48 TRACE("strlen = %d\n", (int)*p
);
50 /*if buflen == 0, then return a read-only pointer to the resource itself in buffer
51 it is assumed that buffer is actually a (LPWSTR *) */
54 *((LPWSTR
*)buffer
) = p
+ 1;
58 i
= min(buflen
- 1, *p
);
60 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
69 TRACE("%s loaded !\n", debugstr_w(buffer
));
73 /**********************************************************************
74 * LoadStringA (USER32.@)
75 * Synced with Wine Staging 1.7.55
77 INT WINAPI
LoadStringA( HINSTANCE instance
, UINT resource_id
, LPSTR buffer
, INT buflen
)
83 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
84 instance
, resource_id
, buffer
, buflen
);
86 if (!buflen
) return -1;
88 /* Use loword (incremented by 1) as resourceid */
89 if ((hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
90 (LPWSTR
)RT_STRING
)) &&
91 (hmem
= LoadResource( instance
, hrsrc
)))
93 const WCHAR
*p
= LockResource(hmem
);
94 unsigned int id
= resource_id
& 0x000f;
96 while (id
--) p
+= *p
+ 1;
99 RtlUnicodeToMultiByteN( buffer
, buflen
- 1, &retval
, (PWSTR
)(p
+ 1), *p
* sizeof(WCHAR
) );
102 TRACE("returning %s\n", debugstr_a(buffer
));
111 RegisterDeviceNotificationW(HANDLE hRecipient
,
112 LPVOID NotificationFilter
,
116 CMP_REGNOTIFY RegNotify
= NULL
;
117 HDEVNOTIFY hDevNotify
= NULL
;
119 if (hSetupApi
== NULL
) hSetupApi
= LoadLibraryA("SETUPAPI.DLL");
120 if (hSetupApi
== NULL
) return NULL
;
122 RegNotify
= (CMP_REGNOTIFY
) GetProcAddress(hSetupApi
, "CMP_RegisterNotification");
123 if (RegNotify
== NULL
)
125 FreeLibrary(hSetupApi
);
130 ConfigRet
= RegNotify(hRecipient
, NotificationFilter
, Flags
, (PULONG
) &hDevNotify
);
131 if (ConfigRet
!= CR_SUCCESS
)
135 case CR_OUT_OF_MEMORY
:
136 SetLastError (ERROR_NOT_ENOUGH_MEMORY
);
139 case CR_INVALID_POINTER
:
140 SetLastError (ERROR_INVALID_PARAMETER
);
143 case CR_INVALID_DATA
:
144 SetLastError (ERROR_INVALID_DATA
);
148 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR
);
162 UnregisterDeviceNotification(HDEVNOTIFY Handle
)
165 CMP_UNREGNOTIFY UnRegNotify
= NULL
;
167 if (hSetupApi
== NULL
) hSetupApi
= LoadLibraryA("SETUPAPI.DLL");
168 if (hSetupApi
== NULL
) return FALSE
;
170 UnRegNotify
= (CMP_UNREGNOTIFY
) GetProcAddress(hSetupApi
, "CMP_UnregisterNotification");
171 if (UnRegNotify
== NULL
)
173 FreeLibrary(hSetupApi
);
178 ConfigRet
= UnRegNotify((ULONG_PTR
)Handle
);
179 if (ConfigRet
!= CR_SUCCESS
)
183 case CR_INVALID_POINTER
:
184 SetLastError (ERROR_INVALID_PARAMETER
);
187 case CR_INVALID_DATA
:
188 SetLastError (ERROR_INVALID_DATA
);
192 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR
);