Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

267 lines
7.4 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. // MultiPlat.CPP
  6. //
  7. // Purpose: Support routines for multiplatform support
  8. //
  9. //***************************************************************************
  10. #include "precomp.h"
  11. #include "multiplat.h"
  12. #include <cnvmacros.h>
  13. HMODULE FRGetModuleHandle(LPCWSTR wszModule)
  14. {
  15. if (CWbemProviderGlue::GetPlatform() == VER_PLATFORM_WIN32_NT)
  16. {
  17. return GetModuleHandleW(wszModule);
  18. }
  19. else
  20. {
  21. bool t_ConversionFailure = false ;
  22. char *szModule = NULL ;
  23. WCSTOANSISTRING(wszModule, szModule , t_ConversionFailure );
  24. if ( ! t_ConversionFailure )
  25. {
  26. if (szModule != NULL)
  27. {
  28. return GetModuleHandleA(szModule);
  29. }
  30. else
  31. {
  32. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  33. }
  34. }
  35. else
  36. {
  37. SetLastError(ERROR_NO_UNICODE_TRANSLATION);
  38. return 0;
  39. }
  40. }
  41. return 0; // To get rid of 64-bit compilation warning
  42. }
  43. DWORD FRGetModuleFileName(HMODULE hModule, LPWSTR lpwcsFileName, DWORD dwSize)
  44. {
  45. if (CWbemProviderGlue::GetPlatform() == VER_PLATFORM_WIN32_NT)
  46. {
  47. return GetModuleFileNameW(hModule, lpwcsFileName, dwSize);
  48. }
  49. else
  50. {
  51. char lpFileName[_MAX_PATH];
  52. DWORD dwRet = GetModuleFileNameA(hModule, lpFileName, dwSize);
  53. // If the call worked, convert the output string
  54. if (dwRet != 0)
  55. {
  56. bool t_ConversionFailure = false ;
  57. WCHAR *pName = NULL;
  58. ANSISTRINGTOWCS(lpFileName, pName, t_ConversionFailure );
  59. if ( ! t_ConversionFailure )
  60. {
  61. if ( pName )
  62. {
  63. wcscpy(lpwcsFileName, pName);
  64. }
  65. else
  66. {
  67. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  68. }
  69. }
  70. else
  71. {
  72. SetLastError(ERROR_NO_UNICODE_TRANSLATION);
  73. return 0;
  74. }
  75. }
  76. return dwRet;
  77. }
  78. }
  79. HINSTANCE FRLoadLibrary(LPCWSTR lpwcsLibFileName)
  80. {
  81. if (CWbemProviderGlue::GetPlatform() == VER_PLATFORM_WIN32_NT)
  82. {
  83. return LoadLibraryW(lpwcsLibFileName);
  84. }
  85. else
  86. {
  87. bool t_ConversionFailure = false ;
  88. char *lpLibFileName = NULL ;
  89. WCSTOANSISTRING(lpwcsLibFileName, lpLibFileName, t_ConversionFailure );
  90. if ( ! t_ConversionFailure )
  91. {
  92. if (lpLibFileName != NULL)
  93. {
  94. return LoadLibraryA(lpLibFileName);
  95. }
  96. else
  97. {
  98. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  99. }
  100. }
  101. else
  102. {
  103. SetLastError(ERROR_NO_UNICODE_TRANSLATION);
  104. return 0;
  105. }
  106. }
  107. return 0; // To get rid of compilation warning
  108. }
  109. BOOL FRGetComputerName(LPWSTR lpwcsBuffer, LPDWORD nSize)
  110. {
  111. if (CWbemProviderGlue::GetPlatform() == VER_PLATFORM_WIN32_NT)
  112. {
  113. return GetComputerNameW(lpwcsBuffer, nSize);
  114. }
  115. else
  116. {
  117. char lpBuffer[_MAX_PATH];
  118. BOOL bRet = GetComputerNameA(lpBuffer, nSize);
  119. // If the call worked
  120. if (bRet)
  121. {
  122. bool t_ConversionFailure = false ;
  123. WCHAR *pName = NULL ;
  124. ANSISTRINGTOWCS(lpBuffer, pName , t_ConversionFailure );
  125. if ( ! t_ConversionFailure )
  126. {
  127. if ( pName )
  128. {
  129. wcscpy(lpwcsBuffer, pName);
  130. }
  131. else
  132. {
  133. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  134. }
  135. }
  136. else
  137. {
  138. SetLastError(ERROR_NO_UNICODE_TRANSLATION);
  139. return FALSE ;
  140. }
  141. }
  142. return bRet;
  143. }
  144. }
  145. HANDLE FRCreateMutex(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitOwner, LPCWSTR lpwstrName)
  146. {
  147. if (CWbemProviderGlue::GetPlatform() == VER_PLATFORM_WIN32_NT)
  148. {
  149. return CreateMutexW(lpMutexAttributes, bInitOwner, lpwstrName);
  150. }
  151. else
  152. {
  153. bool t_ConversionFailure = false ;
  154. char *lpName = NULL ;
  155. WCSTOANSISTRING(lpwstrName, lpName, t_ConversionFailure );
  156. if ( ! t_ConversionFailure )
  157. {
  158. if (lpName != NULL)
  159. {
  160. return CreateMutexA(lpMutexAttributes, bInitOwner, lpName);
  161. }
  162. else
  163. {
  164. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  165. }
  166. }
  167. else
  168. {
  169. SetLastError(ERROR_NO_UNICODE_TRANSLATION);
  170. return 0;
  171. }
  172. }
  173. return NULL; // To get rid of compilation warning
  174. }
  175. DWORD FRExpandEnvironmentStrings(LPCWSTR wszSource, WCHAR *wszDest, DWORD dwSize)
  176. {
  177. if (CWbemProviderGlue::GetPlatform() == VER_PLATFORM_WIN32_NT)
  178. {
  179. return ExpandEnvironmentStringsW(wszSource, wszDest, dwSize);
  180. }
  181. else
  182. {
  183. bool t_ConversionFailure = false ;
  184. char *szSource = NULL ;
  185. WCSTOANSISTRING(wszSource, szSource, t_ConversionFailure );
  186. if ( ! t_ConversionFailure )
  187. {
  188. if (szSource != NULL)
  189. {
  190. char *szDest = new char[dwSize];
  191. if (szDest != NULL)
  192. {
  193. DWORD dwRet;
  194. try
  195. {
  196. dwRet = ExpandEnvironmentStringsA(szSource, szDest, dwSize);
  197. if ((dwRet <= dwSize) && (dwRet != 0))
  198. {
  199. bool t_ConversionFailure = false ;
  200. WCHAR *pName = NULL;
  201. ANSISTRINGTOWCS(szDest, pName, t_ConversionFailure );
  202. if ( ! t_ConversionFailure )
  203. {
  204. if ( pName )
  205. {
  206. wcscpy(wszDest, pName);
  207. }
  208. else
  209. {
  210. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  211. }
  212. }
  213. else
  214. {
  215. SetLastError(ERROR_NO_UNICODE_TRANSLATION);
  216. return 0;
  217. }
  218. }
  219. }
  220. catch ( ... )
  221. {
  222. delete [] szDest;
  223. throw;
  224. }
  225. delete [] szDest;
  226. return dwRet;
  227. }
  228. else
  229. {
  230. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  231. }
  232. }
  233. else
  234. {
  235. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  236. }
  237. }
  238. else
  239. {
  240. SetLastError(ERROR_NO_UNICODE_TRANSLATION);
  241. return 0;
  242. }
  243. }
  244. return NULL; // To get rid of compilation warning
  245. }