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 /* FIXME: Currently IsBadWritePtr is implemented using VirtualQuery which
17 does not seem to work properly for stack address space. */
18 /* kill `left-hand operand of comma expression has no effect' warning */
19 #define IsBadWritePtr(lp, n) ((DWORD)lp==n?0:0)
22 static HINSTANCE hSetupApi
= NULL
;
24 /**********************************************************************
25 * LoadStringW (USER32.@)
26 * Synced with Wine Staging 1.7.55
28 INT WINAPI
LoadStringW( HINSTANCE instance
, UINT resource_id
,
29 LPWSTR buffer
, INT buflen
)
37 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
38 instance
, resource_id
, buffer
, buflen
);
43 /* Use loword (incremented by 1) as resourceid */
44 hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
47 hmem
= LoadResource( instance
, hrsrc
);
50 p
= LockResource(hmem
);
51 string_num
= resource_id
& 0x000f;
52 for (i
= 0; i
< string_num
; i
++)
55 TRACE("strlen = %d\n", (int)*p
);
57 /*if buflen == 0, then return a read-only pointer to the resource itself in buffer
58 it is assumed that buffer is actually a (LPWSTR *) */
61 *((LPWSTR
*)buffer
) = p
+ 1;
65 i
= min(buflen
- 1, *p
);
67 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
76 TRACE("%s loaded !\n", debugstr_w(buffer
));
80 /**********************************************************************
81 * LoadStringA (USER32.@)
82 * Synced with Wine Staging 1.7.55
84 INT WINAPI
LoadStringA( HINSTANCE instance
, UINT resource_id
, LPSTR buffer
, INT buflen
)
90 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
91 instance
, resource_id
, buffer
, buflen
);
93 if (!buflen
) return -1;
95 /* Use loword (incremented by 1) as resourceid */
96 if ((hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
97 (LPWSTR
)RT_STRING
)) &&
98 (hmem
= LoadResource( instance
, hrsrc
)))
100 const WCHAR
*p
= LockResource(hmem
);
101 unsigned int id
= resource_id
& 0x000f;
103 while (id
--) p
+= *p
+ 1;
106 RtlUnicodeToMultiByteN( buffer
, buflen
- 1, &retval
, (PWSTR
)(p
+ 1), *p
* sizeof(WCHAR
) );
109 TRACE("returning %s\n", debugstr_a(buffer
));
118 RegisterDeviceNotificationW(HANDLE hRecipient
,
119 LPVOID NotificationFilter
,
123 CMP_REGNOTIFY RegNotify
= NULL
;
124 HDEVNOTIFY hDevNotify
= NULL
;
126 if (hSetupApi
== NULL
) hSetupApi
= LoadLibraryA("SETUPAPI.DLL");
127 if (hSetupApi
== NULL
) return NULL
;
129 RegNotify
= (CMP_REGNOTIFY
) GetProcAddress(hSetupApi
, "CMP_RegisterNotification");
130 if (RegNotify
== NULL
)
132 FreeLibrary(hSetupApi
);
137 ConfigRet
= RegNotify(hRecipient
, NotificationFilter
, Flags
, (PULONG
) &hDevNotify
);
138 if (ConfigRet
!= CR_SUCCESS
)
142 case CR_OUT_OF_MEMORY
:
143 SetLastError (ERROR_NOT_ENOUGH_MEMORY
);
146 case CR_INVALID_POINTER
:
147 SetLastError (ERROR_INVALID_PARAMETER
);
150 case CR_INVALID_DATA
:
151 SetLastError (ERROR_INVALID_DATA
);
155 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR
);
169 UnregisterDeviceNotification(HDEVNOTIFY Handle
)
172 CMP_UNREGNOTIFY UnRegNotify
= NULL
;
174 if (hSetupApi
== NULL
) hSetupApi
= LoadLibraryA("SETUPAPI.DLL");
175 if (hSetupApi
== NULL
) return FALSE
;
177 UnRegNotify
= (CMP_UNREGNOTIFY
) GetProcAddress(hSetupApi
, "CMP_UnregisterNotification");
178 if (UnRegNotify
== NULL
)
180 FreeLibrary(hSetupApi
);
185 ConfigRet
= UnRegNotify((ULONG_PTR
)Handle
);
186 if (ConfigRet
!= CR_SUCCESS
)
190 case CR_INVALID_POINTER
:
191 SetLastError (ERROR_INVALID_PARAMETER
);
194 case CR_INVALID_DATA
:
195 SetLastError (ERROR_INVALID_DATA
);
199 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR
);