Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenresources.c
Go to the documentation of this file.
00001 #include <user32.h> 00002 00003 #include <wine/debug.h> 00004 00005 #ifndef _CFGMGR32_H_ 00006 #define CR_SUCCESS 0x00000000 00007 #define CR_OUT_OF_MEMORY 0x00000002 00008 #define CR_INVALID_POINTER 0x00000003 00009 #define CR_INVALID_DATA 0x0000001F 00010 #endif 00011 00012 typedef DWORD (WINAPI *CMP_REGNOTIFY) (HANDLE, LPVOID, DWORD, PULONG); 00013 typedef DWORD (WINAPI *CMP_UNREGNOTIFY) (ULONG ); 00014 00015 /* FIXME: Currently IsBadWritePtr is implemented using VirtualQuery which 00016 does not seem to work properly for stack address space. */ 00017 /* kill `left-hand operand of comma expression has no effect' warning */ 00018 #define IsBadWritePtr(lp, n) ((DWORD)lp==n?0:0) 00019 00020 00021 static HINSTANCE hSetupApi = NULL; 00022 00023 00024 /* 00025 * @implemented (Synced with Wine 08.01.2009) 00026 */ 00027 INT 00028 WINAPI 00029 LoadStringA(HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen) 00030 { 00031 HGLOBAL hmem; 00032 HRSRC hrsrc; 00033 DWORD retval = 0; 00034 00035 if (!buflen) return -1; 00036 00037 /* Use loword (incremented by 1) as resourceid */ 00038 if ((hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), 00039 (LPWSTR)RT_STRING )) && 00040 (hmem = LoadResource( instance, hrsrc ))) 00041 { 00042 const WCHAR *p = LockResource(hmem); 00043 unsigned int id = resource_id & 0x000f; 00044 00045 while (id--) p += *p + 1; 00046 00047 RtlUnicodeToMultiByteN( buffer, buflen - 1, &retval, (PWSTR)(p + 1), *p * sizeof(WCHAR) ); 00048 } 00049 buffer[retval] = 0; 00050 return retval; 00051 } 00052 00053 00054 /* 00055 * @implemented (Synced with Wine 08.01.2009) 00056 */ 00057 INT 00058 WINAPI 00059 LoadStringW(HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen) 00060 { 00061 HGLOBAL hmem; 00062 HRSRC hrsrc; 00063 WCHAR *p; 00064 int string_num; 00065 int i; 00066 00067 if(buffer == NULL) 00068 return 0; 00069 00070 /* Use loword (incremented by 1) as resourceid */ 00071 hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), 00072 (LPWSTR)RT_STRING ); 00073 if (!hrsrc) return 0; 00074 hmem = LoadResource( instance, hrsrc ); 00075 if (!hmem) return 0; 00076 00077 p = LockResource(hmem); 00078 string_num = resource_id & 0x000f; 00079 for (i = 0; i < string_num; i++) 00080 p += *p + 1; 00081 00082 /*if buflen == 0, then return a read-only pointer to the resource itself in buffer 00083 it is assumed that buffer is actually a (LPWSTR *) */ 00084 if(buflen == 0) 00085 { 00086 *((LPWSTR *)buffer) = p + 1; 00087 return *p; 00088 } 00089 00090 i = min(buflen - 1, *p); 00091 if (i > 0) { 00092 memcpy(buffer, p + 1, i * sizeof (WCHAR)); 00093 buffer[i] = 0; 00094 } else { 00095 if (buflen > 1) { 00096 buffer[0] = 0; 00097 return 0; 00098 } 00099 } 00100 00101 return i; 00102 } 00103 00104 00105 /* 00106 * @implemented 00107 */ 00108 HDEVNOTIFY 00109 WINAPI 00110 RegisterDeviceNotificationW(HANDLE hRecipient, 00111 LPVOID NotificationFilter, 00112 DWORD Flags) 00113 { 00114 DWORD ConfigRet = 0; 00115 CMP_REGNOTIFY RegNotify = NULL; 00116 HDEVNOTIFY hDevNotify = NULL; 00117 00118 if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL"); 00119 if (hSetupApi == NULL) return NULL; 00120 00121 RegNotify = (CMP_REGNOTIFY) GetProcAddress(hSetupApi, "CMP_RegisterNotification"); 00122 if (RegNotify == NULL) 00123 { 00124 FreeLibrary(hSetupApi); 00125 hSetupApi = NULL; 00126 return NULL; 00127 } 00128 00129 ConfigRet = RegNotify(hRecipient, NotificationFilter, Flags, (PULONG) &hDevNotify); 00130 if (ConfigRet != CR_SUCCESS) 00131 { 00132 switch (ConfigRet) 00133 { 00134 case CR_OUT_OF_MEMORY: 00135 SetLastError (ERROR_NOT_ENOUGH_MEMORY); 00136 break; 00137 00138 case CR_INVALID_POINTER: 00139 SetLastError (ERROR_INVALID_PARAMETER); 00140 break; 00141 00142 case CR_INVALID_DATA: 00143 SetLastError (ERROR_INVALID_DATA); 00144 break; 00145 00146 default: 00147 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR); 00148 break; 00149 } 00150 } 00151 00152 return hDevNotify; 00153 } 00154 00155 00156 /* 00157 * @implemented 00158 */ 00159 BOOL 00160 WINAPI 00161 UnregisterDeviceNotification(HDEVNOTIFY Handle) 00162 { 00163 DWORD ConfigRet = 0; 00164 CMP_UNREGNOTIFY UnRegNotify = NULL; 00165 00166 if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL"); 00167 if (hSetupApi == NULL) return FALSE; 00168 00169 UnRegNotify = (CMP_UNREGNOTIFY) GetProcAddress(hSetupApi, "CMP_UnregisterNotification"); 00170 if (UnRegNotify == NULL) 00171 { 00172 FreeLibrary(hSetupApi); 00173 hSetupApi = NULL; 00174 return FALSE; 00175 } 00176 00177 ConfigRet = UnRegNotify((ULONG_PTR)Handle ); 00178 if (ConfigRet != CR_SUCCESS) 00179 { 00180 switch (ConfigRet) 00181 { 00182 case CR_INVALID_POINTER: 00183 SetLastError (ERROR_INVALID_PARAMETER); 00184 break; 00185 00186 case CR_INVALID_DATA: 00187 SetLastError (ERROR_INVALID_DATA); 00188 break; 00189 00190 default: 00191 SetLastError (ERROR_SERVICE_SPECIFIC_ERROR); 00192 break; 00193 } 00194 return FALSE; 00195 } 00196 00197 return TRUE; 00198 } 00199 00200 /* EOF */ Generated on Mon May 28 2012 04:38:39 for ReactOS by
1.7.6.1
|