3 #include <wine/debug.h>
4 WINE_DEFAULT_DEBUG_CHANNEL(resource
);
7 #define CR_SUCCESS 0x00000000
8 #define CR_OUT_OF_MEMORY 0x00000002
9 #define CR_INVALID_POINTER 0x00000003
10 #define CR_INVALID_DATA 0x0000001F
13 typedef DWORD (WINAPI
*CMP_REGNOTIFY
) (HANDLE
, LPVOID
, DWORD
, PULONG
);
14 typedef DWORD (WINAPI
*CMP_UNREGNOTIFY
) (ULONG
);
16 static HINSTANCE hSetupApi
= NULL
;
18 /**********************************************************************
19 * LoadStringW (USER32.@)
20 * Synced with Wine Staging 1.7.55
22 INT WINAPI
LoadStringW( HINSTANCE instance
, UINT resource_id
,
23 LPWSTR buffer
, INT buflen
)
31 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
32 instance
, resource_id
, buffer
, buflen
);
37 /* Use loword (incremented by 1) as resourceid */
38 hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
41 hmem
= LoadResource( instance
, hrsrc
);
44 p
= LockResource(hmem
);
45 string_num
= resource_id
& 0x000f;
46 for (i
= 0; i
< string_num
; i
++)
49 TRACE("strlen = %d\n", (int)*p
);
51 /*if buflen == 0, then return a read-only pointer to the resource itself in buffer
52 it is assumed that buffer is actually a (LPWSTR *) */
55 *((LPWSTR
*)buffer
) = p
+ 1;
59 i
= min(buflen
- 1, *p
);
61 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
70 TRACE("%s loaded !\n", debugstr_w(buffer
));
74 /**********************************************************************
75 * LoadStringA (USER32.@)
76 * Synced with Wine Staging 1.7.55
78 INT WINAPI
LoadStringA( HINSTANCE instance
, UINT resource_id
, LPSTR buffer
, INT buflen
)
84 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
85 instance
, resource_id
, buffer
, buflen
);
87 if (!buflen
) return -1;
89 /* Use loword (incremented by 1) as resourceid */
90 if ((hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
91 (LPWSTR
)RT_STRING
)) &&
92 (hmem
= LoadResource( instance
, hrsrc
)))
94 const WCHAR
*p
= LockResource(hmem
);
95 unsigned int id
= resource_id
& 0x000f;
97 while (id
--) p
+= *p
+ 1;
100 RtlUnicodeToMultiByteN( buffer
, buflen
- 1, &retval
, (PWSTR
)(p
+ 1), *p
* sizeof(WCHAR
) );
103 TRACE("returning %s\n", debugstr_a(buffer
));
112 RegisterDeviceNotificationW(HANDLE hRecipient
,
113 LPVOID NotificationFilter
,
117 CMP_REGNOTIFY RegNotify
= NULL
;
118 HDEVNOTIFY hDevNotify
= NULL
;
120 if (hSetupApi
== NULL
) hSetupApi
= LoadLibraryA("SETUPAPI.DLL");
121 if (hSetupApi
== NULL
) return NULL
;
123 RegNotify
= (CMP_REGNOTIFY
) GetProcAddress(hSetupApi
, "CMP_RegisterNotification");
124 if (RegNotify
== NULL
)
126 FreeLibrary(hSetupApi
);
131 ConfigRet
= RegNotify(hRecipient
, NotificationFilter
, Flags
, (PULONG
) &hDevNotify
);
132 if (ConfigRet
!= CR_SUCCESS
)
136 case CR_OUT_OF_MEMORY
:
137 SetLastError (ERROR_NOT_ENOUGH_MEMORY
);
140 case CR_INVALID_POINTER
:
141 SetLastError (ERROR_INVALID_PARAMETER
);
144 case CR_INVALID_DATA
:
145 SetLastError (ERROR_INVALID_DATA
);
149 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR
);
163 UnregisterDeviceNotification(HDEVNOTIFY Handle
)
166 CMP_UNREGNOTIFY UnRegNotify
= NULL
;
168 if (hSetupApi
== NULL
) hSetupApi
= LoadLibraryA("SETUPAPI.DLL");
169 if (hSetupApi
== NULL
) return FALSE
;
171 UnRegNotify
= (CMP_UNREGNOTIFY
) GetProcAddress(hSetupApi
, "CMP_UnregisterNotification");
172 if (UnRegNotify
== NULL
)
174 FreeLibrary(hSetupApi
);
179 ConfigRet
= UnRegNotify((ULONG_PTR
)Handle
);
180 if (ConfigRet
!= CR_SUCCESS
)
184 case CR_INVALID_POINTER
:
185 SetLastError (ERROR_INVALID_PARAMETER
);
188 case CR_INVALID_DATA
:
189 SetLastError (ERROR_INVALID_DATA
);
193 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR
);