Leaked source code of windows server 2003
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.

5543 lines
161 KiB

  1. /*
  2. -
  3. - AnsiWrap.c
  4. *
  5. * Contains wrappers for thunking down Unicode calls to the Win 9x ANSI versions
  6. *
  7. */
  8. #include "_apipch.h"
  9. // we should not define the Macro for the APIs that we will implement the wrappers for.
  10. // lets try to keep this list alphabetical for sanity
  11. #undef CallWindowProcW
  12. #undef CharLowerW
  13. #undef CharNextW
  14. #undef CharPrevW
  15. #undef CharUpperBuffW
  16. #undef CharUpperBuffW
  17. #undef CharUpperW
  18. #undef CompareStringW
  19. #undef CopyFileW
  20. #undef CreateDialogParamW
  21. #undef CreateDirectoryW
  22. #undef CreateEventW
  23. #undef CreateFileW
  24. #undef CreateFontIndirectW
  25. #undef CreateMutexW
  26. #undef CreateWindowExW
  27. //#undef CryptAcquireContextW
  28. #undef DefWindowProcW
  29. #undef DeleteFileW
  30. #undef DialogBoxParamW
  31. #undef DispatchMessageW
  32. #undef DragQueryFileW
  33. #undef DrawTextW
  34. #undef ExpandEnvironmentStringsW
  35. #undef FindFirstChangeNotificationW
  36. #undef FindFirstFileW
  37. #undef FormatMessageW
  38. #undef GetClassInfoExW
  39. #undef GetClassInfoW
  40. #undef GetClassNameW
  41. #undef GetDateFormatW
  42. #undef GetDiskFreeSpaceW
  43. #undef GetDlgItemTextW
  44. #undef GetFileAttributesW
  45. #undef GetLocaleInfoW
  46. #undef GetMenuItemInfoW
  47. #undef GetMessageW
  48. #undef GetModuleFileNameW
  49. #undef GetObjectW
  50. #undef GetPrivateProfileIntW
  51. #undef GetPrivateProfileStringW
  52. #undef GetProfileIntW
  53. #undef GetStringTypeW
  54. #undef GetSystemDirectoryW
  55. #undef GetTempFileNameW
  56. #undef GetTempPathW
  57. #undef GetTextExtentPoint32W
  58. #undef GetTimeFormatW
  59. #undef GetUserNameW
  60. #undef GetWindowLongW
  61. #undef GetWindowsDirectoryW
  62. #undef GetWindowTextLengthW
  63. #undef GetWindowTextW
  64. #undef InsertMenuW
  65. #undef IsBadStringPtrW
  66. #undef IsCharLowerW
  67. #undef IsCharUpperW
  68. #undef IsDialogMessageW
  69. #undef LCMapStringW
  70. #undef LoadAcceleratorsW
  71. #undef LoadCursorW
  72. #undef LoadIconW
  73. #undef LoadImageW
  74. #undef LoadLibraryW
  75. #undef LoadMenuW
  76. #undef LoadStringW
  77. #undef lstrcatW
  78. #undef lstrcmpiW
  79. #undef lstrcmpW
  80. #undef lstrcpynW
  81. #undef lstrcpyW
  82. #undef ModifyMenuW
  83. #undef MoveFileW
  84. #undef OutputDebugStringW
  85. #undef PeekMessageW
  86. #undef PostMessageW
  87. #undef RegCreateKeyExW
  88. #undef RegCreateKeyW
  89. #undef RegDeleteKeyW
  90. #undef RegDeleteValueW
  91. #undef RegEnumKeyExW
  92. #undef RegEnumValueW
  93. #undef RegisterClassExW
  94. #undef RegisterClassW
  95. #undef RegisterClipboardFormatW
  96. #undef RegisterWindowMessageW
  97. #undef RegOpenKeyExW
  98. #undef RegQueryInfoKeyW
  99. #undef RegQueryValueExW
  100. #undef RegQueryValueW
  101. #undef RegSetValueExW
  102. #undef RegSetValueW
  103. #undef SendDlgItemMessageW
  104. #undef SendMessageW
  105. #undef SetDlgItemTextW
  106. #undef SetMenuItemInfoW
  107. #undef SetWindowLongW
  108. #undef SetWindowTextW
  109. #undef ShellExecuteW
  110. #undef StartDocW
  111. #undef SystemParametersInfoW
  112. #undef TranslateAcceleratorW
  113. #undef UnRegisterClassW
  114. #undef wsprintfW
  115. #undef wvsprintfW
  116. //
  117. // Do this in every wrapper function to make sure the wrapper
  118. // prototype matches the function it is intending to replace.
  119. //
  120. #define VALIDATE_PROTOTYPE(f) if (f##W == f##WrapW) 0
  121. #define InRange(val, valMin, valMax) (valMin <= val && val <= valMax)
  122. // Because with current build setting, no lib containing wcscpy and wcslen is linked
  123. // so implement these two functions here.
  124. LPWSTR My_wcscpy( LPWSTR pwszDest, LPCWSTR pwszSrc )
  125. {
  126. LPWSTR pwszDestT = NULL;
  127. LPCWSTR pwszSrcT;
  128. pwszSrcT = pwszSrc;
  129. pwszDestT = pwszDest;
  130. while ( *pwszSrcT )
  131. *pwszDestT++ = *pwszSrcT ++;
  132. *pwszDestT = 0x0000;
  133. return pwszDest;
  134. }
  135. DWORD My_wcslen( LPCWSTR lpwszStr )
  136. {
  137. DWORD dLen =0;
  138. LPCWSTR lpwszStrT;
  139. lpwszStrT = lpwszStr;
  140. dLen = 0;
  141. while ( *lpwszStrT ) {
  142. dLen ++;
  143. lpwszStrT ++;
  144. }
  145. return dLen;
  146. }
  147. LPWSTR My_wcscat( LPWSTR pwszDest, LPCWSTR pwszSrc )
  148. {
  149. LPWSTR pwszDestT = pwszDest;
  150. while ( *pwszDestT )
  151. pwszDestT++;
  152. My_wcscpy(pwszDestT, pwszSrc);
  153. return pwszDest;
  154. }
  155. // ADVAPI32.DLL
  156. /* RegOpenKeyEx */
  157. LONG WINAPI RegOpenKeyExWrapW( HKEY hKey, // handle to open key
  158. LPCTSTR lpSubKey, // address of name of subkey to open
  159. DWORD ulOptions, // reserved
  160. REGSAM samDesired, // security access mask
  161. PHKEY phkResult) // address of handle to open key
  162. {
  163. LPSTR lpSubKeyA = NULL;
  164. LONG lRetValue = 0;
  165. VALIDATE_PROTOTYPE(RegOpenKeyEx);
  166. if (g_bRunningOnNT)
  167. return RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult);
  168. lpSubKeyA = ConvertWtoA(lpSubKey);
  169. lRetValue = RegOpenKeyExA(hKey, lpSubKeyA, ulOptions, samDesired, phkResult);
  170. LocalFreeAndNull( &lpSubKeyA );
  171. return lRetValue;
  172. }
  173. /* RegQueryValue */
  174. LONG WINAPI RegQueryValueWrapW( HKEY hKey, // handle to key to query
  175. LPCTSTR lpSubKey, // name of subkey to query
  176. LPTSTR lpValue, // buffer for returned string
  177. PLONG lpcbValue) // receives size of returned string
  178. {
  179. LPSTR lpSubKeyA = NULL;
  180. LPWSTR lpwszValue = NULL;
  181. LONG lRetValue =0;
  182. LPSTR lpValueA = NULL;
  183. LONG cbValueA = 0;
  184. VALIDATE_PROTOTYPE(RegQueryValue);
  185. if (g_bRunningOnNT)
  186. return RegQueryValueW(hKey, lpSubKey, lpValue, lpcbValue);
  187. lpSubKeyA = ConvertWtoA(lpSubKey);
  188. lRetValue = RegQueryValueA(hKey, lpSubKeyA, NULL, &cbValueA);
  189. if ( lRetValue != ERROR_SUCCESS ) {
  190. LocalFreeAndNull( &lpSubKeyA);
  191. return lRetValue;
  192. }
  193. lpValueA = LocalAlloc(LMEM_ZEROINIT, cbValueA);
  194. lRetValue = RegQueryValueA(hKey, lpSubKeyA, lpValueA, &cbValueA);
  195. lpwszValue = ConvertAtoW(lpValueA);
  196. *lpcbValue = (My_wcslen(lpwszValue) + 1 ) * sizeof(WCHAR);
  197. if ( lpValue != NULL )
  198. My_wcscpy(lpValue, lpwszValue);
  199. LocalFreeAndNull( &lpSubKeyA );
  200. LocalFreeAndNull( &lpValueA );
  201. LocalFreeAndNull( &lpwszValue );
  202. return lRetValue;
  203. }
  204. // RegEnumKeyEx
  205. LONG WINAPI RegEnumKeyExWrapW( HKEY hKey, // handle to key to enumerate
  206. DWORD dwIndex, // index of subkey to enumerate
  207. LPTSTR lpName, // address of buffer for subkey name
  208. LPDWORD lpcbName, // address for size of subkey buffer
  209. LPDWORD lpReserved, // reserved
  210. LPTSTR lpClass, // address of buffer for class string
  211. LPDWORD lpcbClass, // address for size of class buffer
  212. PFILETIME lpftLastWriteTime )
  213. // address for time key last written to
  214. {
  215. LONG lRetValue = 0;
  216. CHAR lpNameA[MAX_PATH];
  217. CHAR lpClassA[MAX_PATH];
  218. LPWSTR lpNameW = NULL;
  219. LPWSTR lpClassW= NULL;
  220. DWORD cbName, cbClass;
  221. // [PaulHi] 1/11/99 Init wide char buffers
  222. lpNameA[0] = 0;
  223. lpClassA[0] = 0;
  224. VALIDATE_PROTOTYPE(RegEnumKeyEx);
  225. if (g_bRunningOnNT)
  226. return RegEnumKeyExW(hKey, dwIndex, lpName, lpcbName, lpReserved, lpClass, lpcbClass, lpftLastWriteTime);
  227. cbName = cbClass = MAX_PATH;
  228. lRetValue = RegEnumKeyExA(hKey,dwIndex,lpNameA,&cbName,lpReserved,lpClassA,&cbClass,lpftLastWriteTime);
  229. if ( lRetValue != ERROR_SUCCESS ) return lRetValue;
  230. lpClassW = ConvertAtoW( lpClassA );
  231. lpNameW = ConvertAtoW( lpNameA );
  232. cbName = My_wcslen(lpNameW) + 1;
  233. cbClass= My_wcslen(lpClassW) + 1;
  234. // [PaulHi] 1/11/99 Be careful copying to passed in pointers
  235. if (lpClass && lpcbClass)
  236. {
  237. if (cbClass <= *lpcbClass)
  238. {
  239. CopyMemory(lpClass, lpClassW, cbClass * sizeof(WCHAR) );
  240. *lpcbClass = cbClass;
  241. }
  242. else
  243. {
  244. Assert(0);
  245. lpClass[0] = 0;
  246. *lpcbClass = 0;
  247. lRetValue = ERROR_INSUFFICIENT_BUFFER;
  248. }
  249. }
  250. if (lpName && lpcbName)
  251. {
  252. if (cbName <= *lpcbName)
  253. {
  254. CopyMemory(lpName, lpNameW, cbName * sizeof(WCHAR) );
  255. *lpcbName = cbName;
  256. }
  257. else
  258. {
  259. Assert(0);
  260. lpName[0] = 0;
  261. *lpcbName = 0;
  262. lRetValue = ERROR_INSUFFICIENT_BUFFER;
  263. }
  264. }
  265. LocalFreeAndNull( &lpClassW );
  266. LocalFreeAndNull( &lpNameW );
  267. return lRetValue;
  268. }
  269. /* RegSetValue */
  270. LONG WINAPI RegSetValueWrapW( HKEY hKey, // handle to key to set value for
  271. LPCTSTR lpSubKey, // address of subkey name
  272. DWORD dwType, // type of value
  273. LPCTSTR lpData, // address of value data
  274. DWORD cbData ) // size of value data
  275. {
  276. LPSTR lpSubKeyA =NULL;
  277. LPSTR lpDataA=NULL;
  278. DWORD cbDataA =0;
  279. LONG lRetValue = 0;
  280. VALIDATE_PROTOTYPE(RegSetValue);
  281. if (g_bRunningOnNT)
  282. return RegSetValueW(hKey, lpSubKey, dwType, lpData, cbData);
  283. lpSubKeyA = ConvertWtoA(lpSubKey );
  284. lpDataA = ConvertWtoA( lpData );
  285. cbDataA = lstrlenA( lpDataA );
  286. lRetValue = RegSetValueA(hKey, lpSubKeyA, dwType, lpDataA, cbDataA);
  287. LocalFreeAndNull( &lpSubKeyA );
  288. LocalFreeAndNull( &lpDataA );
  289. return lRetValue;
  290. }
  291. // RegDeleteKey
  292. LONG WINAPI RegDeleteKeyWrapW( HKEY hKey, // handle to open key
  293. LPCTSTR lpSubKey) // address of name of subkey to delete
  294. {
  295. LPSTR lpSubKeyA =NULL;
  296. LONG lRetValue = 0;
  297. VALIDATE_PROTOTYPE(RegDeleteKey);
  298. if (g_bRunningOnNT)
  299. return RegDeleteKeyW(hKey, lpSubKey);
  300. lpSubKeyA = ConvertWtoA(lpSubKey );
  301. lRetValue = RegDeleteKeyA(hKey, lpSubKeyA );
  302. LocalFreeAndNull ( &lpSubKeyA );
  303. return lRetValue;
  304. }
  305. // GetUserName
  306. BOOL WINAPI GetUserNameWrapW( LPTSTR lpBuffer, // address of name buffer
  307. LPDWORD nSize ) // address of size of name buffer
  308. {
  309. CHAR lpBufferA[MAX_PATH];
  310. DWORD nSizeA, nSizeW;
  311. BOOL bRetValue;
  312. LPWSTR lpwszBuffer = NULL;
  313. VALIDATE_PROTOTYPE(GetUserName);
  314. if (g_bRunningOnNT)
  315. return GetUserNameW(lpBuffer, nSize);
  316. nSizeA = MAX_PATH;
  317. bRetValue = GetUserNameA( lpBufferA, &nSizeA );
  318. lpwszBuffer = ConvertAtoW(lpBufferA );
  319. if (lpBuffer == NULL )
  320. bRetValue = FALSE;
  321. nSizeW = My_wcslen(lpwszBuffer);
  322. if ( *nSize < nSizeW ) {
  323. *nSize = nSizeW + 1;
  324. bRetValue = FALSE;
  325. }
  326. if ( bRetValue == TRUE ) {
  327. My_wcscpy( lpBuffer, lpwszBuffer );
  328. *nSize = nSizeW + 1;
  329. }
  330. LocalFreeAndNull( &lpwszBuffer );
  331. return bRetValue;
  332. }
  333. // RegEnumValue
  334. LONG WINAPI RegEnumValueWrapW( HKEY hKey, // handle to key to query
  335. DWORD dwIndex, // index of value to query
  336. LPTSTR lpValueName, // address of buffer for value string
  337. LPDWORD lpcbValueName, // address for size of value buffer
  338. LPDWORD lpReserved, // reserved
  339. LPDWORD lpType, // address of buffer for type code
  340. LPBYTE lpData, // address of buffer for value data
  341. LPDWORD lpcbData ) // address for size of data buffer
  342. {
  343. LONG lRetValue = 0;
  344. CHAR lpValueNameA[MAX_PATH];
  345. LPWSTR lpValueNameW = NULL, lpDataW= NULL;
  346. LPSTR lpDataA = NULL;
  347. DWORD cbValueName, cbData;
  348. VALIDATE_PROTOTYPE(RegEnumValue);
  349. if (g_bRunningOnNT)
  350. return RegEnumValueW(hKey, dwIndex, lpValueName, lpcbValueName, lpReserved, lpType, lpData, lpcbData);
  351. // [PaulHi] Validate return parameters
  352. if (!lpValueName || !lpcbValueName)
  353. return ERROR_INVALID_PARAMETER;
  354. if ( lpData && lpcbData &&( *lpcbData != 0 ) )
  355. {
  356. lpDataA = LocalAlloc( LMEM_ZEROINIT, *lpcbData );
  357. cbData = *lpcbData;
  358. }
  359. cbValueName = MAX_PATH;
  360. lRetValue = RegEnumValueA(hKey, dwIndex, lpValueNameA, &cbValueName, lpReserved, lpType, lpDataA, &cbData);
  361. if ( lRetValue != ERROR_SUCCESS ) return lRetValue;
  362. lpValueNameW = ConvertAtoW( lpValueNameA );
  363. cbValueName = My_wcslen( lpValueNameW ) + 1;
  364. if ( lpType && (*lpType != REG_EXPAND_SZ) && ( *lpType!= REG_MULTI_SZ) && ( *lpType != REG_SZ ) )
  365. {
  366. CopyMemory(lpValueName, lpValueNameW, cbValueName * sizeof(WCHAR) );
  367. *lpcbValueName = cbValueName;
  368. if ( lpData && lpcbData) {
  369. CopyMemory(lpData, lpDataA, cbData );
  370. *lpcbData = cbData;
  371. LocalFreeAndNull( &lpDataA );
  372. }
  373. LocalFreeAndNull( &lpValueNameW );
  374. return lRetValue;
  375. }
  376. if ( lpType && ((*lpType == REG_EXPAND_SZ) || (*lpType == REG_SZ)) )
  377. {
  378. CopyMemory(lpValueName, lpValueNameW, cbValueName * sizeof(WCHAR) );
  379. *lpcbValueName = cbValueName;
  380. if ( lpData && lpcbData ) {
  381. LPWSTR lpDataW;
  382. lpDataW = ConvertAtoW( lpDataA );
  383. cbData = My_wcslen(lpDataW) + 1;
  384. CopyMemory(lpData, lpDataW, cbData * sizeof(WCHAR) );
  385. *lpcbData = cbData * sizeof(WCHAR);
  386. LocalFreeAndNull( &lpDataW );
  387. }
  388. LocalFreeAndNull( &lpValueNameW );
  389. return lRetValue;
  390. }
  391. // the last case REG_MULTI_SZ.
  392. CopyMemory(lpValueName, lpValueNameW, cbValueName * sizeof(WCHAR) );
  393. *lpcbValueName = cbValueName;
  394. if ( lpData && lpcbData ) {
  395. LPWSTR lpDataW= NULL;
  396. LPSTR lpDataAt = NULL;
  397. LPWSTR lpDataT = NULL;
  398. DWORD cbDataAll;
  399. lpDataAt = lpDataA;
  400. cbDataAll = 0;
  401. lpDataT = (LPWSTR)lpData;
  402. while ( *lpDataAt != '\0' ) {
  403. lpDataW = ConvertAtoW( lpDataAt );
  404. cbDataAll += My_wcslen( lpDataW ) + 1;
  405. My_wcscpy(lpDataT, lpDataW);
  406. lpDataT += My_wcslen(lpDataW) + 1;
  407. lpDataAt += lstrlenA(lpDataAt) + 1;
  408. LocalFreeAndNull( &lpDataW );
  409. }
  410. cbDataAll ++;
  411. *lpDataT = 0x0000;
  412. *lpcbData = cbDataAll * sizeof(WCHAR);
  413. }
  414. LocalFreeAndNull( &lpValueNameW );
  415. return lRetValue;
  416. }
  417. // RegDeleteValue
  418. LONG WINAPI RegDeleteValueWrapW( HKEY hKey, // handle to key
  419. LPCTSTR lpValueName ) // address of value name
  420. {
  421. LPSTR lpValueNameA = NULL;
  422. LONG lRetValue=0;
  423. VALIDATE_PROTOTYPE(RegDeleteValue);
  424. if (g_bRunningOnNT)
  425. return RegDeleteValueW(hKey, lpValueName);
  426. lpValueNameA = ConvertWtoA( lpValueName );
  427. lRetValue = RegDeleteValueA( hKey, lpValueNameA );
  428. LocalFreeAndNull( & lpValueNameA );
  429. return lRetValue;
  430. }
  431. // RegCreateKey
  432. LONG WINAPI RegCreateKeyWrapW( HKEY hKey, // handle to an open key
  433. LPCTSTR lpSubKey, // address of name of subkey to open
  434. PHKEY phkResult ) // address of buffer for opened handle
  435. {
  436. LPSTR lpSubKeyA = NULL;
  437. LONG lRetValue =0;
  438. VALIDATE_PROTOTYPE(RegCreateKey);
  439. if (g_bRunningOnNT)
  440. return RegCreateKeyW(hKey, lpSubKey, phkResult);
  441. lpSubKeyA = ConvertWtoA( lpSubKey );
  442. lRetValue = RegCreateKeyA(hKey, lpSubKeyA, phkResult);
  443. LocalFreeAndNull( &lpSubKeyA );
  444. return lRetValue;
  445. }
  446. // in header file wincrypt.h
  447. // CryptAcquireContext
  448. BOOL WINAPI CryptAcquireContextWrapW( HCRYPTPROV *phProv, // out
  449. LPCTSTR pszContainer, // in
  450. LPCTSTR pszProvider, // in
  451. DWORD dwProvType, // in
  452. DWORD dwFlags ) // in
  453. {
  454. LPSTR pszContainerA = NULL;
  455. LPSTR pszProviderA = NULL;
  456. BOOL bRetValue =0;
  457. VALIDATE_PROTOTYPE(CryptAcquireContext);
  458. if (g_bRunningOnNT)
  459. return CryptAcquireContextW(phProv, pszContainer, pszProvider, dwProvType, dwFlags );
  460. pszContainerA = ConvertWtoA( pszContainer );
  461. pszProviderA = ConvertWtoA ( pszProvider );
  462. bRetValue = CryptAcquireContextA(phProv, pszContainerA, pszProviderA, dwProvType, dwFlags );
  463. LocalFreeAndNull( &pszContainerA );
  464. LocalFreeAndNull( &pszProviderA );
  465. return bRetValue;
  466. }
  467. LONG WINAPI RegQueryValueExWrapW( HKEY hKey, // handle to key to query
  468. LPCTSTR lpValueName, // address of name of value to query
  469. LPDWORD lpReserved, // reserved
  470. LPDWORD lpType, // address of buffer for value type
  471. LPBYTE lpData, // address of data buffer
  472. LPDWORD lpcbData ) // address of data buffer size
  473. {
  474. LONG lRetValue =0;
  475. LPSTR lpValueNameA= NULL;
  476. LPWSTR lpDataW= NULL;
  477. LPSTR lpDataA = NULL;
  478. DWORD cbData=0;
  479. DWORD dwRealType;
  480. // VALIDATE_PROTOTYPE(RegQueryValueEx);
  481. if (g_bRunningOnNT)
  482. return RegQueryValueExW(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData );
  483. cbData = 0;
  484. if ( lpData && lpcbData &&( *lpcbData != 0 ) )
  485. {
  486. lpDataA = LocalAlloc( LMEM_ZEROINIT, *lpcbData );
  487. cbData = *lpcbData;
  488. }
  489. lpValueNameA = ConvertWtoA(lpValueName);
  490. lRetValue = RegQueryValueExA(hKey, lpValueNameA, lpReserved, &dwRealType, lpDataA, &cbData);
  491. if (lpType)
  492. *lpType = dwRealType;
  493. if ( (lRetValue != ERROR_SUCCESS) || (lpData == NULL) || (lpcbData == NULL ) ) {
  494. LocalFreeAndNull( &lpValueNameA );
  495. return lRetValue;
  496. }
  497. if ( (dwRealType != REG_EXPAND_SZ) && ( dwRealType != REG_MULTI_SZ) && ( dwRealType != REG_SZ ) ){
  498. CopyMemory(lpData, lpDataA, cbData );
  499. *lpcbData = cbData;
  500. LocalFreeAndNull( &lpDataA );
  501. LocalFreeAndNull( &lpValueNameA );
  502. return lRetValue;
  503. }
  504. if ( (dwRealType == REG_EXPAND_SZ) || (dwRealType == REG_SZ) ) {
  505. LPWSTR lpDataW= NULL;
  506. lpDataW = ConvertAtoW( lpDataA );
  507. cbData = My_wcslen(lpDataW) + 1;
  508. CopyMemory(lpData, lpDataW, cbData * sizeof(WCHAR) );
  509. *lpcbData = cbData * sizeof(WCHAR);
  510. LocalFreeAndNull( &lpDataW );
  511. LocalFreeAndNull( &lpDataA );
  512. LocalFreeAndNull( &lpValueNameA );
  513. return lRetValue;
  514. }
  515. // the last case REG_MULTI_SZ.
  516. if (lpData && lpcbData) {
  517. LPWSTR lpDataW= NULL;
  518. LPSTR lpDataAt= NULL;
  519. LPWSTR lpDataT= NULL;
  520. DWORD cbDataAll=0;
  521. lpDataAt = lpDataA;
  522. cbDataAll = 0;
  523. lpDataT = (LPWSTR)lpData;
  524. while ( *lpDataAt != '\0' ) {
  525. lpDataW = ConvertAtoW( lpDataAt );
  526. cbDataAll += My_wcslen( lpDataW ) + 1;
  527. My_wcscpy(lpDataT, lpDataW);
  528. lpDataT += My_wcslen(lpDataW) + 1;
  529. lpDataAt += lstrlenA(lpDataAt) + 1;
  530. LocalFreeAndNull( &lpDataW );
  531. }
  532. cbDataAll ++;
  533. *lpDataT = 0x0000;
  534. *lpcbData = cbDataAll * sizeof(WCHAR);
  535. }
  536. LocalFreeAndNull( &lpDataA );
  537. LocalFreeAndNull( &lpValueNameA );
  538. return lRetValue;
  539. }
  540. // RegCreateKeyEx
  541. LONG WINAPI RegCreateKeyExWrapW( HKEY hKey, // handle to an open key
  542. LPCTSTR lpSubKey, // address of subkey name
  543. DWORD Reserved, // reserved
  544. LPTSTR lpClass, // address of class string
  545. DWORD dwOptions, // special options flag
  546. REGSAM samDesired, // desired security access
  547. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  548. // address of key security structure
  549. PHKEY phkResult, // address of buffer for opened handle
  550. LPDWORD lpdwDisposition ) // address of disposition value buffer
  551. {
  552. LPSTR lpSubKeyA = NULL;
  553. LPSTR lpClassA = NULL;
  554. LONG lRetValue=0;
  555. VALIDATE_PROTOTYPE(RegCreateKeyEx);
  556. if (g_bRunningOnNT)
  557. return RegCreateKeyExW(hKey,
  558. lpSubKey,
  559. Reserved,
  560. lpClass,
  561. dwOptions,
  562. samDesired,
  563. lpSecurityAttributes,
  564. phkResult,
  565. lpdwDisposition);
  566. lpSubKeyA = ConvertWtoA( lpSubKey );
  567. lpClassA = ConvertWtoA ( lpClass );
  568. lRetValue = RegCreateKeyExA(hKey,
  569. lpSubKeyA,
  570. Reserved,
  571. lpClassA,
  572. dwOptions,
  573. samDesired,
  574. lpSecurityAttributes,
  575. phkResult,
  576. lpdwDisposition);
  577. LocalFreeAndNull( &lpSubKeyA );
  578. LocalFreeAndNull( &lpClassA );
  579. return lRetValue;
  580. }
  581. // RegSetValueEx
  582. LONG WINAPI RegSetValueExWrapW( HKEY hKey, // handle to key to set value for
  583. LPCTSTR lpValueName, // name of the value to set
  584. DWORD Reserved, // reserved
  585. DWORD dwType, // flag for value type
  586. CONST BYTE *lpData, // address of value data
  587. DWORD cbData ) // size of value data
  588. {
  589. LPSTR lpValueNameA = NULL;
  590. LPSTR lpStrA= NULL;
  591. BYTE *lpDataA= NULL;
  592. DWORD cbDataA=0;
  593. LONG lRetValue=0;
  594. VALIDATE_PROTOTYPE(RegSetValueEx);
  595. if (g_bRunningOnNT)
  596. return RegSetValueExW(hKey, lpValueName, Reserved, dwType, lpData, cbData);
  597. lpValueNameA = ConvertWtoA( lpValueName );
  598. if ( ( dwType != REG_EXPAND_SZ ) && (dwType != REG_MULTI_SZ) && (dwType != REG_SZ) ) {
  599. lRetValue = RegSetValueExA(hKey, lpValueNameA, Reserved, dwType, lpData, cbData);
  600. LocalFreeAndNull( &lpValueNameA );
  601. return lRetValue;
  602. }
  603. if ( ( dwType == REG_EXPAND_SZ) || ( dwType == REG_SZ ) ) {
  604. lpDataA = ConvertWtoA( (LPWSTR) lpData );
  605. cbDataA = lstrlenA(lpDataA) + 1;
  606. lRetValue = RegSetValueExA(hKey, lpValueNameA, Reserved, dwType, lpDataA, cbDataA);
  607. LocalFreeAndNull( &lpValueNameA );
  608. LocalFreeAndNull( &lpDataA );
  609. return lRetValue;
  610. }
  611. // the last case is for REG_MULT_SZ
  612. if ( lpData ) {
  613. LPWSTR lpDataWt= NULL;
  614. LPSTR lpDataAt= NULL;
  615. DWORD cbDataAll=0;
  616. lpDataA = LocalAlloc(LMEM_ZEROINIT, cbData);
  617. lpDataAt = lpDataA;
  618. cbDataAll = 0;
  619. lpDataWt = (LPWSTR)lpData;
  620. while ( *lpDataWt != 0x0000 ) {
  621. WideCharToMultiByte(CP_ACP,0, lpDataWt, -1, lpDataAt, -1, NULL, NULL );
  622. cbDataAll += lstrlenA(lpDataAt) + 1;
  623. lpDataWt += My_wcslen(lpDataWt) + 1;
  624. lpDataAt += lstrlenA(lpDataAt) + 1;
  625. }
  626. cbDataAll ++;
  627. *lpDataAt = 0x00;
  628. lRetValue = RegSetValueExA(hKey, lpValueNameA, Reserved, dwType, lpDataA, cbDataAll);
  629. LocalFreeAndNull( &lpDataA );
  630. LocalFreeAndNull( &lpValueNameA );
  631. return lRetValue;
  632. }
  633. return FALSE;
  634. return GetLastError();
  635. }
  636. // RegQueryInfoKey
  637. LONG WINAPI RegQueryInfoKeyWrapW( HKEY hKey, // handle to key to query
  638. LPTSTR lpClass, // address of buffer for class string
  639. LPDWORD lpcbClass, // address of size of class string buffer
  640. LPDWORD lpReserved, // reserved
  641. LPDWORD lpcSubKeys, // address of buffer for number of subkeys
  642. LPDWORD lpcbMaxSubKeyLen, // address of buffer for longest subkey
  643. // name length
  644. LPDWORD lpcbMaxClassLen, // address of buffer for longest class
  645. // string length
  646. LPDWORD lpcValues, // address of buffer for number of value
  647. // entries
  648. LPDWORD lpcbMaxValueNameLen, // address of buffer for longest
  649. // value name length
  650. LPDWORD lpcbMaxValueLen, // address of buffer for longest value
  651. // data length
  652. LPDWORD lpcbSecurityDescriptor,
  653. // address of buffer for security
  654. // descriptor length
  655. PFILETIME lpftLastWriteTime) // address of buffer for last write time
  656. {
  657. LPSTR lpClassA= NULL;
  658. LONG lRetValue=0;
  659. VALIDATE_PROTOTYPE(RegQueryInfoKey);
  660. if (g_bRunningOnNT)
  661. return RegQueryInfoKeyW(hKey, lpClass, lpcbClass, lpReserved, lpcSubKeys,
  662. lpcbMaxSubKeyLen, lpcbMaxClassLen, lpcValues, lpcbMaxValueNameLen,
  663. lpcbMaxValueLen,lpcbSecurityDescriptor,lpftLastWriteTime );
  664. lpClassA = ConvertWtoA( lpClass );
  665. lRetValue = RegQueryInfoKeyA(hKey, lpClassA, lpcbClass, lpReserved, lpcSubKeys,
  666. lpcbMaxSubKeyLen, lpcbMaxClassLen, lpcValues, lpcbMaxValueNameLen,
  667. lpcbMaxValueLen,lpcbSecurityDescriptor,lpftLastWriteTime );
  668. LocalFreeAndNull( &lpClassA );
  669. return lRetValue;
  670. }
  671. //GDI32.DLL
  672. //GetObject
  673. int WINAPI GetObjectWrapW( HGDIOBJ hgdiobj, // handle to graphics object of interest
  674. int cbBuffer, // size of buffer for object information
  675. LPVOID lpvObject ) // pointer to buffer for object information
  676. {
  677. int iRetValue =0;
  678. LOGFONTA lfFontA;
  679. LOGFONTW lfFontW;
  680. VALIDATE_PROTOTYPE(GetObject);
  681. if (g_bRunningOnNT)
  682. return GetObjectW(hgdiobj, cbBuffer, lpvObject);
  683. if ( GetObjectType(hgdiobj) != OBJ_FONT ) {
  684. iRetValue = GetObjectA( hgdiobj, cbBuffer, lpvObject );
  685. return iRetValue;
  686. }
  687. // if Object type is HFONT, the return value lpvObject will point to LOGFONT which contains
  688. // a field lpFaceName with TCHAR * type.
  689. if ( cbBuffer != sizeof(LOGFONTW) )
  690. return 0;
  691. if (lpvObject == NULL ) return sizeof(LOGFONTW);
  692. iRetValue = GetObjectA( hgdiobj, sizeof(lfFontA), &lfFontA );
  693. if (iRetValue == 0 ) return 0;
  694. iRetValue = sizeof(LOGFONTW);
  695. // copy all the fields except lfFaceName from lfFontA to lfFontW
  696. CopyMemory(&lfFontW,&lfFontA, sizeof(LOGFONTA) );
  697. // translate the lfFaceName[] from A to W
  698. MultiByteToWideChar(GetACP(), 0, lfFontA.lfFaceName, LF_FACESIZE, lfFontW.lfFaceName, LF_FACESIZE);
  699. CopyMemory(lpvObject, &lfFontW, sizeof(LOGFONTW) );
  700. return iRetValue;
  701. }
  702. // StartDoc
  703. int WINAPI StartDocWrapW( HDC hdc, // handle to device context
  704. CONST DOCINFO *lpdi ) // address of structure with file names
  705. {
  706. int iRetValue=0;
  707. DOCINFOA diA;
  708. LPSTR lpszDocName= NULL, lpszOutput= NULL, lpszDatatype= NULL;
  709. VALIDATE_PROTOTYPE(StartDoc);
  710. if (g_bRunningOnNT)
  711. return StartDocW(hdc,lpdi);
  712. diA.cbSize = sizeof(DOCINFOA);
  713. lpszDocName = ConvertWtoA( lpdi->lpszDocName );
  714. lpszOutput = ConvertWtoA( lpdi->lpszOutput );
  715. lpszDatatype= ConvertWtoA( lpdi->lpszDatatype);
  716. diA.lpszDocName = lpszDocName;
  717. diA.lpszOutput = lpszOutput;
  718. diA.lpszDatatype = lpszDatatype;
  719. diA.fwType = lpdi->fwType;
  720. iRetValue = StartDocA( hdc, &diA );
  721. LocalFreeAndNull( &lpszDocName );
  722. LocalFreeAndNull( &lpszOutput );
  723. LocalFreeAndNull( &lpszDatatype );
  724. return iRetValue;
  725. }
  726. // CreateFontIndirect
  727. HFONT WINAPI CreateFontIndirectWrapW (CONST LOGFONT *lplf ) // pointer to logical font structure
  728. {
  729. HFONT hRetValue;
  730. LOGFONTA lfFontA;
  731. VALIDATE_PROTOTYPE(CreateFontIndirect);
  732. if (g_bRunningOnNT)
  733. return CreateFontIndirectW(lplf);
  734. // copy LOGFONTW 's fields except lfFaceName to lfFontA.
  735. CopyMemory(&lfFontA, lplf, sizeof(LOGFONTW) - LF_FACESIZE * sizeof(WCHAR) );
  736. WideCharToMultiByte(CP_ACP, 0, lplf->lfFaceName, LF_FACESIZE, lfFontA.lfFaceName, LF_FACESIZE, NULL, NULL );
  737. hRetValue = CreateFontIndirectA( &lfFontA );
  738. return hRetValue;
  739. }
  740. //KERNEL32.DLL
  741. // GetLocaleInfo
  742. int WINAPI GetLocaleInfoWrapW( LCID Locale, // locale identifier
  743. LCTYPE LCType, // type of information
  744. LPTSTR lpLCData, // address of buffer for information
  745. int cchData ) // size of buffer
  746. {
  747. int iRetValue=0;
  748. LPSTR lpLCDataA= NULL;
  749. int cchDataA=0;
  750. LPWSTR lpLCDataW= NULL;
  751. int cchDataW=0;
  752. VALIDATE_PROTOTYPE(GetLocaleInfo);
  753. if (g_bRunningOnNT)
  754. return GetLocaleInfoW(Locale, LCType, lpLCData, cchData);
  755. iRetValue = GetLocaleInfoA(Locale, LCType, NULL, 0);
  756. if ( iRetValue == 0 ) return iRetValue;
  757. cchDataA = iRetValue;
  758. lpLCDataA = LocalAlloc(LMEM_ZEROINIT, cchDataA+1 );
  759. iRetValue = GetLocaleInfoA(Locale, LCType, lpLCDataA, cchDataA);
  760. lpLCDataA[cchDataA] = '\0';
  761. lpLCDataW = ConvertAtoW( lpLCDataA );
  762. cchDataW = My_wcslen( lpLCDataW );
  763. if ( (cchData == 0) || (lpLCData == NULL) ) {
  764. LocalFreeAndNull(&lpLCDataA);
  765. LocalFreeAndNull(&lpLCDataW);
  766. return cchDataW ;
  767. }
  768. CopyMemory(lpLCData, lpLCDataW, cchDataW * sizeof(WCHAR) );
  769. lpLCData[cchDataW] = '\0';
  770. LocalFreeAndNull(&lpLCDataA);
  771. LocalFreeAndNull(&lpLCDataW);
  772. return cchData;
  773. }
  774. // CreateDirectory
  775. BOOL WINAPI CreateDirectoryWrapW(LPCTSTR lpPathName, // pointer to directory path string
  776. LPSECURITY_ATTRIBUTES lpSecurityAttributes)// pointer to security descriptor
  777. {
  778. BOOL bRetValue = FALSE;
  779. LPSTR lpPathNameA = NULL;
  780. VALIDATE_PROTOTYPE(CreateDirectory);
  781. if (g_bRunningOnNT)
  782. return CreateDirectoryW(lpPathName, lpSecurityAttributes);
  783. lpPathNameA = ConvertWtoA( lpPathName );
  784. bRetValue = CreateDirectoryA( lpPathNameA, lpSecurityAttributes );
  785. LocalFreeAndNull( &lpPathNameA );
  786. return bRetValue;
  787. }
  788. // GetWindowsDirectory
  789. UINT WINAPI GetWindowsDirectoryWrapW( LPTSTR lpBuffer, // address of buffer for Windows directory
  790. UINT uSize ) // size of directory buffer
  791. {
  792. UINT uRetValue = 0;
  793. LPSTR lpBufferA = NULL;
  794. VALIDATE_PROTOTYPE(GetWindowsDirectory);
  795. if (g_bRunningOnNT)
  796. return GetWindowsDirectoryW(lpBuffer, uSize);
  797. lpBufferA = LocalAlloc( LMEM_ZEROINIT, uSize * sizeof(WCHAR) );
  798. uRetValue = GetWindowsDirectoryA( lpBufferA, uSize * sizeof(WCHAR) );
  799. uRetValue =MultiByteToWideChar(GetACP( ), 0, lpBufferA, -1, lpBuffer, uSize);
  800. LocalFreeAndNull( &lpBufferA );
  801. return uRetValue;
  802. }
  803. // GetSystemDirectory
  804. UINT WINAPI GetSystemDirectoryWrapW( LPTSTR lpBuffer, // address of buffer for system directory
  805. UINT uSize ) // size of directory buffer
  806. {
  807. UINT uRetValue = 0;
  808. LPSTR lpBufferA = NULL;
  809. VALIDATE_PROTOTYPE(GetSystemDirectory);
  810. if (g_bRunningOnNT)
  811. return GetSystemDirectoryW(lpBuffer, uSize);
  812. lpBufferA = LocalAlloc( LMEM_ZEROINIT, uSize * sizeof(WCHAR) );
  813. uRetValue = GetSystemDirectoryA( lpBufferA, uSize * sizeof(WCHAR) );
  814. uRetValue =MultiByteToWideChar(GetACP( ), 0, lpBufferA, -1, lpBuffer, uSize);
  815. LocalFreeAndNull( &lpBufferA );
  816. return uRetValue;
  817. }
  818. // GetStringType the parameters are not the same
  819. BOOL WINAPI GetStringTypeWrapW( DWORD dwInfoType, // information-type options
  820. LPCTSTR lpSrcStr, // pointer to the source string
  821. int cchSrc, // size, in Characters, of the source string
  822. LPWORD lpCharType ) // pointer to the buffer for output
  823. {
  824. BOOL bRetValue = 0;
  825. LPSTR lpSrcStrA = NULL;
  826. VALIDATE_PROTOTYPE(GetStringType);
  827. if (g_bRunningOnNT)
  828. return GetStringTypeW(dwInfoType, lpSrcStr, cchSrc, lpCharType);
  829. lpSrcStrA = ConvertWtoA( lpSrcStr );
  830. bRetValue = GetStringTypeA( LOCALE_USER_DEFAULT, dwInfoType, lpSrcStrA, -1, lpCharType);
  831. LocalFreeAndNull( &lpSrcStrA );
  832. return bRetValue;
  833. }
  834. // GetProfileInt
  835. UINT WINAPI GetProfileIntWrapW( LPCTSTR lpAppName, // address of section name
  836. LPCTSTR lpKeyName, // address of key name
  837. INT nDefault ) // default value if key name is not found
  838. {
  839. UINT uRetValue = 0;
  840. LPSTR lpAppNameA = NULL;
  841. LPSTR lpKeyNameA = NULL;
  842. VALIDATE_PROTOTYPE(GetProfileInt);
  843. if (g_bRunningOnNT)
  844. return GetProfileIntW(lpAppName, lpKeyName, nDefault);
  845. lpAppNameA = ConvertWtoA( lpAppName );
  846. lpKeyNameA = ConvertWtoA( lpKeyName );
  847. uRetValue = GetProfileIntA( lpAppNameA, lpKeyNameA, nDefault);
  848. LocalFreeAndNull( &lpAppNameA );
  849. LocalFreeAndNull( &lpKeyNameA );
  850. return uRetValue;
  851. }
  852. // LCMapString
  853. int WINAPI LCMapStringWrapW( LCID Locale, // locale identifier
  854. DWORD dwMapFlags, // mapping transformation type
  855. LPCTSTR lpSrcStr, // address of source string
  856. int cchSrc, // number of characters in source string
  857. LPTSTR lpDestStr, // address of destination buffer
  858. int cchDest ) // size of destination buffer
  859. {
  860. int iRetValue =0;
  861. LPSTR lpSrcStrA = NULL;
  862. LPSTR lpDestStrA = NULL;
  863. LPWSTR lpDestStrW = NULL;
  864. int cchSrcA, cchDestA, cchDestW;
  865. VALIDATE_PROTOTYPE(LCMapString);
  866. if (g_bRunningOnNT)
  867. return LCMapStringW(Locale, dwMapFlags, lpSrcStr, cchSrc, lpDestStr, cchDest);
  868. lpSrcStrA = ConvertWtoA( lpSrcStr );
  869. cchSrcA = lstrlenA(lpSrcStrA);
  870. lpDestStrA = LocalAlloc(LMEM_ZEROINIT, cchDest * sizeof(WCHAR) );
  871. cchDestA = cchDest * sizeof(WCHAR);
  872. iRetValue = LCMapStringA(Locale,dwMapFlags,lpSrcStrA,cchSrcA,lpDestStrA,cchDestA);
  873. // [PaulHi] 6/8/99 Don't fill the buffer if the pointer is NULL.
  874. if (lpDestStr && iRetValue != 0)
  875. {
  876. lpDestStrW = ConvertAtoW(lpDestStrA);
  877. iRetValue = My_wcslen(lpDestStrW) + 1;
  878. // Ensure that we don't overwrite the output buffer
  879. iRetValue = (iRetValue <= cchDest) ? iRetValue : cchDest;
  880. CopyMemory( lpDestStr, lpDestStrW, iRetValue * sizeof(WCHAR) );
  881. LocalFreeAndNull( &lpDestStrW );
  882. }
  883. LocalFreeAndNull( &lpDestStrA );
  884. LocalFreeAndNull( &lpSrcStrA );
  885. return iRetValue;
  886. }
  887. // GetFileAttributes
  888. DWORD WINAPI GetFileAttributesWrapW( LPCTSTR lpFileName ) // pointer to the name of a file or directory
  889. {
  890. DWORD dRetValue =0;
  891. LPSTR lpFileNameA = NULL;
  892. VALIDATE_PROTOTYPE(GetFileAttributes);
  893. if (g_bRunningOnNT)
  894. return GetFileAttributes(lpFileName);
  895. lpFileNameA = ConvertWtoA( lpFileName );
  896. dRetValue = GetFileAttributesA(lpFileNameA );
  897. LocalFreeAndNull ( &lpFileNameA );
  898. return dRetValue;
  899. }
  900. // CompareString
  901. int WINAPI CompareStringWrapW( LCID Locale, // locale identifier
  902. DWORD dwCmpFlags, // comparison-style options
  903. LPCWSTR lpString1, // pointer to first string
  904. int cchCount1, // size, in bytes or characters, of first string
  905. LPCWSTR lpString2, // pointer to second string
  906. int cchCount2 ) // size, in bytes or characters, of second string
  907. {
  908. int iRetValue =0;
  909. LPSTR lpString1A = NULL,
  910. lpString2A = NULL;
  911. LPWSTR pszString1 = NULL,
  912. pszString2 = NULL;
  913. VALIDATE_PROTOTYPE(CompareString);
  914. if (g_bRunningOnNT)
  915. return CompareStringW(Locale, dwCmpFlags, lpString1, cchCount1, lpString2, cchCount2);
  916. // [PaulHi] 4/1/99 Raid 75303 If the character count value(s) are -1 then the
  917. // input string(s) are already zero terminated and can be converted to ANSI directly.
  918. Assert(lpString1);
  919. Assert(lpString2);
  920. if (cchCount1 == -1)
  921. {
  922. // Already zero terminated string
  923. // Not great to cast const to non-const, but we don't modify the string
  924. pszString1 = (LPWSTR)lpString1;
  925. }
  926. else
  927. {
  928. // Convert to zero terminated string
  929. pszString1 = LocalAlloc(LMEM_FIXED, (cchCount1+1)*sizeof(WCHAR));
  930. if (!pszString1)
  931. goto exit;
  932. // Zero inited buffer
  933. lstrcpynWrapW(pszString1, lpString1, cchCount1+1);
  934. }
  935. if (cchCount2 == -1)
  936. {
  937. // Already zero terminated string
  938. // Not great to cast const to non-const, but we don't modify the string
  939. pszString2 = (LPWSTR)lpString2;
  940. }
  941. else
  942. {
  943. // Convert to zero terminated string
  944. pszString2 = LocalAlloc(LMEM_FIXED, (cchCount2+1)*sizeof(WCHAR));
  945. if (!pszString2)
  946. goto exit;
  947. // Zero inited buffer
  948. lstrcpynWrapW(pszString2, lpString2, cchCount2+1);
  949. }
  950. // Convert to ANSI, statistically improve our odds by checking that there
  951. // wasn't data loss on the first character. It's too expensive to do a
  952. // full test every time.
  953. lpString1A = ConvertWtoA( pszString1 );
  954. if (!lpString1A || (lpString1A[0]=='?' && pszString1[0]!=L'?'))
  955. goto exit;
  956. lpString2A = ConvertWtoA( pszString2 );
  957. if (!lpString2A || (lpString2A[0]=='?' && pszString2[0]!=L'?'))
  958. goto exit;
  959. iRetValue = CompareStringA(Locale,dwCmpFlags,lpString1A,lstrlenA(lpString1A),lpString2A,lstrlenA(lpString2A));
  960. exit:
  961. LocalFreeAndNull( &lpString1A );
  962. LocalFreeAndNull( &lpString2A );
  963. // Only deallocate if allocated locally
  964. if (pszString1 != (LPWSTR)lpString1)
  965. LocalFreeAndNull( &pszString1 );
  966. if (pszString2 != (LPWSTR)lpString2)
  967. LocalFreeAndNull( &pszString2 );
  968. return iRetValue;
  969. }
  970. // lstrcpy
  971. LPTSTR WINAPI lstrcpyWrapW( LPTSTR lpString1, // pointer to buffer
  972. LPCTSTR lpString2 ) // pointer to string to copy
  973. {
  974. VALIDATE_PROTOTYPE(lstrcpy);
  975. if (g_bRunningOnNT)
  976. return lstrcpyW(lpString1, lpString2);
  977. CopyMemory(lpString1, lpString2, (My_wcslen(lpString2) + 1) * sizeof(WCHAR) );
  978. return lpString1;
  979. }
  980. // lstrcmpi
  981. int WINAPI lstrcmpiWrapW( LPCTSTR lpString1, // pointer to first string
  982. LPCTSTR lpString2 ) // pointer to second string
  983. {
  984. int iRetValue = 0;
  985. LPSTR lpString1A = NULL ;
  986. LPSTR lpString2A = NULL ;
  987. VALIDATE_PROTOTYPE(lstrcmpi);
  988. if (g_bRunningOnNT)
  989. return lstrcmpiW(lpString1, lpString2);
  990. lpString1A = ConvertWtoA( lpString1 );
  991. lpString2A = ConvertWtoA( lpString2 );
  992. iRetValue = lstrcmpiA(lpString1A, lpString2A );
  993. LocalFreeAndNull( &lpString1A );
  994. LocalFreeAndNull( &lpString2A );
  995. return iRetValue;
  996. }
  997. // LoadLibrary
  998. HINSTANCE WINAPI LoadLibraryWrapW( LPCTSTR lpLibFileName ) // address of filename of executable module
  999. {
  1000. HINSTANCE hRetValue =0;
  1001. LPSTR lpLibFileNameA = NULL;
  1002. VALIDATE_PROTOTYPE(LoadLibrary);
  1003. if (g_bRunningOnNT)
  1004. return LoadLibraryW(lpLibFileName);
  1005. lpLibFileNameA = ConvertWtoA(lpLibFileName);
  1006. hRetValue = LoadLibraryA( lpLibFileNameA );
  1007. LocalFreeAndNull( &lpLibFileNameA );
  1008. return hRetValue;
  1009. }
  1010. // GetTextExtentPoint32
  1011. BOOL WINAPI GetTextExtentPoint32WrapW(HDC hdc,
  1012. LPCWSTR pwszBuf,
  1013. int nLen,
  1014. LPSIZE psize)
  1015. {
  1016. LPSTR pszBuf = NULL;
  1017. BOOL bRtn = FALSE;
  1018. VALIDATE_PROTOTYPE(GetTextExtentPoint32);
  1019. if (g_bRunningOnNT)
  1020. return GetTextExtentPoint32W(hdc, pwszBuf, nLen, psize);
  1021. pszBuf = ConvertWtoA(pwszBuf);
  1022. if (pszBuf)
  1023. {
  1024. nLen = lstrlenA(pszBuf);
  1025. bRtn = GetTextExtentPoint32A(hdc, pszBuf, nLen, psize);
  1026. LocalFreeAndNull(&pszBuf);
  1027. }
  1028. else
  1029. {
  1030. psize->cx = 0;
  1031. psize->cy = 0;
  1032. }
  1033. return bRtn;
  1034. }
  1035. // GetTimeFormat
  1036. int WINAPI GetTimeFormatWrapW( LCID Locale, // locale for which time is to be formatted
  1037. DWORD dwFlags, // flags specifying function options
  1038. CONST SYSTEMTIME *lpTime, // time to be formatted
  1039. LPCTSTR lpFormat, // time format string
  1040. LPTSTR lpTimeStr, // buffer for storing formatted string
  1041. int cchTime ) // size, in bytes or characters, of the buffer
  1042. {
  1043. int iRetValue =0;
  1044. LPSTR lpFormatA = NULL;
  1045. LPWSTR lpTimeStrW = NULL;
  1046. LPSTR lpTimeStrA = NULL;
  1047. int cchTimeA=0, cchTimeW=0;
  1048. VALIDATE_PROTOTYPE(GetTimeFormat);
  1049. if (g_bRunningOnNT)
  1050. return GetTimeFormatW(Locale, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime);
  1051. lpFormatA = ConvertWtoA( lpFormat );
  1052. cchTimeA = GetTimeFormatA(Locale, dwFlags, lpTime, lpFormatA, NULL, 0);
  1053. lpTimeStrA = LocalAlloc(LMEM_ZEROINIT, cchTimeA );
  1054. iRetValue = GetTimeFormatA(Locale, dwFlags, lpTime, lpFormatA, lpTimeStrA, cchTimeA );
  1055. if ( iRetValue != 0 ) {
  1056. lpTimeStrW = ConvertAtoW( lpTimeStrA );
  1057. cchTimeW = My_wcslen( lpTimeStrW ) + 1;
  1058. iRetValue = cchTimeW;
  1059. if ( (cchTime !=0) && ( lpTimeStr != NULL ) ) {
  1060. CopyMemory(lpTimeStr, lpTimeStrW, cchTimeW * sizeof(WCHAR) );
  1061. }
  1062. LocalFreeAndNull( &lpTimeStrW );
  1063. }
  1064. LocalFreeAndNull( &lpFormatA );
  1065. LocalFreeAndNull( &lpTimeStrA );
  1066. return iRetValue;
  1067. }
  1068. // GetDateFormat
  1069. int WINAPI GetDateFormatWrapW( LCID Locale, // locale for which date is to be formatted
  1070. DWORD dwFlags, // flags specifying function options
  1071. CONST SYSTEMTIME *lpDate, // date to be formatted
  1072. LPCTSTR lpFormat, // date format string
  1073. LPTSTR lpDateStr, // buffer for storing formatted string
  1074. int cchDate ) // size of buffer
  1075. {
  1076. int iRetValue = 0;
  1077. LPSTR lpFormatA = NULL;
  1078. LPWSTR lpDateStrW = NULL;
  1079. LPSTR lpDateStrA = NULL;
  1080. int cchDateA, cchDateW;
  1081. VALIDATE_PROTOTYPE(GetDateFormat);
  1082. if (g_bRunningOnNT)
  1083. return GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, lpDateStr, cchDate);
  1084. lpFormatA = ConvertWtoA( lpFormat );
  1085. cchDateA = GetDateFormatA(Locale, dwFlags, lpDate, lpFormatA, NULL, 0);
  1086. lpDateStrA = LocalAlloc(LMEM_ZEROINIT, cchDateA );
  1087. iRetValue = GetDateFormatA(Locale, dwFlags, lpDate, lpFormatA, lpDateStrA, cchDateA );
  1088. if ( iRetValue != 0 ) {
  1089. lpDateStrW = ConvertAtoW( lpDateStrA );
  1090. cchDateW = My_wcslen( lpDateStrW ) + 1;
  1091. iRetValue = cchDateW;
  1092. if ( (cchDate !=0) && ( lpDateStr != NULL ) ) {
  1093. CopyMemory(lpDateStr, lpDateStrW, cchDateW * sizeof(WCHAR) );
  1094. }
  1095. LocalFreeAndNull( &lpDateStrW );
  1096. }
  1097. LocalFreeAndNull( &lpFormatA );
  1098. LocalFreeAndNull( &lpDateStrA );
  1099. return iRetValue;
  1100. }
  1101. // lstrcpyn
  1102. LPTSTR WINAPI lstrcpynWrapW( LPTSTR lpString1, // pointer to target buffer
  1103. LPCTSTR lpString2, // pointer to source string
  1104. int iMaxLength ) // number of bytes or characters to copy
  1105. {
  1106. int iLength = 0;
  1107. VALIDATE_PROTOTYPE(lstrcpyn);
  1108. if (g_bRunningOnNT)
  1109. return lstrcpynW(lpString1, lpString2, iMaxLength);
  1110. iLength = My_wcslen(lpString2);
  1111. if ( iLength >= iMaxLength )
  1112. iLength = iMaxLength-1;
  1113. CopyMemory(lpString1, lpString2, iLength * sizeof(WCHAR) );
  1114. lpString1[iLength] = 0x0000;
  1115. return lpString1;
  1116. }
  1117. // CreateFile
  1118. HANDLE WINAPI CreateFileWrapW( LPCTSTR lpFileName, // pointer to name of the file
  1119. DWORD dwDesiredAccess, // access (read-write) mode
  1120. DWORD dwShareMode, // share mode
  1121. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  1122. // pointer to security attributes
  1123. DWORD dwCreationDisposition, // how to create
  1124. DWORD dwFlagsAndAttributes, // file attributes
  1125. HANDLE hTemplateFile ) // handle to file with attributes to copy
  1126. {
  1127. LPSTR lpFileA = NULL;
  1128. HANDLE hFile = NULL;
  1129. VALIDATE_PROTOTYPE(CreateFile);
  1130. if (g_bRunningOnNT)
  1131. return CreateFileW( lpFileName,
  1132. dwDesiredAccess,
  1133. dwShareMode,
  1134. lpSecurityAttributes,
  1135. dwCreationDisposition,
  1136. dwFlagsAndAttributes,
  1137. hTemplateFile);
  1138. lpFileA = ConvertWtoA(lpFileName);
  1139. hFile = CreateFileA(lpFileA,
  1140. dwDesiredAccess,
  1141. dwShareMode,
  1142. lpSecurityAttributes,
  1143. dwCreationDisposition,
  1144. dwFlagsAndAttributes,
  1145. hTemplateFile);
  1146. LocalFreeAndNull(&lpFileA);
  1147. return (hFile);
  1148. }
  1149. // OutputDebugString
  1150. VOID WINAPI OutputDebugStringWrapW(LPCTSTR lpOutputString ) // pointer to string to be displayed
  1151. {
  1152. LPSTR lpOutputStringA = NULL;
  1153. VALIDATE_PROTOTYPE(OutputDebugString);
  1154. if (g_bRunningOnNT) {
  1155. OutputDebugStringW(lpOutputString);
  1156. return;
  1157. }
  1158. lpOutputStringA = ConvertWtoA( lpOutputString );
  1159. OutputDebugStringA( lpOutputStringA );
  1160. LocalFreeAndNull( &lpOutputStringA );
  1161. }
  1162. // lstrcat
  1163. LPTSTR WINAPI lstrcatWrapW( LPTSTR lpString1, // pointer to buffer for concatenated strings
  1164. LPCTSTR lpString2 ) // pointer to string to add to string1
  1165. {
  1166. LPWSTR lpwStr = NULL;
  1167. VALIDATE_PROTOTYPE(lstrcat);
  1168. if (g_bRunningOnNT)
  1169. return lstrcatW(lpString1, lpString2);
  1170. lpwStr = lpString1 + My_wcslen(lpString1);
  1171. CopyMemory(lpwStr, lpString2, (My_wcslen(lpString2)+1) * sizeof(WCHAR) );
  1172. return lpString1;
  1173. }
  1174. // FormatMessage with va_list
  1175. //
  1176. // Since it's hard to muck with the Argument List, instead, we'll go throught
  1177. // the source string and explicitly turn any %x to %x!ws! indicating that the
  1178. // arguments have Wide Strings in them.
  1179. //
  1180. // For sanity we assume we won't ever get more than 9 arguments <BUGBUG>
  1181. //
  1182. static const LPWSTR lpWideFormat = TEXT("!ws!");
  1183. DWORD WINAPI FormatMessageWrapW( DWORD dwFlags, // source and processing options
  1184. LPCVOID lpSource, // pointer to message source
  1185. DWORD dwMessageId, // requested message identifier
  1186. DWORD dwLanguageId, // language identifier for requested message
  1187. LPTSTR lpBuffer, // pointer to message buffer
  1188. DWORD nSize, // maximum size of message buffer
  1189. va_list *Arguments ) // pointer to array of message inserts
  1190. {
  1191. DWORD dwResult=0, iNumArg, iNum;
  1192. LPSTR lpSourceA = NULL;
  1193. LPSTR pszBuffer = NULL;
  1194. LPWSTR lpTemp1=NULL, lpTemp2=NULL;
  1195. VALIDATE_PROTOTYPE(FormatMessage);
  1196. if (g_bRunningOnNT)
  1197. return FormatMessageW(dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);
  1198. // FORMAT_MESSAGE_FROM_STRING means that the source is a string.
  1199. // Otherwise, it's an opaque LPVOID (aka, an atom).
  1200. //
  1201. if ( !(dwFlags & FORMAT_MESSAGE_FROM_STRING) || !(dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ) {
  1202. return 0;
  1203. // we don't handle these cases
  1204. }
  1205. if ( !(dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) )
  1206. {
  1207. LPWSTR lpModifiedSource;
  1208. DebugTrace(TEXT("WARNING: FormatMessageWrap() is being called in Win9X with wide char argument strings. DBCS characters may not be converted correctly!"));
  1209. if(!(lpModifiedSource = LocalAlloc(LMEM_ZEROINIT, sizeof(TCHAR)*(lstrlen(lpSource)+1)*4))) // Four times is big enough
  1210. goto exit;
  1211. lpTemp1 = (LPWSTR)lpSource;
  1212. My_wcscpy(lpModifiedSource, lpSource);
  1213. lpTemp2 = lpModifiedSource;
  1214. while(lpTemp1 && *lpTemp1)
  1215. {
  1216. if( *lpTemp1 == '%' &&
  1217. (*(lpTemp1+1) >= '1' && *(lpTemp1+1) <= '9') &&
  1218. *(lpTemp1+2) != '!') //if there isn't a hard-coded printf format specified here
  1219. {
  1220. lpTemp2 += 2; //skip 2 to get past the %9
  1221. lpTemp1 += 2;
  1222. My_wcscpy(lpTemp2, lpWideFormat);
  1223. My_wcscat(lpTemp2, lpTemp1);
  1224. lpTemp2 += My_wcslen(lpWideFormat);
  1225. }
  1226. else
  1227. {
  1228. lpTemp1++;
  1229. lpTemp2++;
  1230. }
  1231. }
  1232. lpSourceA = ConvertWtoA( lpModifiedSource );
  1233. FormatMessageA(
  1234. dwFlags,
  1235. lpSourceA,
  1236. dwMessageId,
  1237. dwLanguageId,
  1238. (LPSTR)&pszBuffer,
  1239. 0,
  1240. Arguments);
  1241. LocalFreeAndNull(&lpModifiedSource);
  1242. }
  1243. else
  1244. {
  1245. // We have an argument array. Convert wide strings to DBCS
  1246. // Create a new argument array and fill with converted (wide to DBCS)
  1247. // strings to ensure International DBCS conversion occurs correctly.
  1248. int n, nArgCount = 0, nBytes = 0;
  1249. LPVOID * pvArgArray = NULL;
  1250. lpTemp1 = (LPWSTR)lpSource;
  1251. while (*lpTemp1)
  1252. {
  1253. if (*lpTemp1 == '%')
  1254. {
  1255. if ( *(lpTemp1+1) == '%')
  1256. ++lpTemp1; // "%%" not valid argument, step passed
  1257. else
  1258. ++nArgCount; // valid argument
  1259. }
  1260. ++lpTemp1;
  1261. }
  1262. pvArgArray = LocalAlloc(LMEM_ZEROINIT, (nArgCount * sizeof(LPVOID)));
  1263. if (!pvArgArray)
  1264. goto exit;
  1265. lpTemp1 = (LPWSTR)lpSource;
  1266. n = 0;
  1267. while (*lpTemp1)
  1268. {
  1269. if (*lpTemp1 == '%')
  1270. {
  1271. if (*(lpTemp1+1) == '%') // Skip "%%"
  1272. ++lpTemp1;
  1273. else
  1274. {
  1275. if ( *(lpTemp1+1) >= '1' && *(lpTemp1+1) <= '9' &&
  1276. *(lpTemp1+2) != '!' ) // Default Unicode string arg
  1277. {
  1278. pvArgArray[n] = (LPVOID)ConvertWtoA( (LPWSTR) ((LPVOID *)Arguments)[n] );
  1279. nBytes += lstrlenA(pvArgArray[n]);
  1280. }
  1281. else
  1282. pvArgArray[n] = ((LPVOID *)Arguments)[n]; // unknown arg type
  1283. ++n;
  1284. Assert(n <= nArgCount);
  1285. }
  1286. }
  1287. ++lpTemp1;
  1288. }
  1289. // Check if known argument string lengths exceed 1023 bytes. If it does
  1290. // abort because Win9X will overrun a buffer and crash.
  1291. if (nBytes <= 1000)
  1292. {
  1293. lpSourceA = ConvertWtoA((LPWSTR)lpSource);
  1294. FormatMessageA(
  1295. dwFlags,
  1296. lpSourceA,
  1297. dwMessageId,
  1298. dwLanguageId,
  1299. (LPSTR)&pszBuffer,
  1300. 0,
  1301. (va_list *)pvArgArray);
  1302. }
  1303. // Clean up
  1304. lpTemp1 = (LPWSTR)lpSource;
  1305. n = 0;
  1306. while (*lpTemp1)
  1307. {
  1308. if (*lpTemp1 == '%')
  1309. {
  1310. if (*(lpTemp1+1) == '%') // Skip "%%"
  1311. ++lpTemp1;
  1312. else
  1313. {
  1314. if ( *(lpTemp1+1) >= '1' && *(lpTemp1+1) <= '9' &&
  1315. *(lpTemp1+2) != '!' )
  1316. {
  1317. LocalFree(pvArgArray[n]);
  1318. ++n;
  1319. Assert(n <= nArgCount);
  1320. }
  1321. }
  1322. }
  1323. ++lpTemp1;
  1324. }
  1325. LocalFree(pvArgArray);
  1326. }
  1327. if (pszBuffer)
  1328. {
  1329. LPWSTR *lpwBuffer;
  1330. lpwBuffer =(LPWSTR *)(lpBuffer);
  1331. *lpwBuffer = ConvertAtoW(pszBuffer);
  1332. dwResult = My_wcslen(*lpwBuffer);
  1333. LocalFree( pszBuffer );
  1334. }
  1335. exit:
  1336. LocalFreeAndNull(&lpSourceA);
  1337. return dwResult;
  1338. }
  1339. // GetModuleFileName
  1340. DWORD WINAPI GetModuleFileNameWrapW( HMODULE hModule, // handle to module to find filename for
  1341. LPTSTR lpFileName, // pointer to buffer to receive module path
  1342. DWORD nSize ) // size of buffer, in characters
  1343. {
  1344. DWORD dRetValue =0;
  1345. CHAR FileNameA[MAX_PATH];
  1346. LPWSTR lpFileNameW = NULL;
  1347. VALIDATE_PROTOTYPE(GetModuleFileName);
  1348. if (g_bRunningOnNT)
  1349. return GetModuleFileNameW(hModule, lpFileName, nSize);
  1350. dRetValue = GetModuleFileNameA(hModule, FileNameA, MAX_PATH);
  1351. if ( dRetValue == 0 ) return 0;
  1352. lpFileNameW = ConvertAtoW( FileNameA );
  1353. dRetValue = My_wcslen( lpFileNameW );
  1354. if ( dRetValue > nSize )
  1355. dRetValue = nSize;
  1356. CopyMemory(lpFileName, lpFileNameW, (dRetValue+1) * sizeof(WCHAR) );
  1357. LocalFreeAndNull( &lpFileNameW );
  1358. return dRetValue;
  1359. }
  1360. // GetPrivateProfileInt
  1361. UINT WINAPI GetPrivateProfileIntWrapW( LPCTSTR lpAppName, // address of section name
  1362. LPCTSTR lpKeyName, // address of key name
  1363. INT nDefault, // return value if key name is not found
  1364. LPCTSTR lpFileName ) // address of initialization filename
  1365. {
  1366. UINT uRetValue = 0;
  1367. LPSTR lpAppNameA = NULL;
  1368. LPSTR lpKeyNameA = NULL;
  1369. LPSTR lpFileNameA = NULL;
  1370. VALIDATE_PROTOTYPE(GetPrivateProfileInt);
  1371. if (g_bRunningOnNT)
  1372. return GetPrivateProfileIntW(lpAppName, lpKeyName, nDefault, lpFileName);
  1373. lpAppNameA = ConvertWtoA( lpAppName );
  1374. lpKeyNameA = ConvertWtoA( lpKeyName );
  1375. lpFileNameA= ConvertWtoA( lpFileName);
  1376. uRetValue = GetPrivateProfileIntA( lpAppNameA, lpKeyNameA, nDefault, lpFileNameA);
  1377. LocalFreeAndNull( &lpAppNameA );
  1378. LocalFreeAndNull( &lpKeyNameA );
  1379. LocalFreeAndNull( &lpFileNameA);
  1380. return uRetValue;
  1381. }
  1382. // IsBadStringPtr
  1383. BOOL WINAPI IsBadStringPtrWrapW( LPCTSTR lpsz, // address of string
  1384. UINT_PTR ucchMax ) // maximum size of string
  1385. {
  1386. VALIDATE_PROTOTYPE(IsBadStringPtr);
  1387. if (g_bRunningOnNT)
  1388. return IsBadStringPtrW(lpsz, ucchMax);
  1389. return IsBadStringPtrA( (LPSTR)lpsz, ucchMax * sizeof(WCHAR) );
  1390. }
  1391. // GetPrivateProfileString
  1392. DWORD WINAPI GetPrivateProfileStringWrapW( LPCTSTR lpAppName, // points to section name
  1393. LPCTSTR lpKeyName, // points to key name
  1394. LPCTSTR lpDefault, // points to default string
  1395. LPTSTR lpReturnedString, // points to destination buffer
  1396. DWORD nSize, // size of destination buffer
  1397. LPCTSTR lpFileName ) // points to initialization filename
  1398. {
  1399. DWORD dRetValue = 0;
  1400. LPSTR lpAppNameA = NULL;
  1401. LPSTR lpKeyNameA = NULL;
  1402. LPSTR lpDefaultA = NULL;
  1403. LPSTR lpReturnedStringA = NULL;
  1404. LPWSTR lpReturnedStringW = NULL;
  1405. LPSTR lpFileNameA = NULL;
  1406. DWORD nSizeA = 0;
  1407. VALIDATE_PROTOTYPE(GetPrivateProfileString);
  1408. if (g_bRunningOnNT)
  1409. return GetPrivateProfileStringW(lpAppName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName);
  1410. lpAppNameA = ConvertWtoA( lpAppName );
  1411. lpKeyNameA = ConvertWtoA( lpKeyName );
  1412. lpDefaultA = ConvertWtoA( lpDefault );
  1413. lpFileNameA= ConvertWtoA( lpFileName );
  1414. nSizeA = nSize * sizeof(WCHAR)+1;
  1415. lpReturnedStringA = LocalAlloc( LMEM_ZEROINIT, nSizeA );
  1416. nSizeA = GetPrivateProfileStringA(lpAppNameA,lpKeyNameA,lpDefaultA,lpReturnedStringA,nSizeA,lpFileNameA);
  1417. lpReturnedStringW = ConvertAtoW( lpReturnedStringA );
  1418. dRetValue = My_wcslen( lpReturnedStringW );
  1419. My_wcscpy(lpReturnedString, lpReturnedStringW);
  1420. LocalFreeAndNull( &lpAppNameA );
  1421. LocalFreeAndNull( &lpKeyNameA );
  1422. LocalFreeAndNull( &lpDefaultA );
  1423. LocalFreeAndNull( &lpReturnedStringA );
  1424. LocalFreeAndNull( &lpReturnedStringW );
  1425. LocalFreeAndNull( &lpFileNameA );
  1426. return dRetValue;
  1427. }
  1428. // lstrcmp
  1429. int WINAPI lstrcmpWrapW( LPCTSTR lpString1, // pointer to first string
  1430. LPCTSTR lpString2 ) // pointer to second string
  1431. {
  1432. int iRetValue = 0;
  1433. LPSTR lpString1A = NULL ;
  1434. LPSTR lpString2A = NULL ;
  1435. VALIDATE_PROTOTYPE(lstrcmp);
  1436. if (g_bRunningOnNT)
  1437. return lstrcmpW(lpString1, lpString2);
  1438. lpString1A = ConvertWtoA( lpString1 );
  1439. lpString2A = ConvertWtoA( lpString2 );
  1440. iRetValue = lstrcmpA(lpString1A, lpString2A );
  1441. LocalFreeAndNull( &lpString1A );
  1442. LocalFreeAndNull( &lpString2A );
  1443. return iRetValue;
  1444. }
  1445. HANDLE WINAPI CreateMutexWrapW( LPSECURITY_ATTRIBUTES lpMutexAttributes,
  1446. // pointer to security attributes
  1447. BOOL bInitialOwner, // flag for initial ownership
  1448. LPCTSTR lpName ) // pointer to mutex-object name
  1449. {
  1450. LPSTR lpNameA = NULL;
  1451. HANDLE hMutex = NULL;
  1452. VALIDATE_PROTOTYPE(CreateMutex);
  1453. if (g_bRunningOnNT)
  1454. return CreateMutexW(lpMutexAttributes, bInitialOwner, lpName);
  1455. lpNameA = ConvertWtoA(lpName);
  1456. hMutex = CreateMutexA(lpMutexAttributes, bInitialOwner, lpNameA);
  1457. LocalFreeAndNull(&lpNameA);
  1458. return hMutex;
  1459. }
  1460. // GetTempPath
  1461. DWORD WINAPI GetTempPathWrapW( DWORD nBufferLength, // size, in characters, of the buffer
  1462. LPTSTR lpBuffer ) // pointer to buffer for temp. path
  1463. {
  1464. DWORD nRequired = 0;
  1465. CHAR lpBufferA[MAX_PATH];
  1466. LPWSTR lpBufferW = NULL;
  1467. VALIDATE_PROTOTYPE(GetTempPath);
  1468. if (g_bRunningOnNT)
  1469. return GetTempPathW(nBufferLength, lpBuffer);
  1470. nRequired = GetTempPathA(MAX_PATH, lpBufferA);
  1471. lpBufferW = ConvertAtoW(lpBufferA);
  1472. nRequired = My_wcslen(lpBufferW);
  1473. if ( nRequired < nBufferLength)
  1474. CopyMemory(lpBuffer, lpBufferW, (nRequired+1)*sizeof(WCHAR) );
  1475. return nRequired;
  1476. }
  1477. // ExpandEnvironmentStrings
  1478. DWORD WINAPI ExpandEnvironmentStringsWrapW( LPCTSTR lpSrc, // pointer to string with environment variables
  1479. LPTSTR lpDst, // pointer to string with expanded environment
  1480. // variables
  1481. DWORD nSize ) // maximum characters in expanded string
  1482. {
  1483. DWORD dRetValue = 0;
  1484. LPSTR lpSrcA = NULL;
  1485. LPSTR lpDstA = NULL;
  1486. LPWSTR lpDstW = NULL;
  1487. DWORD nSizeA = 0;
  1488. VALIDATE_PROTOTYPE(ExpandEnvironmentStrings);
  1489. if (g_bRunningOnNT)
  1490. return ExpandEnvironmentStringsW(lpSrc, lpDst, nSize);
  1491. nSizeA = nSize * sizeof(WCHAR);
  1492. lpDstA = LocalAlloc( LMEM_ZEROINIT, nSizeA );
  1493. lpSrcA = ConvertWtoA( lpSrc );
  1494. dRetValue = ExpandEnvironmentStringsA( lpSrcA, lpDstA, nSizeA );
  1495. lpDstW = ConvertAtoW( lpDstA );
  1496. dRetValue = My_wcslen( lpDstW );
  1497. if ( dRetValue < nSize )
  1498. My_wcscpy(lpDst, lpDstW);
  1499. LocalFreeAndNull( &lpSrcA );
  1500. LocalFreeAndNull( &lpDstA );
  1501. LocalFreeAndNull( &lpDstW );
  1502. return dRetValue;
  1503. }
  1504. // GetTempFileName
  1505. UINT WINAPI GetTempFileNameWrapW( LPCTSTR lpPathName, // pointer to directory name for temporary file
  1506. LPCTSTR lpPrefixString, // pointer to filename prefix
  1507. UINT uUnique, // number used to create temporary filename
  1508. LPTSTR lpTempFileName ) // pointer to buffer that receives the new filename
  1509. {
  1510. UINT uRetValue = 0;
  1511. LPSTR lpPathNameA = NULL;
  1512. LPSTR lpPrefixStringA = NULL;
  1513. CHAR lpTempFileNameA[MAX_PATH];
  1514. LPWSTR lpTempFileNameW = NULL;
  1515. VALIDATE_PROTOTYPE(GetTempFileName);
  1516. if (g_bRunningOnNT)
  1517. return GetTempFileNameW(lpPathName, lpPrefixString, uUnique, lpTempFileName);
  1518. lpPathNameA = ConvertWtoA( lpPathName );
  1519. lpPrefixStringA = ConvertWtoA( lpPrefixString );
  1520. uRetValue = GetTempFileNameA(lpPathNameA, lpPrefixStringA, uUnique, lpTempFileNameA);
  1521. if ( uRetValue != 0 ) {
  1522. lpTempFileNameW = ConvertAtoW( lpTempFileNameA );
  1523. My_wcscpy( lpTempFileName, lpTempFileNameW );
  1524. LocalFreeAndNull( &lpTempFileNameW );
  1525. }
  1526. LocalFreeAndNull( &lpPathNameA );
  1527. LocalFreeAndNull( &lpPrefixStringA );
  1528. return uRetValue;
  1529. }
  1530. // BOOL WINAPI ReleaseMutexWrapW( HANDLE hMutex ) // handle to mutex object
  1531. // DeleteFile
  1532. BOOL WINAPI DeleteFileWrapW( LPCTSTR lpFileName ) // pointer to name of file to delete
  1533. {
  1534. BOOL bRetValue ;
  1535. LPSTR lpFileNameA = NULL;
  1536. VALIDATE_PROTOTYPE(DeleteFile);
  1537. if (g_bRunningOnNT)
  1538. return DeleteFileW(lpFileName);
  1539. lpFileNameA = ConvertWtoA( lpFileName );
  1540. bRetValue = DeleteFileA( lpFileNameA );
  1541. LocalFreeAndNull( &lpFileNameA );
  1542. return bRetValue;
  1543. }
  1544. // CopyFile
  1545. BOOL WINAPI CopyFileWrapW( LPCTSTR lpExistingFileName, // pointer to name of an existing file
  1546. LPCTSTR lpNewFileName, // pointer to filename to copy to
  1547. BOOL bFailIfExists ) // flag for operation if file exists
  1548. {
  1549. BOOL bRetValue;
  1550. LPSTR lpExistingFileNameA = NULL;
  1551. LPSTR lpNewFileNameA = NULL;
  1552. VALIDATE_PROTOTYPE(CopyFile);
  1553. if (g_bRunningOnNT)
  1554. return CopyFileW(lpExistingFileName, lpNewFileName, bFailIfExists);
  1555. lpExistingFileNameA = ConvertWtoA( lpExistingFileName );
  1556. lpNewFileNameA = ConvertWtoA( lpNewFileName );
  1557. bRetValue = CopyFileA( lpExistingFileNameA, lpNewFileNameA, bFailIfExists);
  1558. LocalFreeAndNull( & lpExistingFileNameA );
  1559. LocalFreeAndNull( & lpNewFileNameA );
  1560. return bRetValue;
  1561. }
  1562. // FindFirstChangeNotification
  1563. HANDLE WINAPI FindFirstChangeNotificationWrapW(LPCTSTR lpcwszFilePath, // Directory path of file to watch
  1564. BOOL bWatchSubtree, // Monitor entire tree
  1565. DWORD dwNotifyFilter) // Conditions to watch for
  1566. {
  1567. HANDLE hRet;
  1568. LPSTR lpszFilePath;
  1569. VALIDATE_PROTOTYPE(FindFirstChangeNotification);
  1570. Assert(lpcwszFilePath);
  1571. if (g_bRunningOnNT)
  1572. return FindFirstChangeNotification(lpcwszFilePath, bWatchSubtree, dwNotifyFilter);
  1573. lpszFilePath = ConvertWtoA(lpcwszFilePath);
  1574. hRet = FindFirstChangeNotificationA(lpszFilePath, bWatchSubtree, dwNotifyFilter);
  1575. LocalFreeAndNull(&lpszFilePath);
  1576. return hRet;
  1577. }
  1578. // FindFirstFile
  1579. HANDLE WINAPI FindFirstFileWrapW( LPCTSTR lpFileName, // pointer to name of file to search for
  1580. LPWIN32_FIND_DATA lpFindFileData ) // pointer to returned information
  1581. {
  1582. HANDLE hRetValue;
  1583. LPSTR lpFileNameA = NULL;
  1584. WIN32_FIND_DATAA FindFileDataA;
  1585. WIN32_FIND_DATAW FindFileDataW;
  1586. VALIDATE_PROTOTYPE(FindFirstFile);
  1587. if (g_bRunningOnNT)
  1588. return FindFirstFileW(lpFileName, lpFindFileData);
  1589. lpFileNameA = ConvertWtoA(lpFileName);
  1590. hRetValue = FindFirstFileA( lpFileNameA, &FindFileDataA );
  1591. if ( hRetValue != INVALID_HANDLE_VALUE ) {
  1592. CopyMemory( &FindFileDataW, &FindFileDataA, sizeof(WIN32_FIND_DATAA)-MAX_PATH-14 );
  1593. MultiByteToWideChar(GetACP(),0,FindFileDataA.cFileName,MAX_PATH,FindFileDataW.cFileName,MAX_PATH);
  1594. MultiByteToWideChar(GetACP(),0,FindFileDataA.cAlternateFileName,14,FindFileDataW.cAlternateFileName,14);
  1595. CopyMemory( lpFindFileData, &FindFileDataW, sizeof(WIN32_FIND_DATAW) );
  1596. }
  1597. LocalFreeAndNull( &lpFileNameA );
  1598. return hRetValue;
  1599. }
  1600. // GetDiskFreeSpace
  1601. BOOL WINAPI GetDiskFreeSpaceWrapW( LPCTSTR lpRootPathName, // pointer to root path
  1602. LPDWORD lpSectorsPerCluster, // pointer to sectors per cluster
  1603. LPDWORD lpBytesPerSector, // pointer to bytes per sector
  1604. LPDWORD lpNumberOfFreeClusters,
  1605. // pointer to number of free clusters
  1606. LPDWORD lpTotalNumberOfClusters )
  1607. // pointer to total number of clusters
  1608. {
  1609. BOOL bRetValue;
  1610. LPSTR lpRootPathNameA = NULL;
  1611. VALIDATE_PROTOTYPE(GetDiskFreeSpace);
  1612. if (g_bRunningOnNT)
  1613. return GetDiskFreeSpaceW(lpRootPathName,
  1614. lpSectorsPerCluster,
  1615. lpBytesPerSector,
  1616. lpNumberOfFreeClusters,
  1617. lpTotalNumberOfClusters);
  1618. lpRootPathNameA = ConvertWtoA( lpRootPathName );
  1619. bRetValue = GetDiskFreeSpaceA(lpRootPathNameA,
  1620. lpSectorsPerCluster,
  1621. lpBytesPerSector,
  1622. lpNumberOfFreeClusters,
  1623. lpTotalNumberOfClusters);
  1624. LocalFreeAndNull( & lpRootPathNameA );
  1625. return bRetValue;
  1626. }
  1627. // MoveFile
  1628. BOOL WINAPI MoveFileWrapW( LPCTSTR lpExistingFileName, // pointer to the name of the existing file
  1629. LPCTSTR lpNewFileName ) // pointer to the new name for the file
  1630. {
  1631. BOOL bRetValue;
  1632. LPSTR lpExistingFileNameA = NULL;
  1633. LPSTR lpNewFileNameA = NULL;
  1634. VALIDATE_PROTOTYPE(MoveFile);
  1635. if (g_bRunningOnNT)
  1636. return MoveFileW(lpExistingFileName, lpNewFileName);
  1637. lpExistingFileNameA = ConvertWtoA( lpExistingFileName );
  1638. lpNewFileNameA = ConvertWtoA( lpNewFileName );
  1639. bRetValue = MoveFileA( lpExistingFileNameA, lpNewFileNameA );
  1640. LocalFreeAndNull( &lpExistingFileNameA );
  1641. LocalFreeAndNull( &lpNewFileNameA );
  1642. return bRetValue;
  1643. }
  1644. // CreateEvent
  1645. HANDLE WINAPI CreateEventWrapW(LPSECURITY_ATTRIBUTES lpEventAttributes, // pointer to security attributes
  1646. BOOL bManualReset, // flag for manual-reset event
  1647. BOOL bInitialState, // flag for initial state
  1648. LPCTSTR lpcwszName) // pointer to event-object name
  1649. {
  1650. HANDLE hRet;
  1651. LPSTR lpszName;
  1652. VALIDATE_PROTOTYPE(CreateEvent);
  1653. if (g_bRunningOnNT)
  1654. return CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpcwszName);
  1655. lpszName = ConvertWtoA(lpcwszName); // Handles NULL lpcwszName case
  1656. hRet = CreateEventA(lpEventAttributes, bManualReset, bInitialState, lpszName);
  1657. LocalFreeAndNull(&lpszName);
  1658. return hRet;
  1659. }
  1660. //SHELL32.DLL
  1661. HINSTANCE WINAPI ShellExecuteWrapW( HWND hwnd,
  1662. LPCTSTR lpOperation,
  1663. LPCTSTR lpFile,
  1664. LPCTSTR lpParameters,
  1665. LPCTSTR lpDirectory,
  1666. INT nShowCmd )
  1667. {
  1668. HINSTANCE hRetValue;
  1669. LPSTR lpOperationA = NULL;
  1670. LPSTR lpFileA = NULL;
  1671. LPSTR lpParametersA = NULL;
  1672. LPSTR lpDirectoryA = NULL;
  1673. VALIDATE_PROTOTYPE(ShellExecute);
  1674. if (g_bRunningOnNT)
  1675. return ShellExecuteW(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd);
  1676. lpOperationA = ConvertWtoA( lpOperation );
  1677. lpFileA = ConvertWtoA( lpFile );
  1678. lpParametersA= ConvertWtoA( lpParameters );
  1679. lpDirectoryA = ConvertWtoA( lpDirectory );
  1680. hRetValue = ShellExecuteA(hwnd, lpOperationA, lpFileA, lpParametersA, lpDirectoryA, nShowCmd);
  1681. LocalFreeAndNull( &lpOperationA);
  1682. LocalFreeAndNull( &lpFileA );
  1683. LocalFreeAndNull( &lpParametersA );
  1684. LocalFreeAndNull( &lpDirectoryA );
  1685. return hRetValue;
  1686. }
  1687. // DragQueryFile
  1688. UINT WINAPI DragQueryFileWrapW( HDROP hDrop,
  1689. UINT iFile,
  1690. LPTSTR lpszFile,
  1691. UINT cch )
  1692. {
  1693. UINT uRetValue = 0;
  1694. LPSTR lpszFileA = NULL;
  1695. LPWSTR lpszFileW = NULL;
  1696. UINT cchA, cchW =0;
  1697. VALIDATE_PROTOTYPE(DragQueryFile);
  1698. if (g_bRunningOnNT)
  1699. return DragQueryFileW(hDrop, iFile, lpszFile, cch);
  1700. cchA = DragQueryFileA( hDrop, iFile, NULL, 0 );
  1701. lpszFileA = LocalAlloc(LMEM_ZEROINIT, cchA+1 );
  1702. uRetValue = DragQueryFileA(hDrop, iFile, lpszFileA, cchA+1);
  1703. lpszFileW = ConvertAtoW( lpszFileA );
  1704. cchW = My_wcslen( lpszFileW );
  1705. if ( lpszFile )
  1706. CopyMemory( lpszFile, lpszFileW, (cchW+1)*sizeof(WCHAR) );
  1707. LocalFreeAndNull( &lpszFileA );
  1708. LocalFreeAndNull( &lpszFileW );
  1709. return cchW;
  1710. }
  1711. //USER32.DLL
  1712. // CharPrev
  1713. LPTSTR WINAPI CharPrevWrapW( LPCTSTR lpszStart, // pointer to first character
  1714. LPCTSTR lpszCurrent ) // pointer to current character
  1715. {
  1716. LPWSTR lpszReturn = NULL;
  1717. VALIDATE_PROTOTYPE(CharPrev);
  1718. if (g_bRunningOnNT)
  1719. return CharPrevW(lpszStart, lpszCurrent);
  1720. if (lpszCurrent == lpszStart)
  1721. lpszReturn = (LPWSTR)lpszStart;
  1722. lpszReturn = (LPWSTR)lpszCurrent - 1;
  1723. return lpszReturn;
  1724. }
  1725. // DrawText
  1726. int WINAPI DrawTextWrapW( HDC hDC, // handle to device context
  1727. LPCTSTR lpString, // pointer to string to draw
  1728. int nCount, // string length, in characters
  1729. LPRECT lpRect, // pointer to struct with formatting dimensions
  1730. UINT uFormat ) // text-drawing flags
  1731. {
  1732. int iRetValue = 0;
  1733. LPSTR lpStringA = NULL;
  1734. VALIDATE_PROTOTYPE(DrawText);
  1735. if (g_bRunningOnNT)
  1736. return DrawTextW(hDC, lpString, nCount, lpRect, uFormat);
  1737. lpStringA = ConvertWtoA( lpString );
  1738. iRetValue = DrawTextA(hDC, lpStringA, nCount, lpRect, uFormat);
  1739. LocalFreeAndNull( &lpStringA );
  1740. return iRetValue;
  1741. }
  1742. // ModifyMenu
  1743. BOOL WINAPI ModifyMenuWrapW( HMENU hMenu, // handle to menu
  1744. UINT uPosition, // menu item to modify
  1745. UINT uFlags, // menu item flags
  1746. UINT_PTR uIDNewItem, // menu item identifier or handle to drop-down
  1747. // menu or submenu
  1748. LPCTSTR lpNewItem ) // menu item content
  1749. {
  1750. BOOL bRetValue;
  1751. LPSTR lpNewItemA = NULL;
  1752. VALIDATE_PROTOTYPE(ModifyMenu);
  1753. if (g_bRunningOnNT)
  1754. return ModifyMenuW(hMenu, uPosition, uFlags, uIDNewItem, lpNewItem);
  1755. Assert(lpNewItem);
  1756. // [PaulHi] 4/5/99 Raid 75428 MF_STRING is defined to be 0x00000000. Need
  1757. // to check alternative interpretations of lpNewItem.
  1758. // MF_BITMAP = 0x00000004L
  1759. // MF_OWNERDRAW = 0x00000100L
  1760. // If this Assert fires then it implies that a new bit defining lpNewItem may have
  1761. // been added to this API!!! If so add this definition to the uFlags if statement.
  1762. Assert( !(uFlags & ~(MF_BITMAP|MF_BYCOMMAND|MF_BYPOSITION|MF_CHECKED|MF_DISABLED|MF_GRAYED|MF_MENUBARBREAK|MF_MENUBREAK|MF_OWNERDRAW|MF_POPUP|MF_SEPARATOR|MF_UNCHECKED)));
  1763. if (uFlags & (MF_BITMAP | MF_OWNERDRAW)) // lpNewItem is NOT a string pointer
  1764. return ModifyMenuA(hMenu, uPosition, uFlags, uIDNewItem, (LPCSTR)lpNewItem);
  1765. lpNewItemA = ConvertWtoA( lpNewItem );
  1766. bRetValue = ModifyMenuA(hMenu, uPosition, uFlags, uIDNewItem, lpNewItemA);
  1767. LocalFreeAndNull( &lpNewItemA );
  1768. return bRetValue;
  1769. }
  1770. // InsertMenu
  1771. BOOL WINAPI InsertMenuWrapW( HMENU hMenu, // handle to menu
  1772. UINT uPosition, // menu item that new menu item precedes
  1773. UINT uFlags, // menu item flags
  1774. UINT_PTR uIDNewItem, // menu item identifier or handle to drop-down
  1775. // menu or submenu
  1776. LPCTSTR lpNewItem ) // menu item content
  1777. {
  1778. BOOL bRetValue;
  1779. LPSTR lpNewItemA = NULL;
  1780. VALIDATE_PROTOTYPE(InsertMenu);
  1781. if (g_bRunningOnNT)
  1782. return InsertMenuW(hMenu, uPosition, uFlags, uIDNewItem, lpNewItem);
  1783. if (uFlags & MF_BITMAP || uFlags & MF_OWNERDRAW) // if anything but MF_STRING .. note: MF_STRING = 0x00000000
  1784. return InsertMenuA(hMenu, uPosition, uFlags, uIDNewItem, (LPCSTR)lpNewItem);
  1785. lpNewItemA = ConvertWtoA( lpNewItem );
  1786. bRetValue = InsertMenuA(hMenu, uPosition, uFlags, uIDNewItem, lpNewItemA);
  1787. LocalFreeAndNull( &lpNewItemA );
  1788. return bRetValue;
  1789. }
  1790. // LoadImage
  1791. HANDLE WINAPI LoadImageWrapW( HINSTANCE hinst, // handle of the instance containing the image
  1792. LPCTSTR lpszName, // name or identifier of image
  1793. UINT uType, // type of image
  1794. int cxDesired, // desired width
  1795. int cyDesired, // desired height
  1796. UINT fuLoad ) // load flags
  1797. {
  1798. HANDLE hRetValue;
  1799. LPSTR lpszNameA = NULL;
  1800. VALIDATE_PROTOTYPE(LoadImage);
  1801. if (g_bRunningOnNT)
  1802. return LoadImageW(hinst, lpszName, uType, cxDesired, cyDesired, fuLoad);
  1803. lpszNameA = ConvertWtoA( lpszName );
  1804. hRetValue = LoadImageA(hinst, lpszNameA, uType, cxDesired, cyDesired, fuLoad);
  1805. LocalFreeAndNull( & lpszNameA );
  1806. return hRetValue;
  1807. }
  1808. // GetClassInfoEx
  1809. BOOL WINAPI GetClassInfoExWrapW( HINSTANCE hinst, // handle of application instance
  1810. LPCTSTR lpszClass, // address of class name string
  1811. LPWNDCLASSEX lpwcx ) // address of structure for class data
  1812. {
  1813. BOOL bRetValue;
  1814. LPSTR lpszClassA = NULL;
  1815. WNDCLASSEXA wcxA;
  1816. WNDCLASSEXW wcxW;
  1817. VALIDATE_PROTOTYPE(GetClassInfoEx);
  1818. if (g_bRunningOnNT)
  1819. return GetClassInfoExW(hinst, lpszClass, lpwcx);
  1820. lpszClassA = ConvertWtoA( lpszClass );
  1821. wcxA.cbSize = sizeof( WNDCLASSEXA );
  1822. bRetValue = GetClassInfoExA( hinst, lpszClassA, &wcxA );
  1823. if ( bRetValue == FALSE ) {
  1824. LocalFreeAndNull( &lpszClassA );
  1825. return bRetValue;
  1826. }
  1827. CopyMemory( &wcxW, &wcxA, sizeof(WNDCLASSEXA) );
  1828. wcxW.cbSize = sizeof(WNDCLASSEXW);
  1829. if ( wcxA.lpszMenuName && !IS_INTRESOURCE(wcxA.lpszMenuName) )
  1830. wcxW.lpszMenuName = ConvertAtoW( wcxA.lpszMenuName );
  1831. if ( wcxA.lpszClassName && !IS_INTRESOURCE(wcxA.lpszClassName) ) // lpszClassName can be an atom, high word is null
  1832. wcxW.lpszClassName = ConvertAtoW( wcxA.lpszClassName );
  1833. CopyMemory(lpwcx, &wcxW, sizeof(WNDCLASSEXW) );
  1834. LocalFreeAndNull( &lpszClassA );
  1835. return bRetValue;
  1836. }
  1837. // LoadString
  1838. int WINAPI LoadStringWrapW( HINSTANCE hInstance, // handle to module containing string resource
  1839. UINT uID, // resource identifier
  1840. LPTSTR lpBuffer, // pointer to buffer for resource
  1841. int nBufferMax ) // size of buffer
  1842. {
  1843. int iRetValue = 0;
  1844. LPSTR lpBufferA = NULL;
  1845. int nBuffer = 0;
  1846. LPWSTR lpBufferW= NULL;
  1847. VALIDATE_PROTOTYPE(LoadString);
  1848. if (g_bRunningOnNT)
  1849. return LoadStringW(hInstance, uID, lpBuffer, nBufferMax);
  1850. nBuffer = nBufferMax * sizeof(WCHAR);
  1851. lpBufferA = LocalAlloc(LMEM_ZEROINIT, nBuffer );
  1852. iRetValue = LoadStringA(hInstance, uID, lpBufferA, nBuffer);
  1853. lpBufferW = ConvertAtoW( lpBufferA );
  1854. nBuffer = My_wcslen( lpBufferW );
  1855. if ( nBuffer >= nBufferMax )
  1856. nBuffer = nBufferMax - 1;
  1857. CopyMemory(lpBuffer, lpBufferW, nBuffer * sizeof( WCHAR) );
  1858. lpBuffer[nBuffer] = 0x0000;
  1859. LocalFreeAndNull( &lpBufferA );
  1860. LocalFreeAndNull( &lpBufferW );
  1861. return nBuffer;
  1862. }
  1863. // CharNext
  1864. LPTSTR WINAPI CharNextWrapW( LPCTSTR lpsz ) // pointer to current character
  1865. {
  1866. LPWSTR lpwsz = NULL;
  1867. VALIDATE_PROTOTYPE(CharNext);
  1868. if (g_bRunningOnNT)
  1869. return CharNextW(lpsz);
  1870. if ( *lpsz == 0x0000 )
  1871. lpwsz = (LPWSTR)lpsz;
  1872. else
  1873. lpwsz = (LPWSTR)lpsz + 1;
  1874. return lpwsz;
  1875. }
  1876. LRESULT WINAPI ListView_GetItemTextA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  1877. {
  1878. LRESULT lRetValue;
  1879. LVITEMA lviA;
  1880. LPLVITEMW lplviW;
  1881. LPSTR lpszText;
  1882. LPWSTR lpszTextW;
  1883. DWORD iMinLen;
  1884. lplviW = (LPLVITEMW) lParam;
  1885. CopyMemory( &lviA, lplviW, sizeof( LVITEMA ) );
  1886. iMinLen = lplviW->cchTextMax * sizeof( WCHAR );
  1887. lpszText = LocalAlloc( LMEM_ZEROINIT, iMinLen );
  1888. lviA.cchTextMax = iMinLen ;
  1889. lviA.pszText = lpszText;
  1890. lRetValue = SendMessageA(hWnd, LVM_GETITEMTEXTA, wParam, (LPARAM)(LVITEMA FAR *)&lviA );
  1891. lpszTextW = ConvertAtoW( lviA.pszText );
  1892. if ( iMinLen > (lstrlenW( lpszTextW ) + 1) * sizeof( WCHAR) )
  1893. iMinLen = (lstrlenW( lpszTextW ) + 1) * sizeof( WCHAR) ;
  1894. CopyMemory( lplviW->pszText, lpszTextW, iMinLen );
  1895. LocalFreeAndNull( &lpszText );
  1896. LocalFreeAndNull( &lpszTextW );
  1897. return lRetValue;
  1898. }
  1899. LRESULT WINAPI ListView_GetItemA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  1900. {
  1901. LRESULT lRetValue;
  1902. LVITEMA lviA;
  1903. LPLVITEMW lplviW = NULL;
  1904. LPSTR lpszText = NULL;
  1905. LPWSTR lpszTextW = NULL;
  1906. DWORD iMinLen;
  1907. lplviW = (LPLVITEMW) lParam;
  1908. CopyMemory( &lviA, lplviW, sizeof( LVITEMA ) );
  1909. iMinLen = 0;
  1910. if ( lplviW->mask & LVIF_TEXT ) {
  1911. iMinLen = lplviW->cchTextMax * sizeof( WCHAR );
  1912. lpszText = LocalAlloc( LMEM_ZEROINIT, iMinLen );
  1913. lviA.cchTextMax = iMinLen ;
  1914. lviA.pszText = lpszText;
  1915. }
  1916. lRetValue = SendMessageA(hWnd, LVM_GETITEMA, wParam, (LPARAM)(LVITEMA FAR *)&lviA );
  1917. lplviW->mask = lviA.mask;
  1918. lplviW->iItem = lviA.iItem;
  1919. lplviW->iSubItem = lviA.iSubItem;
  1920. lplviW->state = lviA.state;
  1921. lplviW->stateMask = lviA.stateMask;
  1922. lplviW->iImage = lviA.iImage;
  1923. lplviW->lParam = lviA.lParam;
  1924. #if (_WIN32_IE >= 0x0300)
  1925. lplviW->iIndent = lviA.iIndent;
  1926. #endif
  1927. if ( lplviW->mask & LVIF_TEXT ) {
  1928. lpszTextW = ConvertAtoW( lviA.pszText );
  1929. if ( iMinLen > (lstrlenW( lpszTextW ) + 1) * sizeof( WCHAR) )
  1930. iMinLen = (lstrlenW( lpszTextW ) + 1) * sizeof( WCHAR) ;
  1931. CopyMemory( lplviW->pszText, lpszTextW, iMinLen );
  1932. }
  1933. LocalFreeAndNull( &lpszText );
  1934. LocalFreeAndNull( &lpszTextW );
  1935. return lRetValue;
  1936. }
  1937. LRESULT WINAPI ListView_InsertItemA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  1938. {
  1939. LRESULT lRetValue;
  1940. LVITEMA lviA;
  1941. LPLVITEMW lplviW;
  1942. LPSTR lpszText = NULL;
  1943. lplviW = (LPLVITEMW) lParam;
  1944. CopyMemory( &lviA, lplviW, sizeof( LVITEMA ) );
  1945. if ( (lplviW->mask & LVIF_TEXT) && (lplviW->pszText != NULL) ) {
  1946. lpszText = ConvertWtoA( lplviW->pszText );
  1947. lviA.cchTextMax = lstrlenA( lpszText ) + 1 ;
  1948. }
  1949. lviA.pszText = lpszText;
  1950. lRetValue = SendMessageA(hWnd, LVM_INSERTITEMA, wParam, (LPARAM)(LVITEMA FAR *)&lviA );
  1951. LocalFreeAndNull( &lpszText );
  1952. return lRetValue;
  1953. }
  1954. LRESULT WINAPI ListView_SetItemA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  1955. {
  1956. LRESULT lRetValue;
  1957. LVITEMA lviA;
  1958. LPLVITEMW lplviW;
  1959. LPSTR lpszText = NULL;
  1960. lplviW = (LPLVITEMW) lParam;
  1961. CopyMemory( &lviA, lplviW, sizeof( LVITEMA ) );
  1962. if ( (lplviW->mask & LVIF_TEXT ) && (lplviW->pszText != NULL) ) {
  1963. lpszText = ConvertWtoA( lplviW->pszText );
  1964. lviA.cchTextMax = lstrlenA( lpszText ) + 1 ;
  1965. lviA.pszText = lpszText;
  1966. }
  1967. lRetValue = SendMessageA(hWnd, LVM_SETITEMA, wParam, (LPARAM)(LVITEMA FAR *)&lviA );
  1968. LocalFreeAndNull( &lpszText );
  1969. return lRetValue;
  1970. }
  1971. LRESULT WINAPI ListView_SetItemTextA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  1972. {
  1973. LRESULT lRetValue;
  1974. LVITEMA lviA;
  1975. LPLVITEMW lplviW;
  1976. LPSTR lpszText;
  1977. lplviW = (LPLVITEMW) lParam;
  1978. CopyMemory( &lviA, lplviW, sizeof( LVITEMA ) );
  1979. lpszText = ConvertWtoA( lplviW->pszText );
  1980. lviA.cchTextMax = lstrlenA( lpszText ) + 1 ;
  1981. lviA.pszText = lpszText;
  1982. lRetValue = SendMessageA(hWnd, LVM_SETITEMTEXTA, wParam, (LPARAM)(LVITEMA FAR *)&lviA );
  1983. LocalFreeAndNull( &lpszText );
  1984. return lRetValue;
  1985. }
  1986. LRESULT WINAPI ListView_SetColumnA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  1987. {
  1988. LRESULT lRetValue;
  1989. LVCOLUMNA lvcA;
  1990. LPLVCOLUMNW lplvcW;
  1991. LPSTR lpszText = NULL;
  1992. lplvcW = (LPLVCOLUMNW) lParam;
  1993. CopyMemory( &lvcA, lplvcW, sizeof( LVCOLUMNA ) );
  1994. if ( (lplvcW->mask & LVCF_TEXT ) && (lplvcW->pszText != NULL) ) {
  1995. lpszText = ConvertWtoA( lplvcW->pszText );
  1996. lvcA.cchTextMax = lstrlenA( lpszText ) + 1 ;
  1997. }
  1998. lvcA.pszText = lpszText;
  1999. lRetValue = SendMessageA(hWnd, LVM_SETCOLUMNA, wParam, (LPARAM)(LPLVCOLUMNA)&lvcA );
  2000. LocalFreeAndNull( &lpszText );
  2001. return lRetValue;
  2002. }
  2003. LRESULT WINAPI ListView_InsertColumnA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  2004. {
  2005. LRESULT lRetValue;
  2006. LVCOLUMNA lvcA;
  2007. LPLVCOLUMNW lplvcW;
  2008. LPSTR lpszText = NULL;
  2009. lplvcW = (LPLVCOLUMNW) lParam;
  2010. CopyMemory( &lvcA, lplvcW, sizeof( LVCOLUMNA ) );
  2011. if ( (lplvcW->mask & LVCF_TEXT ) && (lplvcW->pszText != NULL) ) {
  2012. lpszText = ConvertWtoA( lplvcW->pszText );
  2013. lvcA.cchTextMax = lstrlenA( lpszText ) + 1 ;
  2014. }
  2015. lvcA.pszText = lpszText;
  2016. lRetValue = SendMessageA(hWnd, LVM_INSERTCOLUMNA, wParam, (LPARAM)(LPLVCOLUMNA)&lvcA );
  2017. LocalFreeAndNull( &lpszText );
  2018. return lRetValue;
  2019. }
  2020. LRESULT WINAPI ListView_FindItemA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  2021. {
  2022. LRESULT lRetValue;
  2023. LPSTR lpsz = NULL;
  2024. LVFINDINFOA lvfiA;
  2025. LPFINDINFOW lplvfiW;
  2026. lplvfiW = (LPFINDINFOW) lParam;
  2027. CopyMemory( &lvfiA, lplvfiW, sizeof(LVFINDINFOA ) );
  2028. if ( (lplvfiW->flags & LVFI_PARTIAL) || (lplvfiW->flags & LVFI_STRING) ) {
  2029. if ( lplvfiW->psz != NULL ) {
  2030. lpsz = ConvertWtoA( lplvfiW->psz );
  2031. }
  2032. }
  2033. lvfiA.psz = lpsz;
  2034. if ( lplvfiW->flags & LVFI_PARAM ) {
  2035. // we must convert field lParam, but this is not the case in our current code
  2036. // so ignore it.
  2037. if ( lplvfiW->lParam )
  2038. lvfiA.lParam = lplvfiW->lParam;
  2039. }
  2040. lRetValue = SendMessageA(hWnd, LVM_FINDITEMA, wParam, (LPARAM)(LVFINDINFOA FAR *)&lvfiA );
  2041. LocalFreeAndNull( &lpsz );
  2042. return lRetValue;
  2043. }
  2044. LRESULT WINAPI ListView_SortItemsA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  2045. {
  2046. // not implement yet.
  2047. return SendMessageA( hWnd, Msg, wParam, lParam );
  2048. }
  2049. LRESULT WINAPI ListView_EditLabelA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  2050. {
  2051. return SendMessageA(hWnd, LVM_EDITLABELA, wParam, lParam );
  2052. }
  2053. LRESULT WINAPI ToolBar_AddString(HWND hWnd, LPARAM lParam)
  2054. {
  2055. LRESULT lRetValue;
  2056. LPSTR pStringA = NULL;
  2057. LPWSTR pStringW = NULL;
  2058. LPSTR pStringA_T = NULL, pStringAA = NULL;
  2059. DWORD dwLen;
  2060. WPARAM wParam = 0;
  2061. // get the total length of pStringW
  2062. if (g_bRunningOnNT)
  2063. return SendMessageW(hWnd, TB_ADDSTRINGW, wParam, lParam );
  2064. dwLen = 0;
  2065. pStringW = (LPWSTR)(lParam);
  2066. while ( *pStringW != TEXT('\0') ) {
  2067. dwLen += lstrlenW(pStringW) + 1;
  2068. pStringW += lstrlenW(pStringW) + 1;
  2069. }
  2070. dwLen += 1; // for the last null terminator
  2071. pStringW = (LPWSTR)( lParam );
  2072. pStringA = LocalAlloc( LMEM_ZEROINIT, dwLen * sizeof(WCHAR) );
  2073. pStringA_T = pStringA;
  2074. while ( *pStringW != TEXT('\0') ) {
  2075. pStringAA = ConvertWtoA(pStringW );
  2076. pStringW += lstrlenW(pStringW) + 1;
  2077. strcpy(pStringA_T, pStringAA );
  2078. LocalFreeAndNull( &pStringAA );
  2079. pStringA_T += lstrlenA( pStringA_T ) + 1;
  2080. }
  2081. pStringA_T[lstrlenA(pStringA_T)+1] = '\0';
  2082. lRetValue = SendMessageA(hWnd, TB_ADDSTRINGA, wParam, (LPARAM)pStringA );
  2083. LocalFreeAndNull( &pStringA );
  2084. return lRetValue;
  2085. }
  2086. LRESULT WINAPI ToolBar_AddButtons(HWND hWnd, WPARAM wParam, LPARAM lParam)
  2087. {
  2088. if (g_bRunningOnNT)
  2089. return SendMessageW( hWnd, TB_ADDBUTTONSW, wParam, lParam );
  2090. return SendMessageA( hWnd, TB_ADDBUTTONSA, wParam, lParam );
  2091. }
  2092. LRESULT WINAPI TreeView_GetItemA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  2093. {
  2094. LRESULT lRetValue;
  2095. TVITEMA tviA;
  2096. LPTVITEMW lptviW;
  2097. LPWSTR lpszTextW = NULL;
  2098. LPSTR lpszTextA = NULL;
  2099. lptviW = (LPTVITEMW) lParam;
  2100. CopyMemory( &tviA, lptviW, sizeof( TVITEMA ) );
  2101. if ( lptviW->mask & TVIF_TEXT ) {
  2102. lpszTextA = ConvertWtoA( lptviW->pszText ) ;
  2103. tviA.pszText = lpszTextA;
  2104. tviA.cchTextMax = lstrlenA( lpszTextA ) + 1;
  2105. }
  2106. lRetValue = SendMessageA( hWnd, TVM_GETITEMA, wParam, (LPARAM)(LPTVITEMA)&tviA );
  2107. if ( lptviW->mask & TVIF_TEXT )
  2108. lpszTextW = ConvertAtoW( tviA.pszText );
  2109. lptviW->mask = tviA.mask;
  2110. lptviW->hItem = tviA.hItem;
  2111. lptviW->state = tviA.state;
  2112. lptviW->stateMask = tviA.stateMask;
  2113. if ( lpszTextW ) {
  2114. CopyMemory(lptviW->pszText, lpszTextW, (lstrlenW(lpszTextW)+1) * sizeof(WCHAR) );
  2115. lptviW->cchTextMax = lstrlenW( lpszTextW ) + 1;
  2116. }
  2117. lptviW->iImage = tviA.iImage;
  2118. lptviW->iSelectedImage = tviA.iSelectedImage;
  2119. lptviW->cChildren = tviA.cChildren;
  2120. lptviW->lParam = tviA.lParam;
  2121. LocalFreeAndNull( &lpszTextA );
  2122. LocalFreeAndNull( &lpszTextW );
  2123. return lRetValue;
  2124. }
  2125. LRESULT WINAPI TreeView_SetItemA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  2126. {
  2127. LRESULT lRetValue;
  2128. TVITEMA tviA;
  2129. LPTVITEMW lptviW;
  2130. LPSTR pszTextA = NULL;
  2131. lptviW = (LPTVITEMW) lParam;
  2132. CopyMemory( &tviA, lptviW, sizeof( TVITEMA ) );
  2133. if ( (lptviW->mask & TVIF_TEXT) && (lptviW->pszText != NULL) ) {
  2134. pszTextA = ConvertWtoA( lptviW->pszText );
  2135. tviA.cchTextMax = lstrlenA( pszTextA );
  2136. }
  2137. tviA.pszText = pszTextA;
  2138. lRetValue = SendMessageA( hWnd, TVM_SETITEMA, wParam, (LPARAM)(const TV_ITEM FAR*)&tviA );
  2139. LocalFreeAndNull( &pszTextA );
  2140. return lRetValue;
  2141. }
  2142. LRESULT WINAPI TreeView_InsertItemA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  2143. {
  2144. LRESULT lRetValue;
  2145. LPSTR pszTextA = NULL;
  2146. TVINSERTSTRUCTA tvisA;
  2147. LPTVINSERTSTRUCTW lptvisW;
  2148. lptvisW = (LPTVINSERTSTRUCTW)lParam;
  2149. CopyMemory( &tvisA, lptvisW, sizeof( TVINSERTSTRUCTA ) );
  2150. if ( ((lptvisW->item).mask & TVIF_TEXT) && ((lptvisW->item).pszText != NULL) ) {
  2151. pszTextA = ConvertWtoA( (lptvisW->item).pszText );
  2152. tvisA.item.cchTextMax = lstrlenA( pszTextA );
  2153. tvisA.item.pszText = pszTextA;
  2154. }
  2155. lRetValue = SendMessageA( hWnd, TVM_INSERTITEMA, wParam, (LPARAM)(LPTVINSERTSTRUCTA)&tvisA );
  2156. LocalFreeAndNull( &pszTextA );
  2157. return lRetValue;
  2158. }
  2159. // Tab Control Message Wrapper
  2160. LRESULT WINAPI TabCtrl_InsertItemA( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
  2161. {
  2162. LRESULT lRetValue;
  2163. TCITEMA tciA;
  2164. LPTCITEMW lptciW = NULL;
  2165. LPSTR pszText = NULL;
  2166. lptciW = (LPTCITEMW) lParam;
  2167. CopyMemory( &tciA, lptciW, sizeof(TCITEMA ) );
  2168. if ( lptciW->mask & TCIF_TEXT ) {
  2169. pszText = ConvertWtoA( lptciW->pszText );
  2170. tciA.pszText = pszText;
  2171. tciA.cchTextMax = lstrlenA( pszText ) + 1;
  2172. }
  2173. lRetValue = SendMessageA( hWnd, TCM_INSERTITEMA, wParam, (LPARAM)(LPTCITEMA)&tciA);
  2174. LocalFreeAndNull( &pszText );
  2175. return lRetValue;
  2176. }
  2177. // List Box Control Message wrapper
  2178. LRESULT WINAPI ListBox_AddStringA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2179. {
  2180. LRESULT lRetValue;
  2181. LPSTR lpszStrA = NULL;
  2182. LPWSTR lpszStrW = NULL;
  2183. lpszStrW = (LPWSTR)lParam;
  2184. lpszStrA = ConvertWtoA(lpszStrW);
  2185. lRetValue = SendMessageA(hWnd, LB_ADDSTRING, wParam, (LPARAM)lpszStrA);
  2186. LocalFreeAndNull(&lpszStrA);
  2187. return lRetValue;
  2188. }
  2189. // Combo List Control Message wrapper
  2190. LRESULT WINAPI Combo_AddStringA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  2191. {
  2192. LRESULT lRetValue;
  2193. LPSTR lpszStrA = NULL;
  2194. LPWSTR lpszStrW = NULL;
  2195. lpszStrW = (LPWSTR)lParam;
  2196. lpszStrA = ConvertWtoA( lpszStrW );
  2197. lRetValue = SendMessageA(hWnd, CB_ADDSTRING, wParam, (LPARAM)lpszStrA );
  2198. LocalFreeAndNull( &lpszStrA );
  2199. return lRetValue;
  2200. }
  2201. LRESULT WINAPI Combo_GetLBTextA(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
  2202. {
  2203. LRESULT lRetValue;
  2204. LPSTR lpszStrA = NULL;
  2205. LPWSTR lpszStrW = NULL;
  2206. int nBytes;
  2207. Assert(lParam);
  2208. *((LPWSTR)lParam) = '\0';
  2209. // Allocate the single byte char buffer to the correct size
  2210. nBytes = (int) SendMessageA(hWnd, CB_GETLBTEXTLEN, wParam, 0) + 1;
  2211. lpszStrA = LocalAlloc(LMEM_FIXED, nBytes);
  2212. if (!lpszStrA)
  2213. {
  2214. Assert(0);
  2215. return 0;
  2216. }
  2217. *lpszStrA = '\0';
  2218. lRetValue = SendMessageA(hWnd, CB_GETLBTEXT, wParam, (LPARAM)(lpszStrA));
  2219. if ( lRetValue == CB_ERR )
  2220. return CB_ERR;
  2221. // lRetValue is the length of string lpszStrA, in Bytes.
  2222. // to make sure lpszStrA is Null-terminated.
  2223. lpszStrA[lRetValue] = '\0';
  2224. lpszStrW = ConvertAtoW( lpszStrA );
  2225. lRetValue = lstrlenW( lpszStrW ) * sizeof(WCHAR);
  2226. CopyMemory( (LPWSTR)lParam, lpszStrW, lRetValue + sizeof(WCHAR) );
  2227. LocalFreeAndNull(&lpszStrW);
  2228. LocalFreeAndNull(&lpszStrA);
  2229. return (LRESULT)lRetValue;
  2230. }
  2231. LRESULT WINAPI Combo_InsertStringA(HWND hWnd,UINT Msg, WPARAM wParam,LPARAM lParam)
  2232. {
  2233. LRESULT lRetValue;
  2234. LPSTR lpszStrA = NULL;
  2235. LPWSTR lpszStrW = NULL;
  2236. lpszStrW = (LPWSTR)lParam;
  2237. lpszStrA = ConvertWtoA( lpszStrW );
  2238. lRetValue = SendMessageA(hWnd, CB_INSERTSTRING, wParam, (LPARAM)lpszStrA );
  2239. LocalFreeAndNull( &lpszStrA );
  2240. return lRetValue;
  2241. }
  2242. LRESULT WINAPI Combo_FindStringA(HWND hWnd,UINT Msg, WPARAM wParam,LPARAM lParam)
  2243. {
  2244. LRESULT lRetValue;
  2245. LPSTR lpszStrA = NULL;
  2246. LPWSTR lpszStrW = NULL;
  2247. lpszStrW = (LPWSTR)lParam;
  2248. lpszStrA = ConvertWtoA( lpszStrW );
  2249. lRetValue = SendMessageA(hWnd, CB_FINDSTRING, wParam, (LPARAM)lpszStrA );
  2250. LocalFreeAndNull( &lpszStrA );
  2251. return lRetValue;
  2252. }
  2253. // Animation Control wrappers
  2254. LRESULT WINAPI Animate_OpenA( HWND hWnd,UINT Msg, WPARAM wParam,LPARAM lParam)
  2255. {
  2256. LRESULT lRetValue;
  2257. // lParam pointers to a string or resource String ID,
  2258. // in our codes, only Resources IDs are passed to this function
  2259. // so we don't want to convert value for this parameter
  2260. lRetValue = SendMessageA( hWnd, ACM_OPENA, wParam, lParam );
  2261. return lRetValue;
  2262. }
  2263. // Tooltip Wrappers
  2264. LRESULT WINAPI ToolTip_AddTool(HWND hWnd,LPARAM lParam)
  2265. {
  2266. LRESULT lRetValue;
  2267. LPSTR lpszStrA = NULL;
  2268. LPWSTR lpszStrW = NULL;
  2269. TOOLINFOA TIA = {0};
  2270. LPTOOLINFOW lpTIW = (LPTOOLINFOW)lParam;
  2271. WPARAM wParam = 0;
  2272. if (g_bRunningOnNT)
  2273. return SendMessageW(hWnd, TTM_ADDTOOLW, wParam, lParam);
  2274. if(!lpTIW)
  2275. return 0;
  2276. CopyMemory(&TIA, lpTIW, sizeof(TOOLINFOA));
  2277. TIA.lpszText = ConvertWtoA(lpTIW->lpszText);
  2278. lRetValue = SendMessageA(hWnd, TTM_ADDTOOLA, wParam, (LPARAM)&TIA );
  2279. LocalFreeAndNull( &TIA.lpszText );
  2280. return lRetValue;
  2281. }
  2282. //
  2283. // Guess what TTM_UPDATETIPTEXT is the same as EM_FORMATRANGE .. therefore can't use it
  2284. // through the SendMessage wrapper .. need our own function for this
  2285. LRESULT WINAPI ToolTip_UpdateTipText(HWND hWnd,LPARAM lParam)
  2286. {
  2287. LRESULT lRetValue;
  2288. LPSTR lpszStrA = NULL;
  2289. LPWSTR lpszStrW = NULL;
  2290. TOOLINFOA TIA = {0};
  2291. LPTOOLINFOW lpTIW = (LPTOOLINFOW)lParam;
  2292. WPARAM wParam = 0;
  2293. if (g_bRunningOnNT)
  2294. return SendMessageW(hWnd, TTM_UPDATETIPTEXTW, wParam, lParam);
  2295. if(!lpTIW)
  2296. return 0;
  2297. CopyMemory(&TIA, lpTIW, sizeof(TOOLINFOA));
  2298. TIA.lpszText = ConvertWtoA(lpTIW->lpszText);
  2299. lRetValue = SendMessageA(hWnd, TTM_UPDATETIPTEXTA, wParam, (LPARAM)&TIA );
  2300. LocalFreeAndNull( &TIA.lpszText );
  2301. return lRetValue;
  2302. }
  2303. // SendMessage WM_SETTEXT
  2304. LRESULT WINAPI WM_SetTextA( HWND hWnd, UINT Msg, // message to send
  2305. WPARAM wParam, // first message parameter
  2306. LPARAM lParam ) // second message parameter
  2307. {
  2308. LRESULT lRetValue = 0;
  2309. LPSTR lpA = ConvertWtoA((LPCWSTR)lParam);
  2310. lRetValue = SendMessageA(hWnd, WM_SETTEXT, wParam, (LPARAM)lpA);
  2311. LocalFreeAndNull(&lpA);
  2312. return lRetValue;
  2313. }
  2314. // SendMessage
  2315. //
  2316. // There is a big potential problem with this function .. since we
  2317. // are passing ALL the messages through this function, if there are any over-lapping
  2318. // message ids (e.g. TTM_UPDATETIPTEXT for tooltips is the same as EM_FORMATRANGE
  2319. // for the RichEdit control) with the result that we may route the wrong message to the
  2320. // wrong handler.. need to be careful about handling any messages in the WM_USER range ..
  2321. // This is specially true for a bunch of CommCtrls.
  2322. //
  2323. LRESULT WINAPI SendMessageWrapW( HWND hWnd, // handle of destination window
  2324. UINT Msg, // message to send
  2325. WPARAM wParam, // first message parameter
  2326. LPARAM lParam ) // second message parameter
  2327. {
  2328. VALIDATE_PROTOTYPE(SendMessage);
  2329. if (g_bRunningOnNT)
  2330. return SendMessageW(hWnd, Msg, wParam, lParam);
  2331. switch (Msg) {
  2332. case WM_SETTEXT:
  2333. return WM_SetTextA(hWnd, Msg, wParam, lParam);
  2334. // for ListView Message
  2335. case LVM_GETITEMTEXT :
  2336. return ListView_GetItemTextA(hWnd, Msg, wParam, lParam);
  2337. case LVM_GETITEM :
  2338. return ListView_GetItemA(hWnd, Msg, wParam, lParam);
  2339. case LVM_INSERTCOLUMN :
  2340. return ListView_InsertColumnA( hWnd, Msg, wParam, lParam);
  2341. case LVM_INSERTITEM :
  2342. return ListView_InsertItemA(hWnd, Msg, wParam, lParam);
  2343. case LVM_SETITEM :
  2344. return ListView_SetItemA(hWnd, Msg, wParam, lParam);
  2345. case LVM_SETITEMTEXT :
  2346. return ListView_SetItemTextA(hWnd, Msg, wParam, lParam);
  2347. case LVM_SETCOLUMN :
  2348. return ListView_SetColumnA(hWnd, Msg, wParam, lParam);
  2349. case LVM_FINDITEM :
  2350. return ListView_FindItemA(hWnd, Msg, wParam, lParam);
  2351. case LVM_SORTITEMS :
  2352. return ListView_SortItemsA(hWnd, Msg, wParam, lParam);
  2353. case LVM_EDITLABEL :
  2354. return ListView_EditLabelA(hWnd, Msg, wParam, lParam);
  2355. // For TreeView Message
  2356. case TVM_GETITEM :
  2357. return TreeView_GetItemA(hWnd, Msg, wParam, lParam);
  2358. case TVM_SETITEM :
  2359. return TreeView_SetItemA(hWnd, Msg, wParam, lParam);
  2360. case TVM_INSERTITEM :
  2361. return TreeView_InsertItemA(hWnd, Msg, wParam, lParam);
  2362. // For TabCtrl Message
  2363. case TCM_INSERTITEM :
  2364. return TabCtrl_InsertItemA( hWnd, Msg, wParam, lParam);
  2365. // For ComBo List Control
  2366. case CB_ADDSTRING :
  2367. return Combo_AddStringA(hWnd, Msg, wParam, lParam);
  2368. case CB_GETLBTEXT :
  2369. return Combo_GetLBTextA(hWnd, Msg, wParam, lParam);
  2370. case CB_INSERTSTRING :
  2371. return Combo_InsertStringA(hWnd, Msg, wParam, lParam);
  2372. case CB_FINDSTRING :
  2373. return Combo_FindStringA(hWnd, Msg, wParam, lParam);
  2374. // For ListBox Control
  2375. case LB_ADDSTRING:
  2376. return ListBox_AddStringA(hWnd, Msg, wParam, lParam);
  2377. // For Animation Control
  2378. case ACM_OPEN :
  2379. return Animate_OpenA( hWnd, Msg, wParam, lParam);
  2380. // For Others
  2381. default :
  2382. return SendMessageA(hWnd, Msg, wParam, lParam);
  2383. }
  2384. }
  2385. // DefWindowProc
  2386. LRESULT WINAPI DefWindowProcWrapW( HWND hWnd, // handle to window
  2387. UINT Msg, // message identifier
  2388. WPARAM wParam, // first message parameter
  2389. LPARAM lParam ) // second message parameter
  2390. {
  2391. VALIDATE_PROTOTYPE(DefWindowProc);
  2392. if (g_bRunningOnNT)
  2393. return DefWindowProcW(hWnd, Msg, wParam, lParam);
  2394. return DefWindowProcA(hWnd, Msg, wParam, lParam);
  2395. }
  2396. // wsprintf
  2397. int WINAPI wsprintfWrapW( LPTSTR lpOut, // pointer to buffer for output
  2398. LPCTSTR lpFmt, // pointer to format-control string
  2399. ... ) // optional arguments
  2400. {
  2401. va_list ArgList;
  2402. va_start(ArgList, lpFmt);
  2403. return wvsprintfWrapW(lpOut, lpFmt, ArgList);
  2404. /*
  2405. LPSTR lpFmtA = NULL, lpTemp = NULL;
  2406. char szOut[1024]; //wsprintf has a 1k limit
  2407. int nRet = 0;
  2408. LPWSTR lpOutW = NULL;
  2409. VALIDATE_PROTOTYPE(wsprintf);
  2410. if (g_bRunningOnNT)
  2411. return wsprintfW(lpOut, lpFmt, ... );
  2412. // The argument list can have variable number of LPWSTR parameters which would
  2413. // be too hard to check individually .. instead we can do one of 2 things:
  2414. // - we can change every %s to %S in the format string .. %S will tell the wsprintfA
  2415. // that the argument is a wide string
  2416. // - if this doesn't work then we can try making sure the input format string uses %ws always
  2417. //
  2418. lpFmtA = ConvertWtoA((LPWSTR)lpFmt);
  2419. lpTemp = lpFmtA;
  2420. while(lpTemp && *lpTemp)
  2421. {
  2422. if(*lpTemp == '%' && *(lpTemp+1) == 's')
  2423. *(lpTemp+1) = 'S';
  2424. lpTemp++;
  2425. }
  2426. nRet = wsprintfA(szOut,lpFmtA, ...);
  2427. lpOutW = ConvertAtoW(szOut);
  2428. My_wcscpy(lpOut, lpOutW);
  2429. LocalFreeAndNull(&lpOutW);
  2430. LocalFreeAndNull(&lpFmtA);
  2431. return nRet;
  2432. */
  2433. }
  2434. // wvsprintf
  2435. int WINAPI wvsprintfWrapW( LPTSTR lpOut, // pointer to buffer for output
  2436. LPCTSTR lpFmt, // pointer to format-control string
  2437. va_list arglist ) // variable list of format-control arguments
  2438. {
  2439. LPSTR lpFmtA = NULL, lpTemp = NULL;
  2440. char szOut[1024];
  2441. int nRet = 0;
  2442. LPWSTR lpOutW = NULL;
  2443. VALIDATE_PROTOTYPE(wvsprintf);
  2444. if (g_bRunningOnNT)
  2445. return wvsprintfW(lpOut, lpFmt, arglist);
  2446. // The argument list can have variable number of LPWSTR parameters which would
  2447. // be too hard to check individually .. instead we can do one of 2 things:
  2448. // - we can change every %s to %S in the format string .. %S will tell the wsprintfA
  2449. // that the argument is a wide string
  2450. // - if this doesn't work then we can try making sure the input format string uses %ws always
  2451. //
  2452. lpFmtA = ConvertWtoA((LPWSTR)lpFmt);
  2453. lpTemp = lpFmtA;
  2454. while(lpTemp && *lpTemp)
  2455. {
  2456. if(*lpTemp == '%' && *(lpTemp+1) == 's')
  2457. *(lpTemp+1) = 'S';
  2458. lpTemp++;
  2459. }
  2460. nRet = wvsprintfA(szOut,lpFmtA, arglist);
  2461. lpOutW = ConvertAtoW(szOut);
  2462. My_wcscpy(lpOut, lpOutW);
  2463. LocalFreeAndNull(&lpOutW);
  2464. LocalFreeAndNull(&lpFmtA);
  2465. return nRet;
  2466. }
  2467. // DialogBoxParam
  2468. INT_PTR WINAPI DialogBoxParamWrapW( HINSTANCE hInstance, // handle to application instance
  2469. LPCTSTR lpTemplateName, // identifies dialog box template
  2470. HWND hWndParent, // handle to owner window
  2471. DLGPROC lpDialogFunc, // pointer to dialog box procedure
  2472. LPARAM dwInitParam ) // initialization value
  2473. {
  2474. INT_PTR iRetValue = 0;
  2475. // LPSTR lpTemplateNameA = NULL;
  2476. VALIDATE_PROTOTYPE(DialogBoxParam);
  2477. if (g_bRunningOnNT)
  2478. return DialogBoxParamW(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  2479. // all templateName passed in our current codes are just IDD.
  2480. // so don't do A/W conversion.
  2481. // lpTemplateNameA = ConvertWtoA( lpTemplateName );
  2482. iRetValue = DialogBoxParamA(hInstance, (LPCSTR)lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  2483. // LocalFreeAndNull( &lpTemplateNameA );
  2484. if(iRetValue == -1)
  2485. DebugTrace(TEXT("Error creating dialog: %d\n"), GetLastError());
  2486. return iRetValue;
  2487. }
  2488. // SendDlgItemMessage
  2489. LRESULT WINAPI SendDlgItemMessageWrapW( HWND hDlg, // handle of dialog box
  2490. int nIDDlgItem, // identifier of control
  2491. UINT Msg, // message to send
  2492. WPARAM wParam, // first message parameter
  2493. LPARAM lParam ) // second message parameter
  2494. {
  2495. VALIDATE_PROTOTYPE(SendDlgItemMessage);
  2496. if (g_bRunningOnNT)
  2497. return SendDlgItemMessageW(hDlg, nIDDlgItem, Msg, wParam, lParam);
  2498. // [PaulHi] 1/19/99 Raid 66195
  2499. // Must special case Win9X wrapper failures, just like with SendMessage
  2500. // command
  2501. {
  2502. LPWSTR lpszStrW = NULL;
  2503. LPSTR lpszStrA = NULL;
  2504. LRESULT lRetValue = 0;
  2505. switch (Msg)
  2506. {
  2507. case LB_GETTEXT:
  2508. case CB_GETLBTEXT:
  2509. case WM_GETTEXT:
  2510. // Wrapper function returns single byte string instead of double byte.
  2511. // Note that caller should be expecting double byte and should set lParam
  2512. // size accordingly.
  2513. lRetValue = SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam, lParam);
  2514. lpszStrW = ConvertAtoW((LPSTR)lParam);
  2515. lstrcpyWrapW((LPTSTR)lParam, lpszStrW);
  2516. LocalFreeAndNull(&lpszStrW);
  2517. break;
  2518. case CB_ADDSTRING:
  2519. Assert(lParam);
  2520. lpszStrA = ConvertWtoA((LPCWSTR)lParam);
  2521. lRetValue = SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam, (LPARAM)lpszStrA);
  2522. LocalFreeAndNull(&lpszStrA);
  2523. break;
  2524. default:
  2525. lRetValue = SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam, lParam);
  2526. }
  2527. return lRetValue;
  2528. }
  2529. }
  2530. // SetWindowLong
  2531. LONG WINAPI SetWindowLongWrapW( HWND hWnd, // handle of window
  2532. int nIndex, // offset of value to set
  2533. LONG dwNewLong ) // new value
  2534. {
  2535. VALIDATE_PROTOTYPE(SetWindowLong);
  2536. if (g_bRunningOnNT)
  2537. return SetWindowLongW(hWnd, nIndex, dwNewLong);
  2538. return SetWindowLongA(hWnd, nIndex, dwNewLong);
  2539. }
  2540. // GetWindowLong
  2541. LONG WINAPI GetWindowLongWrapW( HWND hWnd, // handle of window
  2542. int nIndex ) // offset of value to retrieve
  2543. {
  2544. VALIDATE_PROTOTYPE(GetWindowLong);
  2545. if (g_bRunningOnNT)
  2546. return GetWindowLongW(hWnd, nIndex);
  2547. return GetWindowLongA(hWnd, nIndex);
  2548. }
  2549. // SetWindowLong
  2550. LONG_PTR WINAPI SetWindowLongPtrWrapW( HWND hWnd, // handle of window
  2551. int nIndex, // offset of value to set
  2552. LONG_PTR dwNewLong ) // new value
  2553. {
  2554. VALIDATE_PROTOTYPE(SetWindowLongPtr);
  2555. if (g_bRunningOnNT)
  2556. return SetWindowLongPtrW(hWnd, nIndex, dwNewLong);
  2557. return SetWindowLongPtrA(hWnd, nIndex, dwNewLong);
  2558. }
  2559. // GetWindowLong
  2560. LONG_PTR WINAPI GetWindowLongPtrWrapW( HWND hWnd, // handle of window
  2561. int nIndex ) // offset of value to retrieve
  2562. {
  2563. VALIDATE_PROTOTYPE(GetWindowLongPtr);
  2564. if (g_bRunningOnNT)
  2565. return GetWindowLongPtrW(hWnd, nIndex);
  2566. return GetWindowLongPtrA(hWnd, nIndex);
  2567. }
  2568. // CreateWindowEx
  2569. HWND WINAPI CreateWindowExWrapW( DWORD dwExStyle, // extended window style
  2570. LPCTSTR lpClassName, // pointer to registered class name
  2571. LPCTSTR lpWindowName, // pointer to window name
  2572. DWORD dwStyle, // window style
  2573. int x, // horizontal position of window
  2574. int y, // vertical position of window
  2575. int nWidth, // window width
  2576. int nHeight, // window height
  2577. HWND hWndParent, // handle to parent or owner window
  2578. HMENU hMenu, // handle to menu, or child-window identifier
  2579. HINSTANCE hInstance, // handle to application instance
  2580. LPVOID lpParam ) // pointer to window-creation data
  2581. {
  2582. HWND hRetValue = NULL;
  2583. LPSTR lpClassNameA = NULL;
  2584. LPSTR lpWindowNameA = NULL;
  2585. VALIDATE_PROTOTYPE(CreateWindowEx);
  2586. if (g_bRunningOnNT)
  2587. return CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y,
  2588. nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
  2589. lpClassNameA = ConvertWtoA( lpClassName );
  2590. lpWindowNameA = ConvertWtoA( lpWindowName );
  2591. hRetValue = CreateWindowExA(dwExStyle, lpClassNameA, lpWindowNameA, dwStyle, x, y,
  2592. nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
  2593. LocalFreeAndNull( &lpClassNameA );
  2594. LocalFreeAndNull( &lpWindowNameA );
  2595. return hRetValue;
  2596. }
  2597. // UnregisterClass
  2598. BOOL WINAPI UnregisterClassWrapW( LPCTSTR lpClassName, // address of class name string
  2599. HINSTANCE hInstance ) // handle of application instance
  2600. {
  2601. BOOL bRetValue;
  2602. LPSTR lpClassNameA = NULL;
  2603. VALIDATE_PROTOTYPE(UnregisterClass);
  2604. if (g_bRunningOnNT)
  2605. return UnregisterClassW(lpClassName, hInstance);
  2606. lpClassNameA = ConvertWtoA( lpClassName );
  2607. bRetValue = UnregisterClassA(lpClassNameA, hInstance);
  2608. LocalFreeAndNull( &lpClassNameA );
  2609. return bRetValue;
  2610. }
  2611. // RegisterClass
  2612. ATOM WINAPI RegisterClassWrapW(CONST WNDCLASS *lpWndClass ) // address of structure with class date
  2613. {
  2614. ATOM aRetValue;
  2615. WNDCLASSA CLassA;
  2616. LPSTR lpszMenuName = NULL;
  2617. LPSTR lpszClassName = NULL;
  2618. VALIDATE_PROTOTYPE(RegisterClass);
  2619. if (g_bRunningOnNT)
  2620. return RegisterClassW(lpWndClass);
  2621. CLassA.style = lpWndClass->style;
  2622. CLassA.lpfnWndProc = lpWndClass->lpfnWndProc;
  2623. CLassA.cbClsExtra = lpWndClass->cbClsExtra;
  2624. CLassA.cbWndExtra = lpWndClass->cbWndExtra;
  2625. CLassA.hInstance = lpWndClass->hInstance;
  2626. CLassA.hIcon = lpWndClass->hIcon;
  2627. CLassA.hCursor = lpWndClass->hCursor;
  2628. CLassA.hbrBackground = lpWndClass->hbrBackground;
  2629. CLassA.lpszMenuName = NULL;
  2630. CLassA.lpszClassName = NULL;
  2631. if ( lpWndClass->lpszMenuName) {
  2632. lpszMenuName = ConvertWtoA(lpWndClass->lpszMenuName);
  2633. CLassA.lpszMenuName = lpszMenuName;
  2634. }
  2635. if ( lpWndClass->lpszClassName ) {
  2636. lpszClassName = ConvertWtoA(lpWndClass->lpszClassName);
  2637. CLassA.lpszClassName = lpszClassName;
  2638. }
  2639. aRetValue = RegisterClassA(&CLassA);
  2640. LocalFreeAndNull( &lpszMenuName );
  2641. LocalFreeAndNull( &lpszClassName );
  2642. return aRetValue;
  2643. }
  2644. // LoadCursor
  2645. HCURSOR WINAPI LoadCursorWrapW( HINSTANCE hInstance, // handle to application instance
  2646. LPCTSTR lpCursorName ) // name string or cursor resource identifier
  2647. {
  2648. VALIDATE_PROTOTYPE(LoadCursor);
  2649. if (g_bRunningOnNT)
  2650. return LoadCursorW(hInstance, lpCursorName);
  2651. return LoadCursorA(hInstance, (LPSTR)lpCursorName);
  2652. }
  2653. // RegisterWindowMessage
  2654. UINT WINAPI RegisterWindowMessageWrapW( LPCTSTR lpString ) // address of message string
  2655. {
  2656. UINT uRetValue = 0;
  2657. LPSTR lpStringA = NULL;
  2658. VALIDATE_PROTOTYPE(RegisterWindowMessage);
  2659. if (g_bRunningOnNT)
  2660. return RegisterWindowMessageW(lpString);
  2661. lpStringA = ConvertWtoA( lpString );
  2662. uRetValue = RegisterWindowMessageA( lpStringA );
  2663. LocalFreeAndNull( &lpStringA );
  2664. return uRetValue;
  2665. }
  2666. // SystemParametersInfo
  2667. BOOL WINAPI SystemParametersInfoWrapW( UINT uiAction, // system parameter to query or set
  2668. UINT uiParam, // depends on action to be taken
  2669. PVOID pvParam, // depends on action to be taken
  2670. UINT fWinIni ) // user profile update flag
  2671. {
  2672. BOOL bRetValue;
  2673. LOGFONTA lfFontA;
  2674. LOGFONTW lfFontW;
  2675. VALIDATE_PROTOTYPE(SystemParametersInfo);
  2676. if (g_bRunningOnNT)
  2677. return SystemParametersInfoW(uiAction, uiParam, pvParam, fWinIni);
  2678. if ( uiAction != SPI_GETICONTITLELOGFONT )
  2679. return SystemParametersInfoA(uiAction, uiParam, pvParam, fWinIni);
  2680. // we handle SPI_GETICONTITLELOGFONT only for our special requirement. ...
  2681. bRetValue = SystemParametersInfoA(uiAction, uiParam, &lfFontA, fWinIni);
  2682. if ( bRetValue == FALSE ) return FALSE;
  2683. // copy all the fields except lfFaceName from lfFontA to lfFontW
  2684. CopyMemory(&lfFontW,&lfFontA, sizeof(LOGFONTA) );
  2685. // translate the lfFaceName[] from A to W
  2686. MultiByteToWideChar(GetACP(), 0, lfFontA.lfFaceName, LF_FACESIZE, lfFontW.lfFaceName, LF_FACESIZE);
  2687. CopyMemory(pvParam, &lfFontW, sizeof(LOGFONTW) );
  2688. return bRetValue;
  2689. }
  2690. /*
  2691. // No A & W version.
  2692. BOOL WINAPI ShowWindow( HWND hWnd, // handle to window
  2693. int nCmdShow ) // show state of window
  2694. */
  2695. // CreateDialogParam
  2696. HWND WINAPI CreateDialogParamWrapW( HINSTANCE hInstance, // handle to application instance
  2697. LPCTSTR lpTemplateName, // identifies dialog box template
  2698. HWND hWndParent, // handle to owner window
  2699. DLGPROC lpDialogFunc, // pointer to dialog box procedure
  2700. LPARAM dwInitParam ) // initialization value
  2701. {
  2702. VALIDATE_PROTOTYPE(CreateDialogParam);
  2703. if (g_bRunningOnNT)
  2704. return CreateDialogParamW(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  2705. return CreateDialogParamA(hInstance, (LPCSTR) lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  2706. }
  2707. // SetWindowText
  2708. BOOL WINAPI SetWindowTextWrapW( HWND hWnd, // handle to window or control
  2709. LPCTSTR lpString ) // address of string
  2710. {
  2711. BOOL bRetValue;
  2712. LPSTR lpStringA = NULL;
  2713. VALIDATE_PROTOTYPE(SetWindowText);
  2714. if (g_bRunningOnNT)
  2715. return SetWindowTextW(hWnd, lpString);
  2716. lpStringA = ConvertWtoA( lpString );
  2717. bRetValue = SetWindowTextA( hWnd, lpStringA);
  2718. LocalFreeAndNull( &lpStringA );
  2719. return bRetValue;
  2720. }
  2721. // PostMessage
  2722. BOOL WINAPI PostMessageWrapW( HWND hWnd, // handle of destination window
  2723. UINT Msg, // message to post
  2724. WPARAM wParam, // first message parameter
  2725. LPARAM lParam ) // second message parameter
  2726. {
  2727. VALIDATE_PROTOTYPE(PostMessage);
  2728. if (g_bRunningOnNT)
  2729. return PostMessageW(hWnd, Msg, wParam, lParam);
  2730. return PostMessageA(hWnd, Msg, wParam, lParam);
  2731. }
  2732. // GetMenuItemInfo
  2733. BOOL WINAPI GetMenuItemInfoWrapW( HMENU hMenu,
  2734. UINT uItem,
  2735. BOOL fByPosition,
  2736. LPMENUITEMINFO lpmii )
  2737. {
  2738. BOOL bRetValue;
  2739. MENUITEMINFOA miiA = {0};
  2740. LPSTR lpA = NULL;
  2741. LPWSTR lpW = NULL;
  2742. LPWSTR lpOld = NULL;
  2743. VALIDATE_PROTOTYPE(GetMenuItemInfo);
  2744. if (g_bRunningOnNT)
  2745. return GetMenuItemInfoW(hMenu, uItem, fByPosition, lpmii);
  2746. CopyMemory(&miiA, lpmii, sizeof(MENUITEMINFOA) );
  2747. miiA.cbSize = sizeof (MENUITEMINFOA);
  2748. if(miiA.fMask & MIIM_TYPE)
  2749. {
  2750. lpA = LocalAlloc(LMEM_ZEROINIT, lpmii->cch+1);
  2751. miiA.dwTypeData = lpA;
  2752. miiA.cch = lpmii->cch;
  2753. }
  2754. bRetValue = GetMenuItemInfoA(hMenu, uItem, fByPosition, &miiA);
  2755. if(bRetValue)
  2756. {
  2757. lpOld = lpmii->dwTypeData;
  2758. CopyMemory(lpmii, &miiA, sizeof(MENUITEMINFOA) );
  2759. lpmii->dwTypeData = lpOld;
  2760. if ( miiA.fMask & MIIM_TYPE )
  2761. {
  2762. lpW = ConvertAtoW(miiA.dwTypeData);
  2763. lstrcpyWrapW(lpmii->dwTypeData,lpW);
  2764. lpmii->cch = My_wcslen( lpmii->dwTypeData );
  2765. }
  2766. }
  2767. LocalFreeAndNull(&lpA);
  2768. LocalFreeAndNull(&lpW);
  2769. return bRetValue;
  2770. }
  2771. // GetClassInfo
  2772. BOOL WINAPI GetClassInfoWrapW( HINSTANCE hInstance, // handle of application instance
  2773. LPCTSTR lpClassName, // address of class name string
  2774. LPWNDCLASS lpWndClass ) // address of structure for class data
  2775. {
  2776. BOOL bRetValue;
  2777. LPSTR lpClassNameA = NULL;
  2778. WNDCLASSA ClassA;
  2779. VALIDATE_PROTOTYPE(GetClassInfo);
  2780. if (g_bRunningOnNT)
  2781. return GetClassInfoW(hInstance, lpClassName, lpWndClass);
  2782. lpClassNameA = ConvertWtoA( lpClassName );
  2783. bRetValue = GetClassInfoA(hInstance, lpClassNameA, &ClassA );
  2784. if (bRetValue == FALSE) {
  2785. LocalFreeAndNull( & lpClassNameA );
  2786. return FALSE;
  2787. }
  2788. CopyMemory(lpWndClass, &ClassA, sizeof(WNDCLASSA)-2*sizeof(LPSTR) );
  2789. if ( ClassA.lpszMenuName && !IS_INTRESOURCE(ClassA.lpszMenuName) )
  2790. lpWndClass->lpszMenuName = ConvertAtoW( ClassA.lpszMenuName );
  2791. else
  2792. lpWndClass->lpszMenuName = NULL;
  2793. if ( ClassA.lpszClassName && !IS_INTRESOURCE(ClassA.lpszClassName) ) // lpszClassName can be an atom, high word is null
  2794. lpWndClass->lpszClassName = ConvertAtoW( ClassA.lpszClassName);
  2795. else
  2796. lpWndClass->lpszClassName = NULL;
  2797. LocalFreeAndNull( & lpClassNameA );
  2798. return bRetValue;
  2799. }
  2800. //----------------------------------------------------------------------
  2801. //
  2802. // function: CharLowerWrapW( LPWSTR pch )
  2803. //
  2804. // purpose: Converts character to lowercase. Takes either a pointer
  2805. // to a string, or a character masquerading as a pointer.
  2806. // In the later case, the HIWORD must be zero. This is
  2807. // as spec'd for Win32.
  2808. //
  2809. // returns: Lowercased character or string. In the string case,
  2810. // the lowercasing is done inplace.
  2811. //
  2812. //----------------------------------------------------------------------
  2813. LPWSTR WINAPI
  2814. CharLowerWrapW( LPWSTR pch )
  2815. {
  2816. VALIDATE_PROTOTYPE(CharLower);
  2817. if (g_bRunningOnNT)
  2818. {
  2819. return CharLowerW( pch );
  2820. }
  2821. if (!HIWORD(pch))
  2822. {
  2823. WCHAR ch = (WCHAR)(LONG_PTR)pch;
  2824. CharLowerBuffWrapW( &ch, 1 );
  2825. pch = (LPWSTR)MAKEINTATOM(ch);
  2826. }
  2827. else
  2828. {
  2829. CharLowerBuffWrapW( pch, lstrlenW(pch) );
  2830. }
  2831. return pch;
  2832. }
  2833. //----------------------------------------------------------------------
  2834. //
  2835. // function: CharLowerBuffWrapW( LPWSTR pch, DWORD cch )
  2836. //
  2837. // purpose: Converts a string to lowercase. String must be cch
  2838. // characters in length.
  2839. //
  2840. // returns: Character count (cch). The lowercasing is done inplace.
  2841. //
  2842. //----------------------------------------------------------------------
  2843. DWORD WINAPI
  2844. CharLowerBuffWrapW( LPWSTR pch, DWORD cchLength )
  2845. {
  2846. DWORD cch;
  2847. VALIDATE_PROTOTYPE(CharLowerBuff);
  2848. if (g_bRunningOnNT)
  2849. {
  2850. return CharLowerBuffW( pch, cchLength );
  2851. }
  2852. for ( cch = cchLength; cch-- ; pch++ )
  2853. {
  2854. WCHAR ch = *pch;
  2855. if (IsCharUpperWrapW(ch))
  2856. {
  2857. if (ch < 0x0100)
  2858. {
  2859. *pch += 32; // Get Latin-1 out of the way first
  2860. }
  2861. else if (ch < 0x0531)
  2862. {
  2863. if (ch < 0x0391)
  2864. {
  2865. if (ch < 0x01cd)
  2866. {
  2867. if (ch <= 0x178)
  2868. {
  2869. if (ch < 0x0178)
  2870. {
  2871. *pch += (ch == 0x0130) ? 0 : 1;
  2872. }
  2873. else
  2874. {
  2875. *pch -= 121;
  2876. }
  2877. }
  2878. else
  2879. {
  2880. static const BYTE abLookup[] =
  2881. { // 0/8 1/9 2/a 3/b 4/c 5/d 6/e 7/f
  2882. /* 0x0179-0x17f */ 1, 0, 1, 0, 1, 0, 0,
  2883. /* 0x0180-0x187 */ 0, 210, 1, 0, 1, 0, 206, 1,
  2884. /* 0x0188-0x18f */ 0, 205, 205, 1, 0, 0, 79, 202,
  2885. /* 0x0190-0x197 */ 203, 1, 0, 205, 207, 0, 211, 209,
  2886. /* 0x0198-0x19f */ 1, 0, 0, 0, 211, 213, 0, 214,
  2887. /* 0x01a0-0x1a7 */ 1, 0, 1, 0, 1, 0, 0, 1,
  2888. /* 0x01a8-0x1af */ 0, 218, 0, 0, 1, 0, 218, 1,
  2889. /* 0x01b0-0x1b7 */ 0, 217, 217, 1, 0, 1, 0, 219,
  2890. /* 0x01b8-0x1bf */ 1, 0, 0, 0, 1, 0, 0, 0,
  2891. /* 0x01c0-0x1c7 */ 0, 0, 0, 0, 2, 0, 0, 2,
  2892. /* 0x01c8-0x1cb */ 0, 0, 2, 0
  2893. };
  2894. *pch += abLookup[ch-0x0179];
  2895. }
  2896. }
  2897. else if (ch < 0x0386)
  2898. {
  2899. switch (ch)
  2900. {
  2901. case 0x01f1: *pch += 2; break;
  2902. case 0x01f2: break;
  2903. default: *pch += 1;
  2904. }
  2905. }
  2906. else
  2907. {
  2908. static const BYTE abLookup[] =
  2909. { 38, 0, 37, 37, 37, 0, 64, 0, 63, 63 };
  2910. *pch += abLookup[ch-0x0386];
  2911. }
  2912. }
  2913. else
  2914. {
  2915. if (ch < 0x0410)
  2916. {
  2917. if (ch < 0x0401)
  2918. {
  2919. if (ch < 0x03e2)
  2920. {
  2921. if (!InRange(ch, 0x03d2, 0x03d4) &&
  2922. !(InRange(ch, 0x3da, 0x03e0) & !(ch & 1)))
  2923. {
  2924. *pch += 32;
  2925. }
  2926. }
  2927. else
  2928. {
  2929. *pch += 1;
  2930. }
  2931. }
  2932. else
  2933. {
  2934. *pch += 80;
  2935. }
  2936. }
  2937. else
  2938. {
  2939. if (ch < 0x0460)
  2940. {
  2941. *pch += 32;
  2942. }
  2943. else
  2944. {
  2945. *pch += 1;
  2946. }
  2947. }
  2948. }
  2949. }
  2950. else
  2951. {
  2952. if (ch < 0x2160)
  2953. {
  2954. if (ch < 0x1fba)
  2955. {
  2956. if (ch < 0x1f08)
  2957. {
  2958. if (ch < 0x1e00)
  2959. {
  2960. *pch += 48;
  2961. }
  2962. else
  2963. {
  2964. *pch += 1;
  2965. }
  2966. }
  2967. else if (!(InRange(ch, 0x1f88, 0x1faf) && (ch & 15)>7))
  2968. {
  2969. *pch -= 8;
  2970. }
  2971. }
  2972. else
  2973. {
  2974. static const BYTE abLookup[] =
  2975. { // 8 9 a b c d e f
  2976. 0, 0, 74, 74, 0, 0, 0, 0,
  2977. 86, 86, 86, 86, 0, 0, 0, 0,
  2978. 8, 8, 100, 100, 0, 0, 0, 0,
  2979. 8, 8, 112, 112, 7, 0, 0, 0,
  2980. 128, 128, 126, 126, 0, 0, 0, 0
  2981. };
  2982. int i = (ch-0x1fb0);
  2983. *pch -= (int)abLookup[((i>>1) & ~7) | (i & 7)];
  2984. }
  2985. }
  2986. else
  2987. {
  2988. if (ch < 0xff21)
  2989. {
  2990. if (ch < 0x24b6)
  2991. {
  2992. *pch += 16;
  2993. }
  2994. else
  2995. {
  2996. *pch += 26;
  2997. }
  2998. }
  2999. else
  3000. {
  3001. *pch += 32;
  3002. }
  3003. }
  3004. }
  3005. }
  3006. else
  3007. {
  3008. // These are Unicode Number Forms. They have lowercase counter-
  3009. // parts, but are not considered uppercase. Why, I don't know.
  3010. if (InRange(ch, 0x2160, 0x216f))
  3011. {
  3012. *pch += 16;
  3013. }
  3014. }
  3015. }
  3016. return cchLength;
  3017. }
  3018. //----------------------------------------------------------------------
  3019. //
  3020. // function: CharUpperBuffWrapW( LPWSTR pch, DWORD cch )
  3021. //
  3022. // purpose: Converts a string to uppercase. String must be cch
  3023. // characters in length. Note that this function is
  3024. // is messier that CharLowerBuffWrap, and the reason for
  3025. // this is many Unicode characters are considered uppercase,
  3026. // even when they don't have an uppercase counterpart.
  3027. //
  3028. // returns: Character count (cch). The uppercasing is done inplace.
  3029. //
  3030. //----------------------------------------------------------------------
  3031. DWORD WINAPI
  3032. CharUpperBuffWrapW( LPWSTR pch, DWORD cchLength )
  3033. {
  3034. DWORD cch;
  3035. VALIDATE_PROTOTYPE(CharUpperBuff);
  3036. if (g_bRunningOnNT)
  3037. {
  3038. return CharUpperBuffW( pch, cchLength );
  3039. }
  3040. for ( cch = cchLength; cch-- ; pch++ )
  3041. {
  3042. WCHAR ch = *pch;
  3043. if (IsCharLowerWrapW(ch))
  3044. {
  3045. if (ch < 0x00ff)
  3046. {
  3047. *pch -= ((ch != 0xdf) << 5);
  3048. }
  3049. else if (ch < 0x03b1)
  3050. {
  3051. if (ch < 0x01f5)
  3052. {
  3053. if (ch < 0x01ce)
  3054. {
  3055. if (ch < 0x017f)
  3056. {
  3057. if (ch < 0x0101)
  3058. {
  3059. *pch += 121;
  3060. }
  3061. else
  3062. {
  3063. *pch -= (ch != 0x0131 &&
  3064. ch != 0x0138 &&
  3065. ch != 0x0149);
  3066. }
  3067. }
  3068. else if (ch < 0x01c9)
  3069. {
  3070. static const BYTE abMask[] =
  3071. { // 6543210f edcba987
  3072. 0xfc, 0xbf, // 11111100 10111111
  3073. 0xbf, 0x67, // 10111111 01100111
  3074. 0xff, 0xef, // 11111111 11101111
  3075. 0xff, 0xf7, // 11111111 11110111
  3076. 0xbf, 0xfd // 10111111 11111101
  3077. };
  3078. int i = ch - 0x017f;
  3079. *pch -= ((abMask[i>>3] >> (i&7)) & 1) +
  3080. (ch == 0x01c6);
  3081. }
  3082. else
  3083. {
  3084. *pch -= ((ch != 0x01cb)<<1);
  3085. }
  3086. }
  3087. else
  3088. {
  3089. if (ch < 0x01df)
  3090. {
  3091. if (ch < 0x01dd)
  3092. {
  3093. *pch -= 1;
  3094. }
  3095. else
  3096. {
  3097. *pch -= 79;
  3098. }
  3099. }
  3100. else
  3101. {
  3102. *pch -= 1 + (ch == 0x01f3) -
  3103. InRange(ch,0x01f0,0x01f2);
  3104. }
  3105. }
  3106. }
  3107. else if (ch < 0x0253)
  3108. {
  3109. *pch -= (ch < 0x0250);
  3110. }
  3111. else if (ch < 0x03ac)
  3112. {
  3113. static const BYTE abLookup[] =
  3114. {// 0/8 1/9 2/a 3/b 4/c 5/d 6/e 7/f
  3115. /* 0x0253-0x0257 */ 210, 206, 0, 205, 205,
  3116. /* 0x0258-0x025f */ 0, 202, 0, 203, 0, 0, 0, 0,
  3117. /* 0x0260-0x0267 */ 205, 0, 0, 207, 0, 0, 0, 0,
  3118. /* 0x0268-0x026f */ 209, 211, 0, 0, 0, 0, 0, 211,
  3119. /* 0x0270-0x0277 */ 0, 0, 213, 0, 0, 214, 0, 0,
  3120. /* 0x0278-0x027f */ 0, 0, 0, 0, 0, 0, 0, 0,
  3121. /* 0x0280-0x0287 */ 0, 0, 0, 218, 0, 0, 0, 0,
  3122. /* 0x0288-0x028f */ 218, 0, 217, 217, 0, 0, 0, 0,
  3123. /* 0x0290-0x0297 */ 0, 0, 219
  3124. };
  3125. if (ch <= 0x0292)
  3126. {
  3127. *pch -= abLookup[ch - 0x0253];
  3128. }
  3129. }
  3130. else
  3131. {
  3132. *pch -= (ch == 0x03b0) ? 0 : (37 + (ch == 0x03ac));
  3133. }
  3134. }
  3135. else
  3136. {
  3137. if (ch < 0x0561)
  3138. {
  3139. if (ch < 0x0451)
  3140. {
  3141. if (ch < 0x03e3)
  3142. {
  3143. if (ch < 0x03cc)
  3144. {
  3145. *pch -= 32 - (ch == 0x03c2);
  3146. }
  3147. else
  3148. {
  3149. int i = (ch < 0x03d0);
  3150. *pch -= (i<<6) - i + (ch == 0x03cc);
  3151. }
  3152. }
  3153. else if (ch < 0x0430)
  3154. {
  3155. *pch -= (ch < 0x03f0);
  3156. }
  3157. else
  3158. {
  3159. *pch -= 32;
  3160. }
  3161. }
  3162. else if (ch < 0x0461)
  3163. {
  3164. *pch -= 80;
  3165. }
  3166. else
  3167. {
  3168. *pch -= 1;
  3169. }
  3170. }
  3171. else
  3172. {
  3173. if (ch < 0x1fb0)
  3174. {
  3175. if (ch < 0x1f70)
  3176. {
  3177. if (ch < 0x1e01)
  3178. {
  3179. int i = ch != 0x0587 && ch < 0x10d0;
  3180. *pch -= ((i<<5)+(i<<4)); /* 48 */
  3181. }
  3182. else if (ch < 0x1f00)
  3183. {
  3184. *pch -= !InRange(ch, 0x1e96, 0x1e9a);
  3185. }
  3186. else
  3187. {
  3188. int i = !InRange(ch, 0x1f50, 0x1f56)||(ch & 1);
  3189. *pch += (i<<3);
  3190. }
  3191. }
  3192. else
  3193. {
  3194. static const BYTE abLookup[] =
  3195. { 74, 86, 86, 100, 128, 112, 126 };
  3196. if ( ch <= 0x1f7d )
  3197. {
  3198. *pch += abLookup[(ch-0x1f70)>>1];
  3199. }
  3200. }
  3201. }
  3202. else
  3203. {
  3204. if (ch < 0x24d0)
  3205. {
  3206. if (ch < 0x1fe5)
  3207. {
  3208. *pch += (0x0023 & (1<<(ch&15))) ? 8 : 0;
  3209. }
  3210. else if (ch < 0x2170)
  3211. {
  3212. *pch += (0x0023 & (1<<(ch&15))) ? 7 : 0;
  3213. }
  3214. else
  3215. {
  3216. *pch -= ((ch > 0x24b5)<<4);
  3217. }
  3218. }
  3219. else if (ch < 0xff41)
  3220. {
  3221. int i = !InRange(ch, 0xfb00, 0xfb17);
  3222. *pch -= (i<<4)+(i<<3)+(i<<1); /* 26 */
  3223. }
  3224. else
  3225. {
  3226. *pch -= 32;
  3227. }
  3228. }
  3229. }
  3230. }
  3231. }
  3232. else
  3233. {
  3234. int i = InRange(ch, 0x2170, 0x217f);
  3235. *pch -= (i<<4);
  3236. }
  3237. }
  3238. return cchLength;
  3239. }
  3240. // CharUpper
  3241. //----------------------------------------------------------------------
  3242. //
  3243. // function: CharUpperWrapW( LPWSTR pch )
  3244. //
  3245. // purpose: Converts character to uppercase. Takes either a pointer
  3246. // to a string, or a character masquerading as a pointer.
  3247. // In the later case, the HIWORD must be zero. This is
  3248. // as spec'd for Win32.
  3249. //
  3250. // returns: Uppercased character or string. In the string case,
  3251. // the uppercasing is done inplace.
  3252. //
  3253. //----------------------------------------------------------------------
  3254. LPWSTR WINAPI
  3255. CharUpperWrapW( LPWSTR pch )
  3256. {
  3257. VALIDATE_PROTOTYPE(CharUpper);
  3258. if (g_bRunningOnNT)
  3259. {
  3260. return CharUpperW( pch );
  3261. }
  3262. if (!HIWORD(pch))
  3263. {
  3264. WCHAR ch = (WCHAR)(LONG_PTR)pch;
  3265. CharUpperBuffWrapW( &ch, 1 );
  3266. pch = (LPWSTR)MAKEINTATOM(ch);
  3267. }
  3268. else
  3269. {
  3270. CharUpperBuffWrapW( pch, lstrlenW(pch) );
  3271. }
  3272. return pch;
  3273. }
  3274. /*
  3275. LPTSTR WINAPI CharUpperWrapW( LPTSTR lpsz ) // single character or pointer to string
  3276. {
  3277. LPWSTR lpszW = NULL;
  3278. LPSTR lpszA = NULL;
  3279. LPSTR lpszUpperA = NULL;
  3280. VALIDATE_PROTOTYPE(CharUpper);
  3281. if (g_bRunningOnNT)
  3282. return CharUpperW(lpsz);
  3283. lpszA = ConvertWtoA( lpsz );
  3284. lpszUpperA = CharUpperA( lpszA );
  3285. lpszW = ConvertAtoW( lpszUpperA );
  3286. CopyMemory( lpsz, lpszW, My_wcslen(lpszW) * sizeof(WCHAR) );
  3287. LocalFreeAndNull( &lpszW );
  3288. LocalFreeAndNull( &lpszA );
  3289. return lpsz;
  3290. }
  3291. */
  3292. // RegisterClipboardFormat
  3293. UINT WINAPI RegisterClipboardFormatWrapW( LPCTSTR lpszFormat ) // address of name string
  3294. {
  3295. UINT uRetValue =0;
  3296. LPSTR lpszFormatA = NULL;
  3297. VALIDATE_PROTOTYPE(RegisterClipboardFormat);
  3298. if (g_bRunningOnNT)
  3299. return RegisterClipboardFormatW(lpszFormat);
  3300. lpszFormatA = ConvertWtoA( lpszFormat );
  3301. uRetValue = RegisterClipboardFormatA( lpszFormatA );
  3302. LocalFreeAndNull( &lpszFormatA );
  3303. return uRetValue;
  3304. }
  3305. // DispatchMessage
  3306. LRESULT WINAPI DispatchMessageWrapW( CONST MSG *lpmsg ) // pointer to structure with message
  3307. {
  3308. VALIDATE_PROTOTYPE(DispatchMessage);
  3309. if (g_bRunningOnNT)
  3310. return DispatchMessageW(lpmsg);
  3311. return DispatchMessageA(lpmsg);
  3312. }
  3313. /* No A & W version
  3314. BOOL WINAPI TranslateMessage( IN CONST MSG *lpMsg)
  3315. */
  3316. // IsDialogMessage
  3317. BOOL WINAPI IsDialogMessageWrapW( HWND hDlg, // handle of dialog box
  3318. LPMSG lpMsg ) // address of structure with message
  3319. {
  3320. VALIDATE_PROTOTYPE(IsDialogMessage);
  3321. if (g_bRunningOnNT)
  3322. return IsDialogMessageW(hDlg, lpMsg);
  3323. return IsDialogMessageA(hDlg, lpMsg);
  3324. }
  3325. // GetMessage
  3326. BOOL WINAPI GetMessageWrapW( LPMSG lpMsg, // address of structure with message
  3327. HWND hWnd, // handle of window
  3328. UINT wMsgFilterMin, // first message
  3329. UINT wMsgFilterMax ) // last message
  3330. {
  3331. VALIDATE_PROTOTYPE(GetMessage);
  3332. if (g_bRunningOnNT)
  3333. return GetMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
  3334. return GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
  3335. }
  3336. // SetDlgItemText
  3337. BOOL WINAPI SetDlgItemTextWrapW( HWND hDlg, // handle of dialog box
  3338. int nIDDlgItem, // identifier of control
  3339. LPCTSTR lpString ) // text to set
  3340. {
  3341. BOOL bRetValue;
  3342. LPSTR lpStringA = NULL;
  3343. VALIDATE_PROTOTYPE(SetDlgItemText);
  3344. if (g_bRunningOnNT)
  3345. return SetDlgItemTextW(hDlg, nIDDlgItem, lpString);
  3346. lpStringA = ConvertWtoA( lpString );
  3347. bRetValue = SetDlgItemTextA(hDlg, nIDDlgItem, lpStringA);
  3348. LocalFreeAndNull( &lpStringA );
  3349. return bRetValue;
  3350. }
  3351. // RegisterClassEx
  3352. ATOM WINAPI RegisterClassExWrapW( CONST WNDCLASSEX *lpwcx ) // address of structure with class data
  3353. {
  3354. ATOM aReturn;
  3355. WNDCLASSEXA wcxA;
  3356. PSTR lpszClassName = NULL;
  3357. PSTR lpszMenuName = NULL;
  3358. VALIDATE_PROTOTYPE(RegisterClassEx);
  3359. if (g_bRunningOnNT)
  3360. return RegisterClassExW(lpwcx);
  3361. wcxA.cbSize = sizeof(WNDCLASSEXA);
  3362. wcxA.style = lpwcx->style;
  3363. wcxA.lpfnWndProc = lpwcx->lpfnWndProc;
  3364. wcxA.cbClsExtra = lpwcx->cbClsExtra;
  3365. wcxA.cbWndExtra = lpwcx->cbWndExtra;
  3366. wcxA.hInstance = lpwcx->hInstance;
  3367. wcxA.hIcon = lpwcx->hIcon;
  3368. wcxA.hCursor = lpwcx->hCursor;
  3369. wcxA.hbrBackground = lpwcx->hbrBackground;
  3370. wcxA.hIconSm = lpwcx->hIconSm;
  3371. if ( lpwcx->lpszMenuName) {
  3372. lpszMenuName = ConvertWtoA(lpwcx->lpszMenuName);
  3373. wcxA.lpszMenuName = lpszMenuName;
  3374. }
  3375. if (lpwcx->lpszClassName) {
  3376. lpszClassName = ConvertWtoA(lpwcx->lpszClassName);
  3377. wcxA.lpszClassName = lpszClassName;
  3378. }
  3379. aReturn = RegisterClassExA( &wcxA );
  3380. if ( wcxA.lpszMenuName)
  3381. LocalFreeAndNull( &lpszMenuName );
  3382. if (wcxA.lpszClassName)
  3383. LocalFreeAndNull( &lpszClassName );
  3384. return aReturn;
  3385. }
  3386. // LoadAccelerators
  3387. HACCEL WINAPI LoadAcceleratorsWrapW( HINSTANCE hInstance, // handle to application instance
  3388. LPCTSTR lpTableName ) // address of table-name string
  3389. {
  3390. HACCEL hRetValue = NULL;
  3391. LPSTR lpTableNameA = NULL;
  3392. VALIDATE_PROTOTYPE(LoadAccelerators);
  3393. if (g_bRunningOnNT)
  3394. return LoadAcceleratorsW(hInstance, lpTableName);
  3395. lpTableNameA = ConvertWtoA( lpTableName );
  3396. hRetValue = LoadAcceleratorsA( hInstance, lpTableNameA );
  3397. LocalFreeAndNull( &lpTableNameA );
  3398. return hRetValue;
  3399. }
  3400. // LoadMenu
  3401. HMENU WINAPI LoadMenuWrapW( HINSTANCE hInstance, // handle to application instance
  3402. LPCTSTR lpMenuName ) // menu name string or menu-resource identifier
  3403. {
  3404. HMENU hRetValue = NULL;
  3405. LPSTR lpMenuNameA = NULL;
  3406. VALIDATE_PROTOTYPE(LoadMenu);
  3407. if (g_bRunningOnNT)
  3408. return LoadMenuW(hInstance, lpMenuName);
  3409. // becuause all the calling to this functions in our project just pass
  3410. // and Resource ID as lpMenuName. so don't need to covert like a string
  3411. lpMenuNameA = MAKEINTRESOURCEA(lpMenuName);
  3412. hRetValue = LoadMenuA(hInstance,lpMenuNameA);
  3413. return hRetValue;
  3414. }
  3415. //LoadIcon
  3416. HICON WINAPI LoadIconWrapW( HINSTANCE hInstance, // handle to application instance
  3417. LPCTSTR lpIconName ) // icon-name string or icon resource identifier
  3418. {
  3419. HICON hRetValue = NULL;
  3420. LPSTR lpIconNameA = NULL;
  3421. VALIDATE_PROTOTYPE(LoadIcon);
  3422. if (g_bRunningOnNT)
  3423. return LoadIconW(hInstance, lpIconName);
  3424. // becuause all the calling to this functions in our project just pass
  3425. // and Resource ID as lpMenuName. so don't need to covert like a string
  3426. lpIconNameA = MAKEINTRESOURCEA(lpIconName );
  3427. hRetValue = LoadIconA(hInstance, lpIconNameA);
  3428. return hRetValue;
  3429. }
  3430. // GetWindowText
  3431. int WINAPI GetWindowTextWrapW( HWND hWnd, // handle to window or control with text
  3432. LPTSTR lpString, // address of buffer for text
  3433. int nMaxCount ) // maximum number of characters to copy
  3434. {
  3435. int iRetValue =0;
  3436. LPSTR lpStringA = NULL;
  3437. LPWSTR lpStringW = NULL;
  3438. int nCount =0;
  3439. VALIDATE_PROTOTYPE(GetWindowText);
  3440. *lpString = '\0';
  3441. if (g_bRunningOnNT)
  3442. return GetWindowTextW(hWnd, lpString, nMaxCount);
  3443. nCount = nMaxCount * sizeof( WCHAR );
  3444. lpStringA = LocalAlloc( LMEM_ZEROINIT, nCount );
  3445. iRetValue = GetWindowTextA(hWnd, lpStringA, nCount);
  3446. if ( iRetValue == 0 ) {
  3447. LocalFreeAndNull( &lpStringA );
  3448. return iRetValue;
  3449. }
  3450. lpStringW = ConvertAtoW( lpStringA );
  3451. nCount = My_wcslen( lpStringW );
  3452. if ( nCount >= nMaxCount )
  3453. nCount = nMaxCount - 1;
  3454. CopyMemory( lpString, lpStringW, nCount * sizeof(WCHAR) );
  3455. lpString[nCount] = 0x0000;
  3456. iRetValue = nCount;
  3457. LocalFreeAndNull( &lpStringA );
  3458. LocalFreeAndNull( &lpStringW );
  3459. return iRetValue;
  3460. }
  3461. // CallWindowProcWrap
  3462. LRESULT WINAPI CallWindowProcWrapW( WNDPROC lpPrevWndFunc, // pointer to previous procedure
  3463. HWND hWnd, // handle to window
  3464. UINT Msg, // message
  3465. WPARAM wParam, // first message parameter
  3466. LPARAM lParam ) // second message parameter
  3467. {
  3468. VALIDATE_PROTOTYPE(CallWindowProc);
  3469. if (g_bRunningOnNT)
  3470. return CallWindowProcW(lpPrevWndFunc, hWnd, Msg, wParam, lParam);
  3471. return CallWindowProcA(lpPrevWndFunc, hWnd, Msg, wParam, lParam);
  3472. }
  3473. // GetClassName
  3474. int WINAPI GetClassNameWrapW( HWND hWnd, // handle of window
  3475. LPTSTR lpClassName, // address of buffer for class name
  3476. int nMaxCount ) // size of buffer, in characters
  3477. {
  3478. int iRetValue =0;
  3479. LPSTR lpClassNameA = NULL;
  3480. LPWSTR lpClassNameW = NULL;
  3481. int nCount =0;
  3482. VALIDATE_PROTOTYPE(GetClassName);
  3483. if (g_bRunningOnNT)
  3484. return GetClassNameW(hWnd, lpClassName, nMaxCount);
  3485. nCount = nMaxCount * sizeof( WCHAR );
  3486. lpClassNameA = LocalAlloc( LMEM_ZEROINIT, nCount );
  3487. iRetValue = GetClassNameA(hWnd, lpClassNameA, nCount);
  3488. if ( iRetValue == 0 ) {
  3489. LocalFreeAndNull( &lpClassNameA );
  3490. return iRetValue;
  3491. }
  3492. lpClassNameW = ConvertAtoW( lpClassNameA );
  3493. nCount = My_wcslen( lpClassNameW );
  3494. if ( nCount >= nMaxCount )
  3495. nCount = nMaxCount - 1;
  3496. CopyMemory( lpClassName, lpClassNameW, nCount * sizeof(WCHAR) );
  3497. lpClassName[nCount] = 0x0000;
  3498. iRetValue = nCount;
  3499. LocalFreeAndNull( &lpClassNameA );
  3500. LocalFreeAndNull( &lpClassNameW );
  3501. return iRetValue;
  3502. }
  3503. // TranslateAccelerator
  3504. int WINAPI TranslateAcceleratorWrapW( HWND hWnd, // handle to destination window
  3505. HACCEL hAccTable, // handle to accelerator table
  3506. LPMSG lpMsg ) // address of structure with message
  3507. {
  3508. VALIDATE_PROTOTYPE(TranslateAccelerator);
  3509. if (g_bRunningOnNT)
  3510. return TranslateAcceleratorW(hWnd, hAccTable, lpMsg);
  3511. return TranslateAcceleratorA(hWnd, hAccTable, lpMsg);
  3512. }
  3513. // GetDlgItemText
  3514. UINT WINAPI GetDlgItemTextWrapW( HWND hDlg, // handle of dialog box
  3515. int nIDDlgItem, // identifier of control
  3516. LPTSTR lpString, // address of buffer for text
  3517. int nMaxCount ) // maximum size of string
  3518. {
  3519. int iRetValue = 0;
  3520. LPSTR lpStringA = NULL;
  3521. LPWSTR lpStringW = NULL;
  3522. int nCount =0;
  3523. VALIDATE_PROTOTYPE(GetDlgItemText);
  3524. *lpString = '\0';
  3525. if (g_bRunningOnNT)
  3526. return GetDlgItemTextW(hDlg, nIDDlgItem, lpString, nMaxCount);
  3527. nCount = nMaxCount * sizeof( WCHAR );
  3528. lpStringA = LocalAlloc( LMEM_ZEROINIT, nCount );
  3529. iRetValue = GetDlgItemTextA(hDlg, nIDDlgItem, lpStringA, nMaxCount);
  3530. if ( iRetValue == 0 ) {
  3531. LocalFreeAndNull( &lpStringA );
  3532. return iRetValue;
  3533. }
  3534. lpStringW = ConvertAtoW( lpStringA );
  3535. nCount = My_wcslen( lpStringW );
  3536. if ( nCount >= nMaxCount )
  3537. nCount = nMaxCount - 1;
  3538. CopyMemory( lpString, lpStringW, nCount * sizeof(WCHAR) );
  3539. lpString[nCount] = 0x0000;
  3540. iRetValue = nCount;
  3541. LocalFreeAndNull( &lpStringA );
  3542. LocalFreeAndNull( &lpStringW );
  3543. return iRetValue;
  3544. }
  3545. // SetMenuItemInfo
  3546. BOOL WINAPI SetMenuItemInfoWrapW( HMENU hMenu,
  3547. UINT uItem,
  3548. BOOL fByPosition,
  3549. LPMENUITEMINFO lpmii )
  3550. {
  3551. BOOL bRetValue;
  3552. MENUITEMINFOA miiA;
  3553. // VALIDATE_PROTOTYPE(SetMenuItemInfo);
  3554. if (g_bRunningOnNT)
  3555. return SetMenuItemInfoW(hMenu, uItem, fByPosition, lpmii);
  3556. // Bug 1723 WinSE: MFT_STRING is defined as 0. So lpmii->fType can never have MFT_STRING bit set
  3557. //if ( ((lpmii->fMask & MIIM_TYPE) == 0 ) || ((lpmii->fType & MFT_STRING) == 0 ) )
  3558. if ( ((lpmii->fMask & MIIM_TYPE) == 0 ) || lpmii->fType != MFT_STRING )
  3559. {
  3560. return SetMenuItemInfoA(hMenu, uItem, fByPosition, (MENUITEMINFOA *)lpmii );
  3561. }
  3562. CopyMemory(&miiA, lpmii, sizeof(MENUITEMINFOA) );
  3563. miiA.cbSize = sizeof(MENUITEMINFOA);
  3564. miiA.dwTypeData = ConvertWtoA( lpmii->dwTypeData );
  3565. miiA.cch = lstrlenA( miiA.dwTypeData );
  3566. bRetValue = SetMenuItemInfoA(hMenu, uItem, fByPosition, &miiA );
  3567. LocalFreeAndNull( &miiA.dwTypeData );
  3568. return bRetValue;
  3569. }
  3570. // PeekMessage
  3571. BOOL WINAPI PeekMessageWrapW( LPMSG lpMsg, // pointer to structure for message
  3572. HWND hWnd, // handle to window
  3573. UINT wMsgFilterMin, // first message
  3574. UINT wMsgFilterMax, // last message
  3575. UINT wRemoveMsg ) // removal flags
  3576. {
  3577. VALIDATE_PROTOTYPE(PeekMessage);
  3578. if (g_bRunningOnNT)
  3579. return PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
  3580. return PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
  3581. }
  3582. // run time loaded APIs in Comctl32.dll
  3583. extern LPIMAGELIST_LOADIMAGE_A gpfnImageList_LoadImageA;
  3584. extern LPPROPERTYSHEET_A gpfnPropertySheetA;
  3585. extern LP_CREATEPROPERTYSHEETPAGE_A gpfnCreatePropertySheetPageA;
  3586. extern LPIMAGELIST_LOADIMAGE_W gpfnImageList_LoadImageW;
  3587. extern LPPROPERTYSHEET_W gpfnPropertySheetW;
  3588. extern LP_CREATEPROPERTYSHEETPAGE_W gpfnCreatePropertySheetPageW;
  3589. HIMAGELIST WINAPI gpfnImageList_LoadImageWrapW(HINSTANCE hi,
  3590. LPCWSTR lpbmp,
  3591. int cx,
  3592. int cGrow,
  3593. COLORREF crMask,
  3594. UINT uType,
  3595. UINT uFlags)
  3596. {
  3597. WORD rID;
  3598. VALIDATE_PROTOTYPE( gpfnImageList_LoadImage );
  3599. if (g_bRunningOnNT)
  3600. return gpfnImageList_LoadImageW(hi, lpbmp, cx, cGrow, crMask, uType, uFlags) ;
  3601. // in our case, all the calling functions pass resources ID to lpbmp,
  3602. // so we don't want to convert this arguement.
  3603. rID = (WORD)lpbmp;
  3604. return gpfnImageList_LoadImageA(hi,(LPCSTR)((DWORD_PTR)(rID)), cx, cGrow, crMask, uType, uFlags) ;
  3605. }
  3606. INT_PTR WINAPI gpfnPropertySheetWrapW(LPCPROPSHEETHEADERW lppsh)
  3607. {
  3608. INT_PTR iRetValue;
  3609. PROPSHEETHEADERA pshA;
  3610. LPSTR pszCaption = NULL;
  3611. VALIDATE_PROTOTYPE( gpfnPropertySheet );
  3612. if (g_bRunningOnNT)
  3613. return gpfnPropertySheetW( lppsh );
  3614. CopyMemory( &pshA, lppsh, sizeof( PROPSHEETHEADERA ) );
  3615. pshA.dwSize = sizeof(PROPSHEETHEADERA);
  3616. pszCaption = ConvertWtoA( lppsh->pszCaption );
  3617. pshA.pszCaption = pszCaption;
  3618. iRetValue = gpfnPropertySheetA( &pshA );
  3619. LocalFreeAndNull( &pszCaption );
  3620. return iRetValue;
  3621. }
  3622. HPROPSHEETPAGE WINAPI gpfnCreatePropertySheetPageWrapW(LPCPROPSHEETPAGEW lppsp)
  3623. {
  3624. PROPSHEETPAGEA pspA;
  3625. HPROPSHEETPAGE hRetValue;
  3626. LPSTR lpTitle = NULL;
  3627. VALIDATE_PROTOTYPE( gpfnCreatePropertySheetPage );
  3628. if (g_bRunningOnNT)
  3629. return gpfnCreatePropertySheetPageW( lppsp );
  3630. CopyMemory( &pspA, lppsp, sizeof(PROPSHEETPAGEA) );
  3631. pspA.dwSize = sizeof( PROPSHEETPAGEA );
  3632. lpTitle = ConvertWtoA( lppsp->pszTitle );
  3633. pspA.pszTitle = lpTitle;
  3634. hRetValue = gpfnCreatePropertySheetPageA( &pspA );
  3635. LocalFreeAndNull( &lpTitle );
  3636. return hRetValue;
  3637. }
  3638. // APIs in Commdlg32.dll
  3639. extern BOOL (*pfnGetOpenFileNameA)(LPOPENFILENAMEA pof);
  3640. extern BOOL (*pfnGetOpenFileNameW)(LPOPENFILENAMEW pof);
  3641. BOOL WINAPI pfnGetOpenFileNameWrapW(LPOPENFILENAMEW lpOf)
  3642. {
  3643. BOOL bRetValue;
  3644. OPENFILENAMEA ofA;
  3645. LPSTR lpstrFilterA = NULL;
  3646. LPSTR lpstrFilterA_T = NULL,lpstrFilterAA=NULL ;
  3647. LPWSTR lpstrFilterW = NULL;
  3648. CHAR lpstrFileA[MAX_PATH+1] ="";
  3649. LPSTR lpstrFileTitleA = NULL;
  3650. LPSTR lpstrTitleA = NULL;
  3651. LPSTR lpstrDefExtA= NULL;
  3652. LPSTR lpTemplateNameA = NULL;
  3653. LPSTR lpstrInitialDirA = NULL;
  3654. LPWSTR lpstrFileW = NULL;
  3655. DWORD dwLen;
  3656. VALIDATE_PROTOTYPE(pfnGetOpenFileName);
  3657. if (g_bRunningOnNT)
  3658. return pfnGetOpenFileNameW( lpOf );
  3659. CopyMemory( &ofA, lpOf, sizeof( OPENFILENAMEA ) );
  3660. ofA.lStructSize = sizeof( OPENFILENAMEA );
  3661. if ( lpOf->lpTemplateName ) {
  3662. lpTemplateNameA = ConvertWtoA( lpOf->lpTemplateName );
  3663. ofA.lpTemplateName = lpTemplateNameA;
  3664. }
  3665. else
  3666. ofA.lpTemplateName = NULL;
  3667. if ( lpOf->lpstrDefExt ) {
  3668. lpstrDefExtA = ConvertWtoA( lpOf->lpstrDefExt );
  3669. ofA.lpstrDefExt = lpstrDefExtA;
  3670. }
  3671. else
  3672. ofA.lpstrDefExt = NULL;
  3673. if ( lpOf->lpstrTitle ) {
  3674. lpstrTitleA = ConvertWtoA( lpOf->lpstrTitle );
  3675. ofA.lpstrTitle = lpstrTitleA;
  3676. }
  3677. else
  3678. ofA.lpstrTitle = NULL;
  3679. if ( lpOf->lpstrFileTitle ) {
  3680. lpstrFileTitleA = ConvertWtoA( lpOf->lpstrFileTitle );
  3681. ofA.lpstrFileTitle = lpstrFileTitleA;
  3682. }
  3683. else
  3684. ofA.lpstrFileTitle = NULL;
  3685. if ( lpOf->lpstrInitialDir ) {
  3686. lpstrInitialDirA = ConvertWtoA( lpOf->lpstrInitialDir );
  3687. ofA.lpstrInitialDir = lpstrInitialDirA;
  3688. }
  3689. else
  3690. ofA.lpstrInitialDir = NULL;
  3691. ofA.lpstrCustomFilter = NULL;
  3692. // get the total length of lpOf->lpstrFilter
  3693. dwLen = 0;
  3694. lpstrFilterW = (LPWSTR)(lpOf->lpstrFilter);
  3695. while ( *lpstrFilterW != TEXT('\0') ) {
  3696. dwLen += lstrlenW(lpstrFilterW) + 1;
  3697. lpstrFilterW += lstrlenW(lpstrFilterW) + 1;
  3698. }
  3699. dwLen += 1; // for the last null terminator
  3700. lpstrFilterW = (LPWSTR)( lpOf->lpstrFilter );
  3701. lpstrFilterA = LocalAlloc( LMEM_ZEROINIT, dwLen * sizeof(WCHAR) );
  3702. lpstrFilterA_T = lpstrFilterA;
  3703. while ( *lpstrFilterW != TEXT('\0') ) {
  3704. lpstrFilterAA = ConvertWtoA(lpstrFilterW );
  3705. lpstrFilterW += lstrlenW(lpstrFilterW) + 1;
  3706. strcpy(lpstrFilterA_T, lpstrFilterAA );
  3707. LocalFreeAndNull( &lpstrFilterAA );
  3708. lpstrFilterA_T += lstrlenA( lpstrFilterA_T ) + 1;
  3709. }
  3710. lpstrFilterA_T[lstrlenA(lpstrFilterA_T)+1] = '\0';
  3711. ofA.lpstrFilter = lpstrFilterA;
  3712. ofA.lpstrFile = lpstrFileA;
  3713. ofA.nMaxFile = MAX_PATH + 1;
  3714. bRetValue = pfnGetOpenFileNameA( &ofA );
  3715. LocalFreeAndNull( &lpTemplateNameA );
  3716. LocalFreeAndNull( &lpstrDefExtA );
  3717. LocalFreeAndNull( &lpstrTitleA );
  3718. LocalFreeAndNull( &lpstrFileTitleA );
  3719. LocalFreeAndNull( &lpstrInitialDirA );
  3720. LocalFreeAndNull( &lpstrFilterA );
  3721. if ( bRetValue != FALSE ) {
  3722. lpstrFileW = ConvertAtoW( lpstrFileA );
  3723. CopyMemory( lpOf->lpstrFile, lpstrFileW, (lstrlenW(lpstrFileW)+1) * sizeof( WCHAR) );
  3724. LocalFreeAndNull( &lpstrFileW );
  3725. }
  3726. return bRetValue;
  3727. }
  3728. extern BOOL (*pfnGetSaveFileNameA)(LPOPENFILENAMEA pof);
  3729. extern BOOL (*pfnGetSaveFileNameW)(LPOPENFILENAMEW pof);
  3730. BOOL WINAPI pfnGetSaveFileNameWrapW(LPOPENFILENAMEW lpOf)
  3731. {
  3732. BOOL bRetValue;
  3733. OPENFILENAMEA ofA;
  3734. LPSTR lpstrFilterA = NULL;
  3735. LPSTR lpstrFilterA_T = NULL,lpstrFilterAA=NULL ;
  3736. LPWSTR lpstrFilterW = NULL;
  3737. CHAR lpstrFileA[MAX_PATH+1] ="";
  3738. LPSTR lpFileA = NULL;
  3739. LPSTR lpstrFileTitleA = NULL;
  3740. LPSTR lpstrTitleA = NULL;
  3741. LPSTR lpstrDefExtA= NULL;
  3742. LPSTR lpTemplateNameA = NULL;
  3743. LPSTR lpstrInitialDirA = NULL;
  3744. LPWSTR lpstrFileW = NULL;
  3745. DWORD dwLen;
  3746. VALIDATE_PROTOTYPE(pfnGetOpenFileName);
  3747. if (g_bRunningOnNT)
  3748. return pfnGetSaveFileNameW( lpOf );
  3749. CopyMemory( &ofA, lpOf, sizeof( OPENFILENAMEA ) );
  3750. ofA.lStructSize = sizeof( OPENFILENAMEA );
  3751. if ( lpOf->lpTemplateName ) {
  3752. lpTemplateNameA = ConvertWtoA( lpOf->lpTemplateName );
  3753. ofA.lpTemplateName = lpTemplateNameA;
  3754. }
  3755. else
  3756. ofA.lpTemplateName = NULL;
  3757. if ( lpOf->lpstrDefExt ) {
  3758. lpstrDefExtA = ConvertWtoA( lpOf->lpstrDefExt );
  3759. ofA.lpstrDefExt = lpstrDefExtA;
  3760. }
  3761. else
  3762. ofA.lpstrDefExt = NULL;
  3763. if ( lpOf->lpstrTitle ) {
  3764. lpstrTitleA = ConvertWtoA( lpOf->lpstrTitle );
  3765. ofA.lpstrTitle = lpstrTitleA;
  3766. }
  3767. else
  3768. ofA.lpstrTitle = NULL;
  3769. if ( lpOf->lpstrFileTitle ) {
  3770. lpstrFileTitleA = ConvertWtoA( lpOf->lpstrFileTitle );
  3771. ofA.lpstrFileTitle = lpstrFileTitleA;
  3772. }
  3773. else
  3774. ofA.lpstrFileTitle = NULL;
  3775. if ( lpOf->lpstrFile ) {
  3776. lpFileA = ConvertWtoA( lpOf->lpstrFile );
  3777. lstrcpyA(lpstrFileA, lpFileA);
  3778. ofA.lpstrFile = lpstrFileA;
  3779. ofA.nMaxFile = MAX_PATH + 1;
  3780. }
  3781. else
  3782. ofA.lpstrFile = NULL;
  3783. if ( lpOf->lpstrInitialDir ) {
  3784. lpstrInitialDirA = ConvertWtoA( lpOf->lpstrInitialDir );
  3785. ofA.lpstrInitialDir = lpstrInitialDirA;
  3786. }
  3787. else
  3788. ofA.lpstrInitialDir = NULL;
  3789. ofA.lpstrCustomFilter = NULL;
  3790. // get the total length of lpOf->lpstrFilter
  3791. dwLen = 0;
  3792. lpstrFilterW = (LPWSTR)(lpOf->lpstrFilter);
  3793. while ( *lpstrFilterW != TEXT('\0') ) {
  3794. dwLen += lstrlenW(lpstrFilterW) + 1;
  3795. lpstrFilterW += lstrlenW(lpstrFilterW) + 1;
  3796. }
  3797. dwLen += 1; // for the last null terminator
  3798. lpstrFilterW = (LPWSTR)( lpOf->lpstrFilter );
  3799. lpstrFilterA = LocalAlloc( LMEM_ZEROINIT, dwLen * sizeof(WCHAR) );
  3800. lpstrFilterA_T = lpstrFilterA;
  3801. while ( *lpstrFilterW != TEXT('\0') ) {
  3802. lpstrFilterAA = ConvertWtoA(lpstrFilterW );
  3803. lpstrFilterW += lstrlenW(lpstrFilterW) + 1;
  3804. strcpy(lpstrFilterA_T, lpstrFilterAA );
  3805. LocalFreeAndNull( &lpstrFilterAA );
  3806. lpstrFilterA_T += lstrlenA( lpstrFilterA_T ) + 1;
  3807. }
  3808. lpstrFilterA_T[lstrlenA(lpstrFilterA_T)+1] = '\0';
  3809. ofA.lpstrFilter = lpstrFilterA;
  3810. bRetValue = pfnGetSaveFileNameA( &ofA );
  3811. LocalFreeAndNull( &lpTemplateNameA );
  3812. LocalFreeAndNull( &lpstrDefExtA );
  3813. LocalFreeAndNull( &lpstrTitleA );
  3814. LocalFreeAndNull( &lpstrFileTitleA );
  3815. LocalFreeAndNull( &lpstrInitialDirA );
  3816. LocalFreeAndNull( &lpstrFilterA );
  3817. LocalFreeAndNull( &lpFileA );
  3818. if ( bRetValue != FALSE ) {
  3819. lpstrFileW = ConvertAtoW( lpstrFileA );
  3820. CopyMemory( lpOf->lpstrFile, lpstrFileW, (lstrlenW(lpstrFileW)+1) * sizeof( WCHAR) );
  3821. LocalFreeAndNull( &lpstrFileW );
  3822. }
  3823. return bRetValue;
  3824. }
  3825. extern BOOL (*pfnPrintDlgA)(LPPRINTDLGA lppd);
  3826. extern BOOL (*pfnPrintDlgW)(LPPRINTDLGW lppd);
  3827. BOOL WINAPI pfnPrintDlgWrapW(LPPRINTDLGW lppd)
  3828. {
  3829. BOOL bRetValue;
  3830. PRINTDLGA pdA;
  3831. VALIDATE_PROTOTYPE(pfnPrintDlg);
  3832. if (g_bRunningOnNT)
  3833. return pfnPrintDlgW( lppd );
  3834. CopyMemory( &pdA, lppd, sizeof( PRINTDLGA ) );
  3835. pdA.lStructSize = sizeof( PRINTDLGA );
  3836. // Only lpPrintTemplateName and lpSetupTemplateName has STR type,
  3837. // but in our case, only IDD of Resources are passed to these two parameters.
  3838. // so don't do conversion.
  3839. pdA.lpPrintTemplateName = (LPCSTR)(lppd->lpPrintTemplateName);
  3840. pdA.lpSetupTemplateName = (LPCSTR)(lppd->lpSetupTemplateName);
  3841. bRetValue = pfnPrintDlgA ( &pdA );
  3842. lppd->hDC = pdA.hDC;
  3843. lppd->Flags = pdA.Flags;
  3844. lppd->nFromPage = pdA.nFromPage;
  3845. lppd->nToPage = pdA.nToPage;
  3846. lppd->nMinPage = pdA.nMinPage;
  3847. lppd->nMaxPage = pdA.nMaxPage;
  3848. lppd->nCopies = pdA.nCopies;
  3849. return bRetValue;
  3850. }
  3851. extern HRESULT (*pfnPrintDlgExA)(LPPRINTDLGEXA lppdex);
  3852. extern HRESULT (*pfnPrintDlgExW)(LPPRINTDLGEXW lppdex);
  3853. HRESULT WINAPI pfnPrintDlgExWrapW(LPPRINTDLGEXW lppdex)
  3854. {
  3855. HRESULT hRetValue;
  3856. PRINTDLGEXA pdexA;
  3857. VALIDATE_PROTOTYPE(pfnPrintDlgEx);
  3858. if (g_bRunningOnNT)
  3859. return pfnPrintDlgExW( lppdex );
  3860. CopyMemory( &pdexA, lppdex, sizeof( PRINTDLGEXA ) );
  3861. pdexA.lStructSize = sizeof( PRINTDLGEXA );
  3862. // Only lpPrintTemplateName and lpSetupTemplateName has STR type,
  3863. // but in our case, only IDD of Resources are passed to these two parameters.
  3864. // so don't do conversion.
  3865. hRetValue = pfnPrintDlgExA( &pdexA );
  3866. lppdex->dwResultAction = pdexA.dwResultAction;
  3867. lppdex->hDC = pdexA.hDC;
  3868. lppdex->lpPageRanges = pdexA.lpPageRanges;
  3869. lppdex->nCopies = pdexA.nCopies;
  3870. lppdex->nMaxPage = pdexA.nMaxPage;
  3871. lppdex->nMaxPageRanges = pdexA.nMaxPageRanges;
  3872. lppdex->nMinPage = pdexA.nMinPage;
  3873. lppdex->nPageRanges = pdexA.nPageRanges;
  3874. lppdex->nPropertyPages = pdexA.nPropertyPages;
  3875. lppdex->nStartPage = pdexA.nStartPage;
  3876. return hRetValue;
  3877. }
  3878. // GetWindowTextLength
  3879. int WINAPI GetWindowTextLengthWrapW( HWND hWnd)
  3880. {
  3881. VALIDATE_PROTOTYPE(GetWindowTextLength);
  3882. if (g_bRunningOnNT)
  3883. return GetWindowTextLengthW(hWnd);
  3884. else
  3885. return GetWindowTextLengthA(hWnd);
  3886. }
  3887. // GetFileVersionInfoSize
  3888. DWORD GetFileVersionInfoSizeWrapW( LPTSTR lptstrFilename, LPDWORD lpdwHandle )
  3889. {
  3890. LPSTR lpFileA = NULL;
  3891. DWORD dwRet = 0;
  3892. VALIDATE_PROTOTYPE(GetFileVersionInfoSize);
  3893. if (g_bRunningOnNT)
  3894. return GetFileVersionInfoSizeW(lptstrFilename, lpdwHandle);
  3895. lpFileA = ConvertWtoA(lptstrFilename);
  3896. dwRet = GetFileVersionInfoSizeA(lpFileA, lpdwHandle);
  3897. LocalFreeAndNull(&lpFileA);
  3898. return dwRet;
  3899. }
  3900. // GetFileVersionInfo
  3901. BOOL GetFileVersionInfoWrapW( LPTSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData)
  3902. {
  3903. LPSTR lpFileA = NULL;
  3904. BOOL bRet = FALSE;
  3905. VALIDATE_PROTOTYPE(GetFileVersionInfo);
  3906. if (g_bRunningOnNT)
  3907. return GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData);
  3908. // Note this is assuming that the dwLen and dwHandle are the same as those returned by
  3909. // GetFileVersionInfoSize ..
  3910. lpFileA = ConvertWtoA(lptstrFilename);
  3911. bRet = GetFileVersionInfoA(lpFileA, dwHandle, dwLen, lpData);
  3912. LocalFreeAndNull(&lpFileA);
  3913. return bRet;
  3914. }
  3915. // VerQueryValue
  3916. // This one assumes that pBlock etc are all returned by GetFileVersionInfo and GetFileVersionInfoSize etc
  3917. BOOL VerQueryValueWrapW( const LPVOID pBlock, LPTSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
  3918. {
  3919. LPSTR lpBlockA = NULL;
  3920. BOOL bRet = FALSE;
  3921. VALIDATE_PROTOTYPE(GetFileVersionInfo);
  3922. if (g_bRunningOnNT)
  3923. return VerQueryValueW(pBlock, lpSubBlock, lplpBuffer, puLen);
  3924. // Note this is assuming that the dwLen and dwHandle are the same as those returned by
  3925. // GetFileVersionInfoSize ..
  3926. lpBlockA = ConvertWtoA(lpSubBlock);
  3927. bRet = VerQueryValueA(pBlock, lpBlockA, lplpBuffer, puLen);
  3928. LocalFreeAndNull(&lpBlockA);
  3929. return bRet;
  3930. }