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.

4769 lines
157 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cmutoa.cpp
  4. //
  5. // Module: CMUTOA.DLL
  6. //
  7. // Synopsis: This dll is a Unicode to Ansi wrapper that exports AU functions
  8. // that have the function header of the W version of a windows API
  9. // but internally do all the conversions necessary so that the Ansi
  10. // version of the API (A version) can be called. This dll was implemented
  11. // so that a Unicode CM could still run on win9x. The idea was borrowed
  12. // from F. Avery Bishop's April 1999 MSJ article "Design a Single Unicode
  13. // App that Runs on Both Windows 98 and Windows 2000"
  14. //
  15. // Copyright (c) 1999 Microsoft Corporation
  16. //
  17. // Author: quintinb Created 04/25/99
  18. //
  19. //+----------------------------------------------------------------------------
  20. #include <windows.h>
  21. #include <tchar.h>
  22. #include <stdio.h>
  23. #include <shlobj.h>
  24. #include <ras.h>
  25. #include <raserror.h>
  26. #include <shellapi.h>
  27. #include "cmutoa.h"
  28. #include "cmdebug.h"
  29. #include "cm_def.h"
  30. #include "cmutil.h"
  31. #include "cmras.h"
  32. #include "raslink.h"
  33. // raslink text constants
  34. #define _CMUTOA_MODULE
  35. #include "raslink.cpp"
  36. //
  37. // Globals
  38. //
  39. DWORD g_dwTlsIndex;
  40. //
  41. // Function Headers
  42. //
  43. LRESULT WINAPI SendMessageAU(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  44. int WINAPI wvsprintfAU(OUT LPWSTR pszwDest, IN LPCWSTR pszwFmt, IN va_list arglist);
  45. int WINAPI lstrlenAU(IN LPCWSTR lpString);
  46. //+----------------------------------------------------------------------------
  47. //
  48. // Function: DllMain
  49. //
  50. // Synopsis: Main Entry point for the DLL, notice that we use thread local
  51. // storage and initialize it here.
  52. //
  53. // Arguments: HANDLE hDll - instance handle to the dll
  54. // DWORD dwReason - reason the function was called
  55. // LPVOID lpReserved -
  56. //
  57. // Returns: BOOL - TRUE on success
  58. //
  59. // History: quintinb Created 6/24/99
  60. //
  61. //+----------------------------------------------------------------------------
  62. BOOL APIENTRY DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
  63. {
  64. if (dwReason == DLL_PROCESS_ATTACH)
  65. {
  66. CMTRACE(TEXT("====================================================="));
  67. CMTRACE1(TEXT(" CMUTOA.DLL - LOADING - Process ID is 0x%x "), GetCurrentProcessId());
  68. CMTRACE(TEXT("====================================================="));
  69. g_dwTlsIndex = TlsAlloc();
  70. if (g_dwTlsIndex == TLS_OUT_OF_INDEXES)
  71. {
  72. return FALSE;
  73. }
  74. DisableThreadLibraryCalls((HMODULE) hDll);
  75. }
  76. else if (dwReason == DLL_PROCESS_DETACH)
  77. {
  78. CMTRACE(TEXT("====================================================="));
  79. CMTRACE1(TEXT(" CMUTOA.DLL - UNLOADING - Process ID is 0x%x "), GetCurrentProcessId());
  80. CMTRACE(TEXT("====================================================="));
  81. //
  82. // free the tls index
  83. //
  84. if (g_dwTlsIndex != TLS_OUT_OF_INDEXES)
  85. {
  86. TlsFree(g_dwTlsIndex);
  87. }
  88. }
  89. return TRUE;
  90. }
  91. //+----------------------------------------------------------------------------
  92. //
  93. // Function: CharNextAU
  94. //
  95. // Synopsis: Unicode to Ansi wrapper for the win32 CharNext API.
  96. //
  97. // Arguments: LPCWSTR lpsz - The string to return the next character of
  98. //
  99. // Returns: LPWSTR -- the Next character in the string, unless the current
  100. // char is a NULL terminator and then the input param
  101. // is returned.
  102. //
  103. // History: quintinb Created 6/24/99
  104. //
  105. //+----------------------------------------------------------------------------
  106. LPWSTR WINAPI CharNextAU(IN LPCWSTR lpsz)
  107. {
  108. LPWSTR pszReturn = (LPWSTR)lpsz;
  109. if (lpsz && (L'\0' != *lpsz))
  110. {
  111. pszReturn++; // this is what _wcsinc does
  112. }
  113. return pszReturn;
  114. }
  115. //+----------------------------------------------------------------------------
  116. //
  117. // Function: CharPrevAU
  118. //
  119. // Synopsis: Unicode to Ansi wrapper for the win32 CharPrev API.
  120. //
  121. // Arguments: LPCWSTR lpszStart - start of the string
  122. // LPCWSTR lpsz - The current position in the string for which we
  123. // want the previous char of
  124. //
  125. //
  126. // Returns: LPWSTR -- the Previous character in the string, unless the current
  127. // char is less than or equal to the Start of the string or
  128. // a NULL string is passed to the function, then lpszStart
  129. // is returned.
  130. //
  131. // History: quintinb Created 6/24/99
  132. //
  133. //+----------------------------------------------------------------------------
  134. LPWSTR WINAPI CharPrevAU(IN LPCWSTR lpszStart, IN LPCWSTR lpszCurrent)
  135. {
  136. LPWSTR pszReturn = (LPWSTR)lpszCurrent;
  137. if (lpszStart && lpszCurrent && (lpszCurrent > lpszStart))
  138. {
  139. pszReturn--; // this is what _wcsdec does
  140. }
  141. else
  142. {
  143. CMASSERTMSG(FALSE, TEXT("NULL String passed to CharPrevAU"));
  144. pszReturn = (LPWSTR)lpszStart;
  145. }
  146. return pszReturn;
  147. }
  148. typedef WINUSERAPI LPSTR (WINAPI *CharLowerOrUpperA)(LPSTR);
  149. //+----------------------------------------------------------------------------
  150. //
  151. // Function: LowerOrUpperHelper
  152. //
  153. // Synopsis: Helper function called by either CharLowerAU or CharUpperAU which have
  154. // basically the same functionality except for the calling of CharLowerA or
  155. // CharUpperA, respectively.
  156. //
  157. // Arguments: LPWSTR lpsz -- either a pointer to a string to convert to its
  158. // lower/upper character version or a single character stored
  159. // in the low word of the pointer to find the lowercase/uppercase
  160. // character for.
  161. //
  162. // Returns: LPWSTR -- lower/upper case version of the string passed in (same as lpsz
  163. // because it is converted in place) or lower/upper case version
  164. // of the character stored in the Low word of lpsz.
  165. //
  166. // History: quintinb Created 01/03/2000
  167. //
  168. //+----------------------------------------------------------------------------
  169. LPWSTR WINAPI LowerOrUpperHelper(IN OUT LPWSTR lpsz, CharLowerOrUpperA pfnLowerOrUpper)
  170. {
  171. LPWSTR pszwReturn = lpsz;
  172. LPSTR pszAnsiTmp = NULL;
  173. if (lpsz)
  174. {
  175. //
  176. // CharLower/CharUpper can be used in two ways. There is a Character mode where the Loword of the
  177. // pointer passed in actually stores the numeric value of the character to get the lowercase/uppercase
  178. // value of. There is also the traditional use, where the whole string is passed in. Thus
  179. // we have to detect which mode we are in and handle it accordingly.
  180. //
  181. if (0 == HIWORD(lpsz))
  182. {
  183. //
  184. // Character Mode
  185. //
  186. CHAR szAnsiTmp[2];
  187. WCHAR szwWideTmp[2];
  188. szwWideTmp[0] = (WCHAR)LOWORD(lpsz);
  189. szwWideTmp[1] = L'\0';
  190. int iChars = WzToSz(szwWideTmp, szAnsiTmp, 2);
  191. if (iChars && (iChars <= 2))
  192. {
  193. pfnLowerOrUpper(szAnsiTmp);
  194. iChars = SzToWz(szAnsiTmp, szwWideTmp, 2);
  195. if (iChars && (iChars <= 2))
  196. {
  197. lpsz = (LPWSTR) ((WORD)szwWideTmp[0]);
  198. pszwReturn = lpsz;
  199. }
  200. else
  201. {
  202. CMASSERTMSG(FALSE, TEXT("LowerOrUpperHelper-- Failed to convert szAnsiTmp back to szwWideTmp."));
  203. }
  204. }
  205. else
  206. {
  207. CMASSERTMSG(FALSE, TEXT("LowerOrUpperHelper -- Failed to convert szwWideTmp to szAnsiTmp."));
  208. }
  209. }
  210. else
  211. {
  212. //
  213. // String Mode
  214. //
  215. pszAnsiTmp = WzToSzWithAlloc(lpsz);
  216. if (!pszAnsiTmp)
  217. {
  218. goto exit;
  219. }
  220. pfnLowerOrUpper(pszAnsiTmp);
  221. //
  222. // Convert back into UNICODE chars in lpsz
  223. //
  224. int iCharCount = (lstrlenAU(lpsz) + 1); // include NULL
  225. int iChars = SzToWz(pszAnsiTmp, lpsz, iCharCount);
  226. if (!iChars || (iChars > iCharCount))
  227. {
  228. CMASSERTMSG(FALSE, TEXT("LowerOrUpperHelper -- Failed to convert pszAnsiTmp to lpsz."));
  229. goto exit;
  230. }
  231. }
  232. }
  233. exit:
  234. CmFree(pszAnsiTmp);
  235. return pszwReturn;
  236. }
  237. //+----------------------------------------------------------------------------
  238. //
  239. // Function: CharLowerAU
  240. //
  241. // Synopsis: Unicode to Ansi wrapper for the win32 CharLower API. Notice that
  242. // we support both the string input parameter and the single character
  243. // input method.
  244. //
  245. // Arguments: LPWSTR lpsz -- either a pointer to a string to convert to its
  246. // lower character version or a single character stored
  247. // in the low word of the pointer to find the lowercase
  248. // character for.
  249. //
  250. // Returns: LPWSTR -- lower case version of the string passed in (same as lpsz
  251. // because it is converted in place) or lower case version
  252. // of the character stored in the Low word of lpsz.
  253. //
  254. // History: quintinb Created 6/24/99
  255. //
  256. //+----------------------------------------------------------------------------
  257. LPWSTR WINAPI CharLowerAU(IN OUT LPWSTR lpsz)
  258. {
  259. return LowerOrUpperHelper(lpsz, CharLowerA);
  260. }
  261. //+----------------------------------------------------------------------------
  262. //
  263. // Function: CharUpperAU
  264. //
  265. // Synopsis: Unicode to Ansi wrapper for the win32 CharUpper API. Notice that
  266. // we support both the string input parameter and the single character
  267. // input method.
  268. //
  269. // Arguments: LPWSTR lpsz -- either a pointer to a string to convert to its
  270. // upper character version or a single character stored
  271. // in the low word of the pointer to find the uppercase
  272. // character for.
  273. //
  274. // Returns: LPWSTR -- upper case version of the string passed in (same as lpsz
  275. // because it is converted in place) or upper case version
  276. // of the character stored in the Low word of lpsz.
  277. //
  278. // History: quintinb Created 6/24/99
  279. //
  280. //+----------------------------------------------------------------------------
  281. LPWSTR WINAPI CharUpperAU(IN OUT LPWSTR lpsz)
  282. {
  283. return LowerOrUpperHelper(lpsz, CharUpperA);
  284. }
  285. //+----------------------------------------------------------------------------
  286. //
  287. // Function: CompareStringAU
  288. //
  289. // Synopsis: Unicode to Ansi wrapper for the win32 CompareString API. This only
  290. // supports the syntax where both cchCount values are -1, i.e. where
  291. // the entire string is being compared.
  292. //
  293. // Arguments: See the win32 API definition
  294. //
  295. // Returns: See the win32 API definition
  296. //
  297. // History: SumitC Created 20-Aug-2001
  298. //
  299. //+----------------------------------------------------------------------------
  300. int WINAPI CompareStringAU(
  301. IN LCID Locale,
  302. IN DWORD dwCmpFlags,
  303. IN LPCWSTR lpString1,
  304. IN int cchCount1,
  305. IN LPCWSTR lpString2,
  306. IN int cchCount2)
  307. {
  308. MYDBGASSERT(cchCount1 == -1);
  309. MYDBGASSERT(cchCount2 == -1);
  310. if ((-1 != cchCount1) || (-1 != cchCount2))
  311. {
  312. return 0;
  313. }
  314. int iReturn = 0;
  315. LPSTR pszAnsiString1 = NULL;
  316. LPSTR pszAnsiString2 = NULL;
  317. if (lpString1)
  318. {
  319. pszAnsiString1 = WzToSzWithAlloc(lpString1);
  320. }
  321. if (lpString2)
  322. {
  323. pszAnsiString2 = WzToSzWithAlloc(lpString2);
  324. }
  325. if (lpString1 && lpString2)
  326. {
  327. iReturn = CompareStringA(Locale, dwCmpFlags, pszAnsiString1, -1, pszAnsiString2, -1);
  328. }
  329. CmFree(pszAnsiString1);
  330. CmFree(pszAnsiString2);
  331. return iReturn;
  332. }
  333. //+----------------------------------------------------------------------------
  334. //
  335. // Function: CreateDialogParamAU
  336. //
  337. // Synopsis: Unicode to Ansi wrapper for the win32 CreateDialogParam API. Notice that
  338. // we support both a full string for the lpTemplateName param or only
  339. // a int from MAKEINTRESOURCE (a resource identifier stored in the string
  340. // pointer var).
  341. //
  342. // Arguments: See the win32 API definition
  343. //
  344. // Returns: See the win32 API definition
  345. //
  346. // History: quintinb Created 6/24/99
  347. //
  348. //+----------------------------------------------------------------------------
  349. HWND WINAPI CreateDialogParamAU(IN HINSTANCE hInstance, IN LPCWSTR lpTemplateName, IN HWND hWndParent,
  350. IN DLGPROC lpDialogFunc, IN LPARAM dwInitParam)
  351. {
  352. HWND hWndReturn = NULL;
  353. CHAR szAnsiTemplateName[MAX_PATH+1];
  354. LPSTR pszAnsiTemplateName;
  355. MYDBGASSERT(hInstance);
  356. MYDBGASSERT(lpTemplateName);
  357. MYDBGASSERT(lpDialogFunc);
  358. if (hInstance && lpTemplateName && lpDialogFunc)
  359. {
  360. if (HIWORD(lpTemplateName))
  361. {
  362. //
  363. // We have a full template name that we must convert
  364. //
  365. pszAnsiTemplateName = szAnsiTemplateName;
  366. int iChars = WzToSz(lpTemplateName, pszAnsiTemplateName, MAX_PATH);
  367. if (!iChars || (MAX_PATH < iChars))
  368. {
  369. goto exit;
  370. }
  371. }
  372. else
  373. {
  374. //
  375. // All we need is a cast
  376. //
  377. pszAnsiTemplateName = (LPSTR)lpTemplateName;
  378. }
  379. hWndReturn = CreateDialogParamA(hInstance, pszAnsiTemplateName, hWndParent,
  380. lpDialogFunc, dwInitParam);
  381. }
  382. exit:
  383. return hWndReturn;
  384. }
  385. //+----------------------------------------------------------------------------
  386. //
  387. // Function: CreateDirectoryAU
  388. //
  389. // Synopsis: Unicode to Ansi wrapper for the win32 CreateDirectory API.
  390. //
  391. // Arguments: See the win32 API definition
  392. //
  393. // Returns: See the win32 API definition
  394. //
  395. // History: quintinb Created 6/24/99
  396. //
  397. //+----------------------------------------------------------------------------
  398. BOOL WINAPI CreateDirectoryAU(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
  399. {
  400. BOOL bRet = FALSE;
  401. LPSTR pszPathName = WzToSzWithAlloc(lpPathName);
  402. if (pszPathName)
  403. {
  404. bRet = CreateDirectoryA(pszPathName, lpSecurityAttributes);
  405. CmFree(pszPathName);
  406. }
  407. return bRet;
  408. }
  409. //+----------------------------------------------------------------------------
  410. //
  411. // Function: CreateEventAU
  412. //
  413. // Synopsis: Unicode to Ansi wrapper for the win32 CreateEvent API.
  414. //
  415. // Arguments: See the win32 API definition
  416. //
  417. // Returns: See the win32 API definition
  418. //
  419. // History: quintinb Created 6/24/99
  420. //
  421. //+----------------------------------------------------------------------------
  422. HANDLE WINAPI CreateEventAU(IN LPSECURITY_ATTRIBUTES lpEventAttributes, IN BOOL bManualReset,
  423. IN BOOL bInitialState, IN LPCWSTR lpName)
  424. {
  425. CHAR szAnsiName[MAX_PATH+1]; // lpName is limited to MAX_PATH chars according to the docs.
  426. HANDLE hReturn = NULL;
  427. LPSTR pszAnsiName = NULL;
  428. if (lpName) // lpName could be NULL
  429. {
  430. pszAnsiName = szAnsiName;
  431. int uNumChars = WzToSz(lpName, pszAnsiName, MAX_PATH);
  432. if (!uNumChars || (MAX_PATH < uNumChars))
  433. {
  434. CMTRACE(TEXT("CreateEventAU -- Unable to convert lpName"));
  435. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  436. goto exit;
  437. }
  438. }
  439. hReturn = CreateEventA(lpEventAttributes, bManualReset, bInitialState, pszAnsiName);
  440. exit:
  441. return hReturn;
  442. }
  443. //+----------------------------------------------------------------------------
  444. //
  445. // Function: CreateFileMappingAU
  446. //
  447. // Synopsis: Unicode to Ansi wrapper for the win32 CreateFileMapping API.
  448. //
  449. // Arguments: See the win32 API definition
  450. //
  451. // Returns: See the win32 API definition
  452. //
  453. // History: quintinb Created 6/24/99
  454. //
  455. //+----------------------------------------------------------------------------
  456. HANDLE WINAPI CreateFileMappingAU(IN HANDLE hFile, IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
  457. IN DWORD flProtect, IN DWORD dwMaximumSizeHigh,
  458. IN DWORD dwMaximumSizeLow, IN LPCWSTR lpName)
  459. {
  460. HANDLE hHandle = NULL;
  461. LPSTR pszName = NULL;
  462. if (lpName) // could be NULL
  463. {
  464. pszName = WzToSzWithAlloc(lpName);
  465. }
  466. if (pszName || (NULL == lpName))
  467. {
  468. hHandle = CreateFileMappingA(hFile, lpFileMappingAttributes, flProtect, dwMaximumSizeHigh,
  469. dwMaximumSizeLow, pszName);
  470. CmFree(pszName);
  471. }
  472. return hHandle;
  473. }
  474. //+----------------------------------------------------------------------------
  475. //
  476. // Function: CreateFileAU
  477. //
  478. // Synopsis: Unicode to Ansi wrapper for the win32 CreateFile API.
  479. //
  480. // Arguments: See the win32 API definition
  481. //
  482. // Returns: See the win32 API definition
  483. //
  484. // History: quintinb Created 6/24/99
  485. //
  486. //+----------------------------------------------------------------------------
  487. HANDLE WINAPI CreateFileAU(IN LPCWSTR lpFileName, IN DWORD dwDesiredAccess, IN DWORD dwShareMode,
  488. IN LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  489. IN DWORD dwCreationDisposition, IN DWORD dwFlagsAndAttributes,
  490. IN HANDLE hTemplateFile)
  491. {
  492. HANDLE hHandle = INVALID_HANDLE_VALUE;
  493. LPSTR pszFileName = WzToSzWithAlloc(lpFileName);
  494. if (pszFileName)
  495. {
  496. hHandle = CreateFileA(pszFileName, dwDesiredAccess, dwShareMode,
  497. lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
  498. hTemplateFile);
  499. CmFree(pszFileName);
  500. }
  501. return hHandle;
  502. }
  503. //+----------------------------------------------------------------------------
  504. //
  505. // Function: CreateMutexAU
  506. //
  507. // Synopsis: Unicode to Ansi wrapper for the win32 CreateMutex API.
  508. //
  509. // Arguments: See the win32 API definition
  510. //
  511. // Returns: See the win32 API definition
  512. //
  513. // History: quintinb Created 6/24/99
  514. //
  515. //+----------------------------------------------------------------------------
  516. HANDLE WINAPI CreateMutexAU(IN LPSECURITY_ATTRIBUTES lpMutexAttributes, IN BOOL bInitialOwner,
  517. IN LPCWSTR lpName)
  518. {
  519. HANDLE hHandle = NULL;
  520. LPSTR pszName = NULL;
  521. if (lpName) // lpName can be NULL, creates an unnamed mutex
  522. {
  523. pszName = WzToSzWithAlloc(lpName);
  524. }
  525. if (pszName || (NULL == lpName))
  526. {
  527. hHandle = CreateMutexA(lpMutexAttributes, bInitialOwner, pszName);
  528. CmFree(pszName);
  529. }
  530. return hHandle;
  531. }
  532. //+----------------------------------------------------------------------------
  533. //
  534. // Function: CreateProcessAU
  535. //
  536. // Synopsis: Unicode to Ansi wrapper for the win32 CreateProcess API.
  537. //
  538. // Arguments: See the win32 API definition
  539. //
  540. // Returns: See the win32 API definition
  541. //
  542. // History: quintinb Created 6/24/99
  543. //
  544. //+----------------------------------------------------------------------------
  545. BOOL WINAPI CreateProcessAU(IN LPCWSTR lpApplicationName, IN LPWSTR lpCommandLine,
  546. IN LPSECURITY_ATTRIBUTES lpProcessAttributes,
  547. IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
  548. IN BOOL bInheritHandles, IN DWORD dwCreationFlags,
  549. IN LPVOID lpEnvironment, IN LPCWSTR lpCurrentDirectory,
  550. IN LPSTARTUPINFOW lpStartupInfo,
  551. OUT LPPROCESS_INFORMATION lpProcessInformation)
  552. {
  553. BOOL bSuccess = FALSE;
  554. //
  555. // Check for possible security violations. Either the lpApplicationName param
  556. // should not be NULL, or at least the lpCommandLine param should have the
  557. // actual exe name in quotes (we do a partial check for the latter).
  558. //
  559. CMASSERTMSG((lpApplicationName || (lpCommandLine && (TEXT('"') == lpCommandLine[0]))),
  560. TEXT("CreateProcessAU -- Security Violation. Either lpApplication name should be non-null, or the app name in lpCommandLine should be delimited with double-quotes"));
  561. //
  562. // Convert the string parameters. Since the environment block is controlled by
  563. // a flag (whether it is Ansi or Unicode) we shouldn't have to touch it here.
  564. //
  565. LPSTR pszAppName = WzToSzWithAlloc(lpApplicationName); // WzToSzWithAlloc will return NULL if the input is NULL
  566. LPSTR pszCmdLine = WzToSzWithAlloc(lpCommandLine);
  567. LPSTR pszCurrentDir = WzToSzWithAlloc(lpCurrentDirectory);
  568. //
  569. // Set up the StartUp Info struct. Note that we don't convert it but pass a blank
  570. // structure. If someone needs startupinfo then they will have to write the conversion
  571. // code. We currently don't use it anywhere.
  572. //
  573. STARTUPINFOA StartUpInfoA;
  574. ZeroMemory(&StartUpInfoA, sizeof(STARTUPINFOA));
  575. StartUpInfoA.cb = sizeof(STARTUPINFOA);
  576. #ifdef DEBUG
  577. STARTUPINFOW CompareStartupInfoWStruct;
  578. ZeroMemory(&CompareStartupInfoWStruct, sizeof(STARTUPINFOW));
  579. CompareStartupInfoWStruct.cb = sizeof(STARTUPINFOW);
  580. CMASSERTMSG((0 == memcmp(lpStartupInfo, &CompareStartupInfoWStruct, sizeof(STARTUPINFOW))), TEXT("CreateProcessAU -- Non-NULL STARTUPINFOW struct passed. Conversion code needs to be written."));
  581. #endif
  582. //
  583. // If we have the Command Line or an App Name go ahead
  584. //
  585. if (pszAppName || pszCmdLine)
  586. {
  587. bSuccess = CreateProcessA(pszAppName, pszCmdLine,
  588. lpProcessAttributes, lpThreadAttributes,
  589. bInheritHandles, dwCreationFlags,
  590. lpEnvironment, pszCurrentDir,
  591. &StartUpInfoA, lpProcessInformation);
  592. }
  593. //
  594. // Cleanup
  595. //
  596. CmFree(pszAppName);
  597. CmFree(pszCmdLine);
  598. CmFree(pszCurrentDir);
  599. return bSuccess;
  600. }
  601. //+----------------------------------------------------------------------------
  602. //
  603. // Function: CreateWindowExAU
  604. //
  605. // Synopsis: Unicode to Ansi wrapper for the win32 CreateWindowEx API. Note that
  606. // we only allow MAX_PATH chars for the ClassName and the WindowName
  607. //
  608. // Arguments: See the win32 API definition
  609. //
  610. // Returns: See the win32 API definition
  611. //
  612. // History: quintinb Created 6/24/99
  613. //
  614. //+----------------------------------------------------------------------------
  615. HWND WINAPI CreateWindowExAU(DWORD dwExStyle, LPCWSTR lpClassNameW, LPCWSTR lpWindowNameW, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
  616. {
  617. CHAR szClassNameA [MAX_PATH+1];
  618. CHAR szWindowNameA[MAX_PATH+1];
  619. HWND hReturn = NULL;
  620. if (lpClassNameW && lpWindowNameW)
  621. {
  622. MYDBGASSERT(MAX_PATH >= lstrlenAU(lpClassNameW));
  623. MYDBGASSERT(MAX_PATH >= lstrlenAU(lpWindowNameW));
  624. if (WzToSz(lpClassNameW, szClassNameA, MAX_PATH))
  625. {
  626. if (WzToSz(lpWindowNameW, szWindowNameA, MAX_PATH))
  627. {
  628. hReturn = CreateWindowExA(dwExStyle, szClassNameA, szWindowNameA, dwStyle, x, y,
  629. nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
  630. }
  631. }
  632. }
  633. return hReturn;
  634. }
  635. //+----------------------------------------------------------------------------
  636. //
  637. // Function: DeleteFileAU
  638. //
  639. // Synopsis: Unicode to Ansi wrapper for the win32 DeleteFile API.
  640. //
  641. // Arguments: See the win32 API definition
  642. //
  643. // Returns: See the win32 API definition
  644. //
  645. // History: quintinb Created 6/24/99
  646. //
  647. //+----------------------------------------------------------------------------
  648. BOOL WINAPI DeleteFileAU(IN LPCWSTR lpFileName)
  649. {
  650. BOOL bReturn = FALSE;
  651. LPSTR pszAnsiFileName = WzToSzWithAlloc(lpFileName); // WzToSzWithAlloc will return NULL if lpFileName is NULL
  652. if (pszAnsiFileName)
  653. {
  654. DeleteFileA(pszAnsiFileName);
  655. CmFree(pszAnsiFileName);
  656. }
  657. return bReturn;
  658. }
  659. //+----------------------------------------------------------------------------
  660. //
  661. // Function: DialogBoxParamAU
  662. //
  663. // Synopsis: Unicode to Ansi wrapper for the win32 DialogBoxParam API. Note that
  664. // we don't support the use of a full string name, only ints for the
  665. // lpTemplateName param. We will assert if one is used.
  666. //
  667. // Arguments: See the win32 API definition
  668. //
  669. // Returns: See the win32 API definition
  670. //
  671. // History: quintinb Created 6/24/99
  672. //
  673. //+----------------------------------------------------------------------------
  674. INT_PTR WINAPI DialogBoxParamAU(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
  675. {
  676. MYDBGASSERT(0 == HIWORD(lpTemplateName)); // we don't support or use the full string name
  677. return DialogBoxParamA(hInstance, (LPCSTR) lpTemplateName, hWndParent, lpDialogFunc, dwInitParam);
  678. }
  679. //+----------------------------------------------------------------------------
  680. //
  681. // Function: ExpandEnvironmentStringsAU
  682. //
  683. // Synopsis: Unicode to Ansi wrapper for the win32 ExpandEnvironmentStrings API.
  684. // We support allowing the user to size the string by passing in the
  685. // following Str, NULL, 0 just as the API reference mentions.
  686. //
  687. // Arguments: See the win32 API definition
  688. //
  689. // Returns: See the win32 API definition
  690. //
  691. // History: quintinb Created 6/24/99
  692. //
  693. //+----------------------------------------------------------------------------
  694. DWORD WINAPI ExpandEnvironmentStringsAU(IN LPCWSTR lpSrc, OUT LPWSTR lpDst, IN DWORD nSize)
  695. {
  696. DWORD dwReturn = 0;
  697. if (lpSrc)
  698. {
  699. //
  700. //
  701. // Since the user could pass in 0 for the size and a NULL pszAnsiDst because they
  702. // want to size the destination string, we want to handle that case. However,
  703. // Win98 and Win95 machines (not counting WinME) don't honor sizing the buffer
  704. // using a NULL lpDst. We will "fool" these machines by using a buffer of size 1.
  705. // Thus they could call it with Str, NULL, 0 and then allocate the correct size and
  706. // call again. Note that we will return an error if the user passes Str, NULL, x
  707. // because we have no buffer to copy the data returned from ExpandEnvironmentStringsA
  708. // into.
  709. //
  710. LPSTR pszAnsiSrc = WzToSzWithAlloc(lpSrc);
  711. LPSTR pszAnsiDst = (LPSTR)CmMalloc((nSize+1)*sizeof(CHAR));
  712. if (pszAnsiSrc && pszAnsiDst)
  713. {
  714. dwReturn = ExpandEnvironmentStringsA(pszAnsiSrc, pszAnsiDst, nSize);
  715. if (dwReturn && (dwReturn <= nSize))
  716. {
  717. //
  718. // Then the function succeeded and there was sufficient buffer space to hold
  719. // the expanded string. Thus we should convert the results and store it back
  720. // in lpDst.
  721. if (lpDst)
  722. {
  723. if (!SzToWz(pszAnsiDst, lpDst, nSize))
  724. {
  725. CMTRACE(TEXT("ExpandEnvironmentStringsAU -- SzToWz conversion of output param failed."));
  726. dwReturn = 0;
  727. }
  728. }
  729. else
  730. {
  731. CMTRACE(TEXT("ExpandEnvironmentStringsAU -- NULL pointer passed for lpDst"));
  732. dwReturn = 0;
  733. SetLastError(ERROR_INVALID_PARAMETER);
  734. }
  735. }
  736. }
  737. else
  738. {
  739. CMTRACE(TEXT("ExpandEnvironmentStringsAU -- NULL pointer returned for pszAnsiSrc or pszAnsiDst"));
  740. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  741. }
  742. CmFree(pszAnsiSrc);
  743. CmFree(pszAnsiDst);
  744. }
  745. else
  746. {
  747. CMTRACE(TEXT("ExpandEnvironmentStringsAU -- NULL pointer passed for lpSrc"));
  748. SetLastError(ERROR_INVALID_PARAMETER);
  749. }
  750. return dwReturn;
  751. }
  752. //+----------------------------------------------------------------------------
  753. //
  754. // Function: FindResourceExAU
  755. //
  756. // Synopsis: Unicode to Ansi wrapper for the win32 FindResourceEx API.
  757. //
  758. // Arguments: See the win32 API definition
  759. //
  760. // Returns: See the win32 API definition
  761. //
  762. // History: quintinb Created 6/24/99
  763. //
  764. //+----------------------------------------------------------------------------
  765. HRSRC WINAPI FindResourceExAU(IN HMODULE hModule, IN LPCWSTR lpType, IN LPCWSTR lpName, IN WORD wLanguage)
  766. {
  767. HRSRC hReturn = NULL;
  768. LPSTR pszType = NULL;
  769. LPSTR pszName = NULL;
  770. //
  771. // Check the input parameters
  772. //
  773. if (lpType && lpName)
  774. {
  775. //
  776. // Two cases for the lpType and the lpName params. These could just be identifiers. We will know
  777. // if the high word is zero. In that case we just need to do a cast and pass it through. If not
  778. // then we need to actually convert the strings.
  779. //
  780. if (0 == HIWORD(lpType))
  781. {
  782. pszType = (LPSTR)lpType;
  783. }
  784. else
  785. {
  786. pszType = WzToSzWithAlloc(lpType);
  787. }
  788. if (0 == HIWORD(lpName))
  789. {
  790. pszName = (LPSTR)lpName;
  791. }
  792. else
  793. {
  794. pszName = WzToSzWithAlloc(lpName);
  795. }
  796. //
  797. // Finally call FindResourceEx
  798. //
  799. if (pszName && pszType)
  800. {
  801. hReturn = FindResourceExA(hModule, pszType, pszName, wLanguage);
  802. }
  803. else
  804. {
  805. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  806. }
  807. }
  808. else
  809. {
  810. SetLastError(ERROR_INVALID_PARAMETER);
  811. }
  812. //
  813. // Clean up
  814. //
  815. if (0 != HIWORD(pszType))
  816. {
  817. CmFree(pszType);
  818. }
  819. if (0 != HIWORD(pszName))
  820. {
  821. CmFree(pszName);
  822. }
  823. return hReturn;
  824. }
  825. //+----------------------------------------------------------------------------
  826. //
  827. // Function: FindWindowExAU
  828. //
  829. // Synopsis: Unicode to Ansi wrapper for the win32 FindWindowEx API.
  830. //
  831. // Arguments: See the win32 API definition
  832. //
  833. // Returns: See the win32 API definition
  834. //
  835. // History: quintinb Created 6/24/99
  836. //
  837. //+----------------------------------------------------------------------------
  838. HWND WINAPI FindWindowExAU(IN HWND hwndParent, IN HWND hwndChildAfter, IN LPCWSTR pszClass, IN LPCWSTR pszWindow)
  839. {
  840. HWND hReturn = NULL;
  841. LPSTR pszAnsiWindow = NULL;
  842. LPSTR pszAnsiClass = NULL;
  843. if (pszClass)
  844. {
  845. //
  846. // We have two cases for pszClass. It can either be a resource ID (high word zero,
  847. // low word contains the ID) in which case we just need to do a cast or
  848. // it could be a NULL terminated string.
  849. //
  850. if (0 == HIWORD(pszClass))
  851. {
  852. pszAnsiClass = (LPSTR)pszClass;
  853. }
  854. else
  855. {
  856. pszAnsiClass = WzToSzWithAlloc(pszClass);
  857. }
  858. //
  859. // pszWindow could be NULL. That will match all Window titles.
  860. //
  861. if (pszWindow)
  862. {
  863. pszAnsiWindow = WzToSzWithAlloc(pszWindow);
  864. }
  865. //
  866. // Check our allocations and call FindWindowExA
  867. //
  868. if (pszAnsiClass && (!pszWindow || pszAnsiWindow))
  869. {
  870. hReturn = FindWindowExA(hwndParent, hwndChildAfter, pszAnsiClass, pszAnsiWindow);
  871. }
  872. else
  873. {
  874. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  875. }
  876. }
  877. else
  878. {
  879. SetLastError(ERROR_INVALID_PARAMETER);
  880. }
  881. //
  882. // Cleanup
  883. //
  884. if (0 != HIWORD(pszAnsiClass))
  885. {
  886. CmFree(pszAnsiClass);
  887. }
  888. CmFree(pszAnsiWindow);
  889. return hReturn;
  890. }
  891. //+----------------------------------------------------------------------------
  892. //
  893. // Function: GetDateFormatAU
  894. //
  895. // Synopsis: Unicode to Ansi wrapper for the win32 GetDateFormat API.
  896. //
  897. // Arguments: See the win32 API definition
  898. //
  899. // Returns: See the win32 API definition
  900. //
  901. // History: sumitc Created 11/20/00
  902. //
  903. //+----------------------------------------------------------------------------
  904. int WINAPI GetDateFormatAU(IN LCID Locale, IN DWORD dwFlags,
  905. IN CONST SYSTEMTIME *lpDate, IN LPCWSTR lpFormat,
  906. OUT LPWSTR lpDateStr, IN int cchDate)
  907. {
  908. int iReturn = 0;
  909. LPSTR pszAnsiFormat = NULL;
  910. LPSTR pszAnsiBuffer = NULL;
  911. if (lpFormat)
  912. {
  913. pszAnsiFormat = WzToSzWithAlloc(lpFormat);
  914. if (!pszAnsiFormat)
  915. {
  916. CMASSERTMSG(FALSE, TEXT("GetDateFormatAU -- Conversion of lpFormat Failed."));
  917. goto exit;
  918. }
  919. }
  920. else
  921. {
  922. pszAnsiFormat = (LPSTR)lpFormat; // Could be NULL
  923. }
  924. if (lpDateStr && cchDate)
  925. {
  926. pszAnsiBuffer = (LPSTR) CmMalloc(cchDate * sizeof(CHAR));
  927. }
  928. iReturn = GetDateFormatA(Locale, dwFlags, lpDate, pszAnsiFormat, pszAnsiBuffer, cchDate);
  929. if (iReturn && lpDateStr && cchDate && pszAnsiBuffer)
  930. {
  931. SzToWz(pszAnsiBuffer, lpDateStr, cchDate);
  932. }
  933. exit:
  934. CmFree(pszAnsiFormat);
  935. CmFree(pszAnsiBuffer);
  936. return iReturn;
  937. }
  938. //+----------------------------------------------------------------------------
  939. //
  940. // Function: GetDlgItemTextAU
  941. //
  942. // Synopsis: Unicode to Ansi wrapper for the win32 GetDlgItemText API. Note that
  943. // this function makes a WM_GETTEXT window message call using GetDlgItem
  944. // and SendMessageAU. This is how the win32 API function is implemented.
  945. //
  946. // Arguments: See the win32 API definition
  947. //
  948. // Returns: See the win32 API definition
  949. //
  950. // History: quintinb Created 6/24/99
  951. //
  952. //+----------------------------------------------------------------------------
  953. UINT WINAPI GetDlgItemTextAU(IN HWND hDlg, IN int nIDDlgItem, OUT LPWSTR pszwString, IN int nMaxCount)
  954. {
  955. return (int) SendMessageAU(GetDlgItem(hDlg, nIDDlgItem), WM_GETTEXT, (WPARAM) nMaxCount, (LPARAM) pszwString);
  956. }
  957. //+----------------------------------------------------------------------------
  958. //
  959. // Function: GetFileAttributesAU
  960. //
  961. // Synopsis: Unicode to Ansi wrapper for the win32 GetFileAttributes API.
  962. //
  963. // Arguments: See the win32 API definition
  964. //
  965. // Returns: See the win32 API definition
  966. //
  967. // History: sumitc Created 11/08/00
  968. //
  969. //+----------------------------------------------------------------------------
  970. DWORD WINAPI GetFileAttributesAU(LPCWSTR lpFileName)
  971. {
  972. DWORD dwReturn = -1;
  973. LPSTR pszAnsiFileName = WzToSzWithAlloc(lpFileName);
  974. if (pszAnsiFileName)
  975. {
  976. dwReturn = GetFileAttributesA(pszAnsiFileName);
  977. CmFree(pszAnsiFileName);
  978. }
  979. return dwReturn;
  980. }
  981. //+----------------------------------------------------------------------------
  982. //
  983. // Function: GetModuleFileNameAU
  984. //
  985. // Synopsis: Unicode to Ansi wrapper for the win32 GetModuleFileName API.
  986. // Note that we only allow MAX_PATH chars for the module name.
  987. //
  988. // Arguments: See the win32 API definition
  989. //
  990. // Returns: See the win32 API definition
  991. //
  992. // History: quintinb Created 6/24/99
  993. //
  994. //+----------------------------------------------------------------------------
  995. DWORD WINAPI GetModuleFileNameAU(HMODULE hModule, LPWSTR lpFileName, DWORD nSize)
  996. {
  997. DWORD dwReturn = 0;
  998. CHAR pszAnsiFileName[MAX_PATH] = {'\0'} ;
  999. MYDBGASSERT(MAX_PATH >= nSize);
  1000. dwReturn = GetModuleFileNameA(hModule, pszAnsiFileName, __min(nSize, MAX_PATH));
  1001. if(dwReturn && lpFileName)
  1002. {
  1003. SzToWz(pszAnsiFileName, lpFileName, __min(nSize, MAX_PATH));
  1004. }
  1005. return dwReturn;
  1006. }
  1007. //+----------------------------------------------------------------------------
  1008. //
  1009. // Function: GetModuleHandleAU
  1010. //
  1011. // Synopsis: Unicode to Ansi wrapper for the win32 GetModuleHandle API.
  1012. // Note that we only allow MAX_PATH chars for the module name.
  1013. //
  1014. // Arguments: See the win32 API definition
  1015. //
  1016. // Returns: See the win32 API definition
  1017. //
  1018. // History: sumitc Created 10/20/2000
  1019. //
  1020. //+----------------------------------------------------------------------------
  1021. HMODULE WINAPI GetModuleHandleAU(LPCWSTR lpModuleName)
  1022. {
  1023. HMODULE hMod = NULL;
  1024. LPSTR pszAnsiModuleName = WzToSzWithAlloc(lpModuleName);
  1025. if (pszAnsiModuleName)
  1026. {
  1027. hMod = GetModuleHandleA(pszAnsiModuleName);
  1028. CmFree(pszAnsiModuleName);
  1029. }
  1030. return hMod;
  1031. }
  1032. //+----------------------------------------------------------------------------
  1033. //
  1034. // Function: GetPrivateProfileIntAU
  1035. //
  1036. // Synopsis: Unicode to Ansi wrapper for the win32 GetPrivateProfileInt API.
  1037. //
  1038. // Arguments: See the win32 API definition
  1039. //
  1040. // Returns: See the win32 API definition
  1041. //
  1042. // History: quintinb Created 6/24/99
  1043. //
  1044. //+----------------------------------------------------------------------------
  1045. UINT WINAPI GetPrivateProfileIntAU(IN LPCWSTR lpAppName, IN LPCWSTR lpKeyName, IN INT nDefault,
  1046. IN LPCWSTR lpFileName)
  1047. {
  1048. UINT uReturn = nDefault;
  1049. if (lpAppName && lpKeyName && lpFileName)
  1050. {
  1051. CHAR pszAnsiAppName[MAX_PATH+1];
  1052. CHAR pszAnsiKeyName[MAX_PATH+1];
  1053. CHAR pszAnsiFileName[MAX_PATH+1];
  1054. BOOL bSuccess = TRUE;
  1055. int nChars;
  1056. nChars = WzToSz(lpAppName, pszAnsiAppName, MAX_PATH);
  1057. bSuccess = bSuccess && nChars && (MAX_PATH >= nChars);
  1058. nChars = WzToSz(lpKeyName, pszAnsiKeyName, MAX_PATH);
  1059. bSuccess = bSuccess && nChars && (MAX_PATH >= nChars);
  1060. nChars = WzToSz(lpFileName, pszAnsiFileName, MAX_PATH);
  1061. bSuccess = bSuccess && nChars && (MAX_PATH >= nChars);
  1062. if (bSuccess)
  1063. {
  1064. uReturn = GetPrivateProfileIntA(pszAnsiAppName, pszAnsiKeyName, nDefault,
  1065. pszAnsiFileName);
  1066. }
  1067. CMASSERTMSG(bSuccess, TEXT("GetPrivateProfileIntAU -- Failed to convert lpAppName, lpKeyName, or lpFileName"));
  1068. }
  1069. return uReturn;
  1070. }
  1071. //+----------------------------------------------------------------------------
  1072. //
  1073. // Function: GetPrivateProfileStringAU
  1074. //
  1075. // Synopsis: Unicode to Ansi wrapper for the win32 GetPrivateProfileString API.
  1076. // Note that either lpAppName or lpKeyName could be NULL. This means
  1077. // that our return buffer will contain multiple lines of NULL terminated
  1078. // text. We must use MultiByteToWideChar directly with a size param
  1079. // to properly convert such a situation.
  1080. //
  1081. // Arguments: See the win32 API definition
  1082. //
  1083. // Returns: See the win32 API definition
  1084. //
  1085. // History: quintinb Created 6/24/99
  1086. //
  1087. //+----------------------------------------------------------------------------
  1088. DWORD WINAPI GetPrivateProfileStringAU(IN LPCWSTR lpAppName, IN LPCWSTR lpKeyName,
  1089. IN LPCWSTR lpDefault, OUT LPWSTR lpReturnedString,
  1090. IN DWORD nSize, IN LPCWSTR lpFileName)
  1091. {
  1092. //
  1093. // Declare all the temp vars we need
  1094. //
  1095. LPSTR pszAnsiAppName = NULL;
  1096. LPSTR pszAnsiKeyName = NULL;
  1097. LPSTR pszAnsiReturnedString = NULL;
  1098. CHAR szAnsiAppName[MAX_PATH+1];
  1099. CHAR szAnsiKeyName[MAX_PATH+1];
  1100. CHAR szAnsiDefault[MAX_PATH+1];
  1101. CHAR szAnsiFileName[MAX_PATH+1];
  1102. DWORD dwReturn = 0;
  1103. int nChars;
  1104. //
  1105. // Check the inputs, note that either lpAppName or lpKeyName may be NULL (or both)
  1106. //
  1107. if (lpDefault && lpReturnedString && nSize && lpFileName)
  1108. {
  1109. if (lpAppName) // pszAnsiAppName already initialized to NULL
  1110. {
  1111. pszAnsiAppName = szAnsiAppName;
  1112. nChars = WzToSz(lpAppName, pszAnsiAppName, MAX_PATH);
  1113. if (!nChars || (MAX_PATH < nChars))
  1114. {
  1115. //
  1116. // Conversion failed.
  1117. //
  1118. goto exit;
  1119. }
  1120. }
  1121. if (lpKeyName) // pszAnsiKeyName already initialized to NULL
  1122. {
  1123. pszAnsiKeyName = szAnsiKeyName;
  1124. nChars = WzToSz(lpKeyName, szAnsiKeyName, MAX_PATH);
  1125. if (!nChars || (MAX_PATH < nChars))
  1126. {
  1127. //
  1128. // Conversion failed.
  1129. //
  1130. goto exit;
  1131. }
  1132. }
  1133. nChars = WzToSz(lpDefault, szAnsiDefault, MAX_PATH);
  1134. if (!nChars || (MAX_PATH < nChars))
  1135. {
  1136. goto exit;
  1137. }
  1138. nChars = WzToSz(lpFileName, szAnsiFileName, MAX_PATH);
  1139. if (!nChars || (MAX_PATH < nChars))
  1140. {
  1141. goto exit;
  1142. }
  1143. //
  1144. // Alloc the Ansi return Buffer
  1145. //
  1146. pszAnsiReturnedString = (LPSTR)CmMalloc(nSize*sizeof(CHAR));
  1147. if (pszAnsiReturnedString)
  1148. {
  1149. dwReturn = GetPrivateProfileStringA(pszAnsiAppName, pszAnsiKeyName, szAnsiDefault,
  1150. pszAnsiReturnedString, nSize, szAnsiFileName);
  1151. if (dwReturn)
  1152. {
  1153. if (pszAnsiAppName && pszAnsiKeyName)
  1154. {
  1155. if (!SzToWz(pszAnsiReturnedString, lpReturnedString, nSize))
  1156. {
  1157. dwReturn = 0;
  1158. }
  1159. }
  1160. else
  1161. {
  1162. //
  1163. // We have multiple lines of text in the return buffer, use MultiByteToWideChar
  1164. // with a size specifier
  1165. //
  1166. if (!MultiByteToWideChar(CP_ACP, 0, pszAnsiReturnedString, dwReturn,
  1167. lpReturnedString, nSize))
  1168. {
  1169. dwReturn = 0;
  1170. }
  1171. }
  1172. }
  1173. }
  1174. }
  1175. exit:
  1176. CmFree(pszAnsiReturnedString);
  1177. return dwReturn;
  1178. }
  1179. //+----------------------------------------------------------------------------
  1180. //
  1181. // Function: GetStringTypeExAU
  1182. //
  1183. // Synopsis: Unicode to Ansi wrapper for the win32 GetStringTypeEx API. Note
  1184. // that because we only use one char at a time with this API, I have
  1185. // limited it to a 10 char static buffer to make it faster.
  1186. //
  1187. // Arguments: See the win32 API definition
  1188. //
  1189. // Returns: See the win32 API definition
  1190. //
  1191. // History: quintinb Created 6/24/99
  1192. //
  1193. //+----------------------------------------------------------------------------
  1194. BOOL WINAPI GetStringTypeExAU(IN LCID Locale, IN DWORD dwInfoType, IN LPCWSTR lpSrcStr,
  1195. IN int cchSrc, OUT LPWORD lpCharType)
  1196. {
  1197. BOOL bReturn = FALSE;
  1198. CHAR szAnsiString[10]; // We should only be using 1 char at a time with this
  1199. if (lpSrcStr && cchSrc)
  1200. {
  1201. MYDBGASSERT(cchSrc <= 10);
  1202. int nCount = WideCharToMultiByte(CP_ACP, 0, lpSrcStr, cchSrc, szAnsiString,
  1203. 9, NULL, NULL);
  1204. if (nCount) // nCount may not exactly equal cchSrc if DBCS chars were necessary
  1205. {
  1206. bReturn = GetStringTypeExA(Locale, dwInfoType, szAnsiString, nCount, lpCharType);
  1207. }
  1208. }
  1209. return bReturn;
  1210. }
  1211. //+----------------------------------------------------------------------------
  1212. //
  1213. // Function: GetSystemDirectoryAU
  1214. //
  1215. // Synopsis: Unicode to Ansi wrapper for the win32 GetSystemDirectory API.
  1216. //
  1217. // Arguments: See the win32 API definition
  1218. //
  1219. // Returns: See the win32 API definition
  1220. //
  1221. // History: quintinb Created 6/24/99
  1222. //
  1223. //+----------------------------------------------------------------------------
  1224. UINT WINAPI GetSystemDirectoryAU(OUT LPWSTR lpBuffer, IN UINT uSize)
  1225. {
  1226. UINT uReturn = 0;
  1227. LPSTR pszAnsiSystemDir;
  1228. pszAnsiSystemDir = uSize ? (LPSTR)CmMalloc(uSize*sizeof(CHAR)) : NULL;
  1229. if (pszAnsiSystemDir || (0 == uSize))
  1230. {
  1231. uReturn = GetSystemDirectoryA(pszAnsiSystemDir, uSize);
  1232. CMASSERTMSG(uReturn, TEXT("GetSystemDirectoryAU -- GetSystemDirectoryAU failed."));
  1233. if (uReturn && lpBuffer && (uSize >= uReturn))
  1234. {
  1235. if (!SzToWz(pszAnsiSystemDir, lpBuffer, uSize))
  1236. {
  1237. //
  1238. // Conversion failed.
  1239. //
  1240. CMASSERTMSG(FALSE, TEXT("GetSystemDirectoryAU -- SzToWz conversion failed."));
  1241. uReturn = 0;
  1242. }
  1243. }
  1244. }
  1245. CmFree(pszAnsiSystemDir);
  1246. return uReturn;
  1247. }
  1248. //+----------------------------------------------------------------------------
  1249. //
  1250. // Function: GetTempFileNameAU
  1251. //
  1252. // Synopsis: Unicode to Ansi wrapper for the win32 GetTempFileName API.
  1253. //
  1254. // Arguments: See the win32 API definition
  1255. //
  1256. // Returns: See the win32 API definition
  1257. //
  1258. // History: quintinb Created 6/24/99
  1259. //
  1260. //+----------------------------------------------------------------------------
  1261. UINT WINAPI GetTempFileNameAU(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique,
  1262. OUT LPWSTR lpTempFileName)
  1263. {
  1264. UINT uReturn = 0;
  1265. if (lpPathName && lpPrefixString && lpTempFileName)
  1266. {
  1267. CHAR szAnsiTempFileName[MAX_PATH+1];
  1268. CHAR szPathName[MAX_PATH+1];
  1269. CHAR szPrefixString[MAX_PATH+1];
  1270. BOOL bSuccess = TRUE;
  1271. int nChars;
  1272. nChars = WzToSz(lpPathName, szPathName, MAX_PATH);
  1273. bSuccess = bSuccess && nChars && (MAX_PATH >= nChars);
  1274. nChars = WzToSz(lpPrefixString, szPrefixString, MAX_PATH);
  1275. bSuccess = bSuccess && nChars && (MAX_PATH >= nChars);
  1276. if (bSuccess)
  1277. {
  1278. uReturn = GetTempFileNameA(szPathName, szPrefixString, uUnique, szAnsiTempFileName);
  1279. if (uReturn)
  1280. {
  1281. if (!SzToWz(szAnsiTempFileName, lpTempFileName, MAX_PATH))
  1282. {
  1283. CMASSERTMSG(FALSE, TEXT("GetTempFileNameAU -- conversion of output buffer failed."));
  1284. uReturn = 0;
  1285. }
  1286. }
  1287. }
  1288. else
  1289. {
  1290. CMASSERTMSG(FALSE, TEXT("GetTempFileNameAU -- conversion of inputs failed."));
  1291. SetLastError(ERROR_INVALID_PARAMETER);
  1292. }
  1293. }
  1294. else
  1295. {
  1296. SetLastError(ERROR_INVALID_PARAMETER);
  1297. }
  1298. return uReturn;
  1299. }
  1300. //+----------------------------------------------------------------------------
  1301. //
  1302. // Function: GetTempPathAU
  1303. //
  1304. // Synopsis: Unicode to Ansi wrapper for the win32 GetTempPath API.
  1305. //
  1306. // Arguments: See the win32 API definition
  1307. //
  1308. // Returns: See the win32 API definition
  1309. //
  1310. // History: quintinb Created 6/24/99
  1311. //
  1312. //+----------------------------------------------------------------------------
  1313. DWORD WINAPI GetTempPathAU(IN DWORD nBufferLength, OUT LPWSTR lpBuffer)
  1314. {
  1315. UINT uReturn = 0;
  1316. LPSTR pszAnsiBuffer = (LPSTR)CmMalloc(nBufferLength*sizeof(CHAR));
  1317. if (pszAnsiBuffer)
  1318. {
  1319. uReturn = GetTempPathA(nBufferLength, pszAnsiBuffer);
  1320. if (uReturn)
  1321. {
  1322. if (!SzToWz(pszAnsiBuffer, lpBuffer, nBufferLength))
  1323. {
  1324. CMASSERTMSG(FALSE, TEXT("GetTempPathAU -- conversion of output buffer failed."));
  1325. uReturn = 0;
  1326. }
  1327. }
  1328. CmFree(pszAnsiBuffer);
  1329. }
  1330. return uReturn;
  1331. }
  1332. //+----------------------------------------------------------------------------
  1333. //
  1334. // Function: GetTimeFormatAU
  1335. //
  1336. // Synopsis: Unicode to Ansi wrapper for the win32 GetTimeFormat API.
  1337. //
  1338. // Arguments: See the win32 API definition
  1339. //
  1340. // Returns: See the win32 API definition
  1341. //
  1342. // History: sumitc Created 11/20/00
  1343. //
  1344. //+----------------------------------------------------------------------------
  1345. int WINAPI GetTimeFormatAU(IN LCID Locale, IN DWORD dwFlags,
  1346. IN CONST SYSTEMTIME *lpTime, IN LPCWSTR lpFormat,
  1347. OUT LPWSTR lpTimeStr, IN int cchTime)
  1348. {
  1349. int iReturn = 0;
  1350. LPSTR pszAnsiFormat = NULL;
  1351. LPSTR pszAnsiBuffer = NULL;
  1352. if (lpFormat)
  1353. {
  1354. pszAnsiFormat = WzToSzWithAlloc(lpFormat);
  1355. if (!pszAnsiFormat)
  1356. {
  1357. CMASSERTMSG(FALSE, TEXT("GetTimeFormatAU -- Conversion of lpFormat Failed."));
  1358. goto exit;
  1359. }
  1360. }
  1361. else
  1362. {
  1363. pszAnsiFormat = (LPSTR)lpFormat; // Could be NULL
  1364. }
  1365. if (lpTimeStr && cchTime)
  1366. {
  1367. pszAnsiBuffer = (LPSTR) CmMalloc(cchTime * sizeof(CHAR));
  1368. }
  1369. iReturn = GetTimeFormatA(Locale, dwFlags, lpTime, pszAnsiFormat, pszAnsiBuffer, cchTime);
  1370. if (iReturn && lpTimeStr && cchTime && pszAnsiBuffer)
  1371. {
  1372. SzToWz(pszAnsiBuffer, lpTimeStr, cchTime);
  1373. }
  1374. exit:
  1375. CmFree(pszAnsiFormat);
  1376. CmFree(pszAnsiBuffer);
  1377. return iReturn;
  1378. }
  1379. //+----------------------------------------------------------------------------
  1380. //
  1381. // Function: GetUserNameAU
  1382. //
  1383. // Synopsis: Unicode to Ansi wrapper for the win32 GetUserName API.
  1384. // Note that we assume the user name will fit in MAX_PATH chars.
  1385. //
  1386. // Arguments: See the win32 API definition
  1387. //
  1388. // Returns: See the win32 API definition
  1389. //
  1390. // History: quintinb Created 6/24/99
  1391. //
  1392. //+----------------------------------------------------------------------------
  1393. BOOL WINAPI GetUserNameAU(OUT LPWSTR lpBuffer, IN OUT LPDWORD pdwSize)
  1394. {
  1395. BOOL bReturn = FALSE;
  1396. if (lpBuffer && pdwSize && *pdwSize)
  1397. {
  1398. MYDBGASSERT(MAX_PATH >= *pdwSize);
  1399. CHAR szAnsiBuffer[MAX_PATH+1]; // API says UNLEN+1 needed but this is less than MAX_PATH
  1400. DWORD dwTemp = MAX_PATH;
  1401. bReturn = GetUserNameA(szAnsiBuffer, &dwTemp);
  1402. if (bReturn)
  1403. {
  1404. if (!SzToWz(szAnsiBuffer, lpBuffer, *pdwSize))
  1405. {
  1406. bReturn = FALSE;
  1407. }
  1408. else
  1409. {
  1410. *pdwSize = lstrlenAU(lpBuffer) + 1;
  1411. }
  1412. }
  1413. }
  1414. else
  1415. {
  1416. SetLastError(ERROR_INVALID_PARAMETER);
  1417. }
  1418. CMASSERTMSG(bReturn, TEXT("GetUserNameAU Failed."));
  1419. return bReturn;
  1420. }
  1421. //+----------------------------------------------------------------------------
  1422. //
  1423. // Function: GetVersionExAU
  1424. //
  1425. // Synopsis: Unicode to Ansi wrapper for the win32 GetVersionEx API. Note that
  1426. // we check to make sure we aren't passed an OSVERSIONINFOEXW struct
  1427. // because that struct is currently NT5 only.
  1428. //
  1429. // Arguments: See the win32 API definition
  1430. //
  1431. // Returns: See the win32 API definition
  1432. //
  1433. // History: quintinb Created 6/24/99
  1434. //
  1435. //+----------------------------------------------------------------------------
  1436. BOOL WINAPI GetVersionExAU(IN OUT LPOSVERSIONINFOW lpVersionInformation)
  1437. {
  1438. BOOL bReturn = FALSE;
  1439. if (lpVersionInformation)
  1440. {
  1441. OSVERSIONINFOA AnsiVersionInfo;
  1442. //
  1443. // Check to make sure we didn't get an OSVERSIONINFOEXW struct instead of a OSVERSIONINFO
  1444. // the EX version is NT5 only we shouldn't be calling this on NT5.
  1445. //
  1446. MYDBGASSERT(lpVersionInformation->dwOSVersionInfoSize != sizeof(_OSVERSIONINFOEXW));
  1447. AnsiVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
  1448. bReturn = GetVersionExA(&AnsiVersionInfo);
  1449. if (bReturn)
  1450. {
  1451. //lpVersionInformation.dwOSVersionInfoSize; // should be set appropriately already
  1452. lpVersionInformation->dwMajorVersion = AnsiVersionInfo.dwMajorVersion;
  1453. lpVersionInformation->dwMinorVersion = AnsiVersionInfo.dwMinorVersion;
  1454. lpVersionInformation->dwBuildNumber = AnsiVersionInfo.dwBuildNumber;
  1455. lpVersionInformation->dwPlatformId = AnsiVersionInfo.dwPlatformId;
  1456. if (!SzToWz(AnsiVersionInfo.szCSDVersion, lpVersionInformation->szCSDVersion, 128-1))
  1457. {
  1458. bReturn = FALSE;
  1459. }
  1460. }
  1461. }
  1462. CMASSERTMSG(bReturn, TEXT("GetVersionExAU Failed"));
  1463. return bReturn;
  1464. }
  1465. //+----------------------------------------------------------------------------
  1466. //
  1467. // Function: GetWindowTextAU
  1468. //
  1469. // Synopsis: Unicode to Ansi wrapper for the win32 GetWindowText API. This API
  1470. // is implemented as a WM_GETTEXT message just as the real windows
  1471. // API is.
  1472. //
  1473. // Arguments: See the win32 API definition
  1474. //
  1475. // Returns: See the win32 API definition
  1476. //
  1477. // History: quintinb Created 6/24/99
  1478. //
  1479. //+----------------------------------------------------------------------------
  1480. int WINAPI GetWindowTextAU(HWND hWnd, LPWSTR lpStringW, int nMaxChars)
  1481. {
  1482. return (int) SendMessageAU(hWnd, WM_GETTEXT, (WPARAM) nMaxChars, (LPARAM) lpStringW);
  1483. }
  1484. //+----------------------------------------------------------------------------
  1485. //
  1486. // Function: GetWindowTextAU
  1487. //
  1488. // Synopsis: Unicode to Ansi wrapper for the win32 GetWindowText API. This API
  1489. // is implemented as a WM_GETTEXT message just as the real windows
  1490. // API is. Note that since MF_STRING is 0, we must check to make sure
  1491. // that it isn't one of the other menu item choices (MF_OWNERDRAW,
  1492. // MF_BITMAP, or MF_SEPARATOR). The other MF_ flags are just modifiers
  1493. // for the above basic types.
  1494. //
  1495. // Arguments: See the win32 API definition
  1496. //
  1497. // Returns: See the win32 API definition
  1498. //
  1499. // History: quintinb Created 6/24/99
  1500. //
  1501. //+----------------------------------------------------------------------------
  1502. BOOL WINAPI InsertMenuAU(IN HMENU hMenu, IN UINT uPosition, IN UINT uFlags,
  1503. IN UINT_PTR uIDNewItem, IN LPCWSTR lpNewItem)
  1504. {
  1505. BOOL bReturn = FALSE;
  1506. LPSTR pszAnsiNewItem = NULL;
  1507. BOOL bFreeAnsiNewItem = FALSE;
  1508. if (hMenu)
  1509. {
  1510. //
  1511. // Since MF_STRING == 0, we must check that it is not MF_OWNERDRAW or MF_BITMAP or
  1512. // that it is not MF_SEPARATOR
  1513. //
  1514. if ((0 == (uFlags & MF_BITMAP)) && (0 == (uFlags & MF_OWNERDRAW)) &&
  1515. (0 == (uFlags & MF_SEPARATOR)) && lpNewItem)
  1516. {
  1517. //
  1518. // Then the menu item actually contains a string and we must convert it.
  1519. //
  1520. pszAnsiNewItem = WzToSzWithAlloc(lpNewItem);
  1521. if (!pszAnsiNewItem)
  1522. {
  1523. CMASSERTMSG(FALSE, TEXT("InsertMenuAU -- Conversion of lpNewItem Failed."));
  1524. goto exit;
  1525. }
  1526. bFreeAnsiNewItem = TRUE;
  1527. }
  1528. else
  1529. {
  1530. pszAnsiNewItem = (LPSTR)lpNewItem; // Could be NULL
  1531. }
  1532. bReturn = InsertMenuA(hMenu, uPosition, uFlags, uIDNewItem, pszAnsiNewItem);
  1533. }
  1534. exit:
  1535. if (bFreeAnsiNewItem)
  1536. {
  1537. CmFree(pszAnsiNewItem);
  1538. }
  1539. return bReturn;
  1540. }
  1541. //+----------------------------------------------------------------------------
  1542. //
  1543. // Function: LoadCursorAU
  1544. //
  1545. // Synopsis: Unicode to Ansi wrapper for the win32 LoadCursor API. Note that
  1546. // lpCursorName could be a string or it could be a resource ID from
  1547. // MAKEINTRESOURCE. We assume the cursor name will fit in MAX_PATH
  1548. // chars if it is a string.
  1549. //
  1550. // Arguments: See the win32 API definition
  1551. //
  1552. // Returns: See the win32 API definition
  1553. //
  1554. // History: quintinb Created 6/24/99
  1555. //
  1556. //+----------------------------------------------------------------------------
  1557. HCURSOR WINAPI LoadCursorAU(IN HINSTANCE hInstance, IN LPCWSTR lpCursorName)
  1558. {
  1559. LPSTR pszCursorName;
  1560. CHAR szCursorName[MAX_PATH+1];
  1561. HCURSOR hReturn = NULL;
  1562. if (lpCursorName)
  1563. {
  1564. BOOL bSuccess = TRUE;
  1565. if (0 == HIWORD(lpCursorName))
  1566. {
  1567. pszCursorName = (LPSTR)lpCursorName;
  1568. }
  1569. else
  1570. {
  1571. int nChars;
  1572. pszCursorName = szCursorName;
  1573. nChars = WzToSz(lpCursorName, pszCursorName, MAX_PATH);
  1574. bSuccess = bSuccess && nChars && (MAX_PATH >= nChars);
  1575. }
  1576. if (bSuccess)
  1577. {
  1578. hReturn = LoadCursorA(hInstance, pszCursorName);
  1579. }
  1580. }
  1581. else
  1582. {
  1583. SetLastError(ERROR_INVALID_PARAMETER);
  1584. }
  1585. return hReturn;
  1586. }
  1587. //+----------------------------------------------------------------------------
  1588. //
  1589. // Function: LoadIconAU
  1590. //
  1591. // Synopsis: Unicode to Ansi wrapper for the win32 LoadIcon API. Note that
  1592. // lpIconName could be a string or it could be a resource ID from
  1593. // MAKEINTRESOURCE. We assume the icon name will fit in MAX_PATH
  1594. // chars if it is a string.
  1595. //
  1596. // Arguments: See the win32 API definition
  1597. //
  1598. // Returns: See the win32 API definition
  1599. //
  1600. // History: quintinb Created 6/24/99
  1601. //
  1602. //+----------------------------------------------------------------------------
  1603. HICON WINAPI LoadIconAU(IN HINSTANCE hInstance, IN LPCWSTR lpIconName)
  1604. {
  1605. LPSTR pszIconName;
  1606. CHAR szIconName[MAX_PATH+1];
  1607. HICON hReturn = NULL;
  1608. if (hInstance && lpIconName)
  1609. {
  1610. BOOL bSuccess = TRUE;
  1611. if (0 == HIWORD(lpIconName))
  1612. {
  1613. pszIconName = (LPSTR)lpIconName;
  1614. }
  1615. else
  1616. {
  1617. int nChars;
  1618. pszIconName = szIconName;
  1619. nChars = WzToSz(lpIconName, pszIconName, MAX_PATH);
  1620. bSuccess = bSuccess && nChars && (MAX_PATH >= nChars);
  1621. }
  1622. if (bSuccess)
  1623. {
  1624. hReturn = LoadIconA(hInstance, pszIconName);
  1625. }
  1626. }
  1627. else
  1628. {
  1629. SetLastError(ERROR_INVALID_PARAMETER);
  1630. }
  1631. return hReturn;
  1632. }
  1633. //+----------------------------------------------------------------------------
  1634. //
  1635. // Function: LoadImageAU
  1636. //
  1637. // Synopsis: Unicode to Ansi wrapper for the win32 LoadImage API. Note that
  1638. // pszwName could be a string or it could be a resource ID from
  1639. // MAKEINTRESOURCE. We assume the image name will fit in MAX_PATH
  1640. // chars if it is a string.
  1641. //
  1642. // Arguments: See the win32 API definition
  1643. //
  1644. // Returns: See the win32 API definition
  1645. //
  1646. // History: quintinb Created 6/24/99
  1647. //
  1648. //+----------------------------------------------------------------------------
  1649. HANDLE WINAPI LoadImageAU(IN HINSTANCE hInst, IN LPCWSTR pszwName, IN UINT uType, IN int cxDesired,
  1650. IN int cyDesired, IN UINT fuLoad)
  1651. {
  1652. HANDLE hReturn = NULL;
  1653. MYDBGASSERT(hInst || (LR_LOADFROMFILE & fuLoad)); // we don't support loading OEM images -- implement it if you need it.
  1654. if (pszwName)
  1655. {
  1656. CHAR szAnsiName [MAX_PATH+1];
  1657. LPSTR pszAnsiName;
  1658. if (0 == HIWORD(pszwName))
  1659. {
  1660. pszAnsiName = LPSTR(pszwName);
  1661. }
  1662. else
  1663. {
  1664. pszAnsiName = szAnsiName;
  1665. int iChars = WzToSz(pszwName, pszAnsiName, MAX_PATH);
  1666. if (!iChars || (MAX_PATH < iChars))
  1667. {
  1668. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1669. goto exit;
  1670. }
  1671. }
  1672. hReturn = LoadImageA(hInst, pszAnsiName, uType, cxDesired, cyDesired, fuLoad);
  1673. }
  1674. exit:
  1675. return hReturn;
  1676. }
  1677. //+----------------------------------------------------------------------------
  1678. //
  1679. // Function: LoadLibraryExAU
  1680. //
  1681. // Synopsis: Unicode to Ansi wrapper for the win32 LoadLibraryEx API. Note that
  1682. // we expect the library name to fit in MAX_PATH ANSI chars.
  1683. //
  1684. // Arguments: See the win32 API definition
  1685. //
  1686. // Returns: See the win32 API definition
  1687. //
  1688. // History: quintinb Created 6/24/99
  1689. //
  1690. //+----------------------------------------------------------------------------
  1691. HMODULE WINAPI LoadLibraryExAU(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
  1692. {
  1693. CHAR pszLibFileName[MAX_PATH+1];
  1694. HMODULE hReturn = NULL;
  1695. if (lpLibFileName && (NULL == hFile)) // hFile is reserved, it must be NULL
  1696. {
  1697. if(WzToSz(lpLibFileName, pszLibFileName, MAX_PATH))
  1698. {
  1699. hReturn = LoadLibraryExA(pszLibFileName, hFile, dwFlags);
  1700. }
  1701. }
  1702. return hReturn;
  1703. }
  1704. //+----------------------------------------------------------------------------
  1705. //
  1706. // Function: LoadMenuAU
  1707. //
  1708. // Synopsis: Unicode to Ansi wrapper for the win32 LoadMenu API. Note that
  1709. // lpMenuName could be a string or it could be a resource ID from
  1710. // MAKEINTRESOURCE. We assume the menu name will fit in MAX_PATH
  1711. // chars if it is a string.
  1712. //
  1713. // Arguments: See the win32 API definition
  1714. //
  1715. // Returns: See the win32 API definition
  1716. //
  1717. // History: quintinb Created 6/24/99
  1718. //
  1719. //+----------------------------------------------------------------------------
  1720. HMENU WINAPI LoadMenuAU(IN HINSTANCE hInstance, IN LPCWSTR lpMenuName)
  1721. {
  1722. HMENU hMenuReturn = NULL;
  1723. LPSTR pszAnsiMenuName;
  1724. CHAR szAnsiMenuName[MAX_PATH+1];
  1725. if (hInstance && lpMenuName)
  1726. {
  1727. if (HIWORD(lpMenuName))
  1728. {
  1729. pszAnsiMenuName = szAnsiMenuName;
  1730. int iChars = WzToSz(lpMenuName, pszAnsiMenuName, MAX_PATH);
  1731. if (!iChars || (MAX_PATH < iChars))
  1732. {
  1733. goto exit;
  1734. }
  1735. }
  1736. else
  1737. {
  1738. pszAnsiMenuName = (LPSTR)lpMenuName;
  1739. }
  1740. hMenuReturn = LoadMenuA(hInstance, pszAnsiMenuName);
  1741. }
  1742. exit:
  1743. return hMenuReturn;
  1744. }
  1745. //+----------------------------------------------------------------------------
  1746. //
  1747. // Function: LoadStringAU
  1748. //
  1749. // Synopsis: Unicode to Ansi wrapper for the win32 LoadString API.
  1750. //
  1751. // Arguments: See the win32 API definition
  1752. //
  1753. // Returns: See the win32 API definition
  1754. //
  1755. // History: quintinb Created 6/24/99
  1756. //
  1757. //+----------------------------------------------------------------------------
  1758. int WINAPI LoadStringAU(HINSTANCE hInstance, UINT uID, LPWSTR lpBuffer, int nBufferMax)
  1759. {
  1760. int iReturn = 0;
  1761. if (uID && hInstance) // lpBuffer and nBufferMax could be Zero
  1762. {
  1763. LPSTR pszAnsiBuffer = nBufferMax ? (LPSTR)CmMalloc(nBufferMax*sizeof(CHAR)) : NULL;
  1764. if (pszAnsiBuffer || (0 == nBufferMax))
  1765. {
  1766. iReturn = LoadStringA(hInstance, uID, pszAnsiBuffer, nBufferMax);
  1767. if (lpBuffer && iReturn && (iReturn <= nBufferMax))
  1768. {
  1769. if (!SzToWz(pszAnsiBuffer, lpBuffer, nBufferMax))
  1770. {
  1771. iReturn = 0;
  1772. }
  1773. }
  1774. }
  1775. CmFree(pszAnsiBuffer);
  1776. }
  1777. CMASSERTMSG(iReturn, TEXT("LoadStringAU Failed."));
  1778. return iReturn;
  1779. }
  1780. //+----------------------------------------------------------------------------
  1781. //
  1782. // Function: lstrcatAU
  1783. //
  1784. // Synopsis: Unicode to Ansi wrapper for the win32 lstrcat API. Note that we
  1785. // use wcscat instead of doing a conversion from Unicode to ANSI,
  1786. // then using lstrcatA, and then converting back to Unicode again.
  1787. // That seemed like a lot of effort when wcscat should work just fine.
  1788. //
  1789. // Arguments: See the win32 API definition
  1790. //
  1791. // Returns: See the win32 API definition
  1792. //
  1793. // History: quintinb Created 6/24/99
  1794. //
  1795. //+----------------------------------------------------------------------------
  1796. LPWSTR WINAPI lstrcatAU(IN OUT LPWSTR lpString1, IN LPCWSTR lpString2)
  1797. {
  1798. if (lpString2 && lpString2)
  1799. {
  1800. return wcscat(lpString1, lpString2);
  1801. }
  1802. else
  1803. {
  1804. CMASSERTMSG(FALSE, TEXT("NULL String passed to lstrcatAU"));
  1805. return lpString1;
  1806. }
  1807. }
  1808. //+----------------------------------------------------------------------------
  1809. //
  1810. // Function: lstrcmpAU
  1811. //
  1812. // Synopsis: Unicode to Ansi wrapper for the win32 lstrcmp API. Note that we
  1813. // use wcscmp instead of doing a conversion from Unicode to ANSI,
  1814. // then using lstrcmpA, and then converting back to Unicode again.
  1815. // That seemed like a lot of effort when wcscmp should work just fine.
  1816. //
  1817. // Arguments: See the win32 API definition
  1818. //
  1819. // Returns: See the win32 API definition
  1820. //
  1821. // History: quintinb Created 6/24/99
  1822. //
  1823. //+----------------------------------------------------------------------------
  1824. int WINAPI lstrcmpAU(IN LPCWSTR lpString1, IN LPCWSTR lpString2)
  1825. {
  1826. if (lpString1 && lpString2)
  1827. {
  1828. return wcscmp(lpString1, lpString2);
  1829. }
  1830. else
  1831. {
  1832. CMASSERTMSG(FALSE, TEXT("NULL String passed to lstrcmpAU"));
  1833. //
  1834. // Wasn't exactly sure what to do on failure since their isn't a failure
  1835. // return value from lstrcmp. I looked at the current implementation
  1836. // and they do something like the following.
  1837. //
  1838. if (lpString1)
  1839. {
  1840. return 1;
  1841. }
  1842. else if (lpString2)
  1843. {
  1844. return -1;
  1845. }
  1846. else
  1847. {
  1848. return 0;
  1849. }
  1850. }
  1851. }
  1852. //+----------------------------------------------------------------------------
  1853. //
  1854. // Function: lstrcmpiAU
  1855. //
  1856. // Synopsis: Unicode to Ansi wrapper for the win32 lstrcmpi API. Note that we
  1857. // use _wcsicmp instead of doing a conversion from Unicode to ANSI,
  1858. // then using lstrcmpiA, and then converting back to Unicode again.
  1859. // That seemed like a lot of effort when _wcsicmp should work just fine.
  1860. //
  1861. // Arguments: See the win32 API definition
  1862. //
  1863. // Returns: See the win32 API definition
  1864. //
  1865. // History: quintinb Created 6/24/99
  1866. //
  1867. //+----------------------------------------------------------------------------
  1868. int WINAPI lstrcmpiAU(IN LPCWSTR lpString1, IN LPCWSTR lpString2)
  1869. {
  1870. if (lpString1 && lpString2)
  1871. {
  1872. return _wcsicmp(lpString1, lpString2);
  1873. }
  1874. else
  1875. {
  1876. CMASSERTMSG(FALSE, TEXT("NULL String passed to lstrcmpiAU"));
  1877. //
  1878. // Wasn't exactly sure what to do on failure since their isn't a failure
  1879. // return value from lstrcmp. I looked at the current implementation
  1880. // and they do something like the following.
  1881. //
  1882. if (lpString1)
  1883. {
  1884. return 1;
  1885. }
  1886. else if (lpString2)
  1887. {
  1888. return -1;
  1889. }
  1890. else
  1891. {
  1892. return 0;
  1893. }
  1894. }
  1895. }
  1896. //+----------------------------------------------------------------------------
  1897. //
  1898. // Function: lstrcpyAU
  1899. //
  1900. // Synopsis: Unicode to Ansi wrapper for the win32 lstrcpy API. Note that we
  1901. // use wcscpy instead of doing a conversion from Unicode to ANSI,
  1902. // then using lstrcpyA, and then converting back to Unicode again.
  1903. // That seemed like a lot of effort when wcscpy should work just fine.
  1904. //
  1905. // Arguments: See the win32 API definition
  1906. //
  1907. // Returns: See the win32 API definition
  1908. //
  1909. // History: quintinb Created 6/24/99
  1910. //
  1911. //+----------------------------------------------------------------------------
  1912. LPWSTR WINAPI lstrcpyAU(OUT LPWSTR pszDest, IN LPCWSTR pszSource)
  1913. {
  1914. if (pszDest && pszSource)
  1915. {
  1916. return wcscpy(pszDest, pszSource);
  1917. }
  1918. else
  1919. {
  1920. CMASSERTMSG(FALSE, TEXT("NULL String passed to lstrcpyAU"));
  1921. return pszDest;
  1922. }
  1923. }
  1924. //+----------------------------------------------------------------------------
  1925. //
  1926. // Function: lstrcpynAU
  1927. //
  1928. // Synopsis: Unicode to Ansi wrapper for the win32 lstrcpyn API. Note that we
  1929. // use wcsncpy instead of doing a conversion from Unicode to ANSI,
  1930. // then using lstrcpynA, and then converting back to Unicode again.
  1931. // That seemed like a lot of effort when wcsncpy should work just fine.
  1932. //
  1933. // Arguments: See the win32 API definition
  1934. //
  1935. // Returns: See the win32 API definition
  1936. //
  1937. // History: quintinb Created 6/24/99
  1938. //
  1939. //+----------------------------------------------------------------------------
  1940. LPWSTR WINAPI lstrcpynAU(OUT LPWSTR pszDest, IN LPCWSTR pszSource, IN int iMaxLength)
  1941. {
  1942. if (pszDest && pszSource && iMaxLength)
  1943. {
  1944. LPWSTR pszReturn = wcsncpy(pszDest, pszSource, iMaxLength);
  1945. //
  1946. // wcsncpy and lstrcpy behave differently about terminating NULL
  1947. // characters. The last char in the lstrcpyn buffer always gets
  1948. // a TEXT('\0'), whereas wcsncpy doesn't do this. Thus we must
  1949. // NULL the last char before returning.
  1950. //
  1951. pszDest[iMaxLength-1] = TEXT('\0');
  1952. return pszReturn;
  1953. }
  1954. else
  1955. {
  1956. CMASSERTMSG(FALSE, TEXT("Invalid parameter passed to lstrcpynAU"));
  1957. return pszDest;
  1958. }
  1959. }
  1960. //+----------------------------------------------------------------------------
  1961. //
  1962. // Function: lstrlenAU
  1963. //
  1964. // Synopsis: Unicode to Ansi wrapper for the win32 lstrlen API. Note that we
  1965. // use wcslen instead of doing a conversion from Unicode to ANSI,
  1966. // then using lstrlenA, and then converting back to Unicode again.
  1967. // That seemed like a lot of effort when wcslen should work just fine.
  1968. //
  1969. // Arguments: See the win32 API definition
  1970. //
  1971. // Returns: See the win32 API definition
  1972. //
  1973. // History: quintinb Created 6/24/99
  1974. //
  1975. //+----------------------------------------------------------------------------
  1976. int WINAPI lstrlenAU(IN LPCWSTR lpString)
  1977. {
  1978. if (lpString)
  1979. {
  1980. return wcslen(lpString);
  1981. }
  1982. else
  1983. {
  1984. // CMASSERTMSG(FALSE, TEXT("NULL String passed to lstrlenAU"));
  1985. return 0;
  1986. }
  1987. }
  1988. //+----------------------------------------------------------------------------
  1989. //
  1990. // Function: OpenEventAU
  1991. //
  1992. // Synopsis: Unicode to Ansi wrapper for the win32 OpenEvent API.
  1993. //
  1994. // Arguments: See the win32 API definition
  1995. //
  1996. // Returns: See the win32 API definition
  1997. //
  1998. // History: quintinb Created 6/24/99
  1999. //
  2000. //+----------------------------------------------------------------------------
  2001. HANDLE WINAPI OpenEventAU(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
  2002. {
  2003. HANDLE hReturn = NULL;
  2004. if (lpName)
  2005. {
  2006. LPSTR pszAnsiName = WzToSzWithAlloc(lpName);
  2007. if (pszAnsiName)
  2008. {
  2009. hReturn = OpenEventA(dwDesiredAccess, bInheritHandle, pszAnsiName);
  2010. }
  2011. CmFree(pszAnsiName);
  2012. }
  2013. return hReturn;
  2014. }
  2015. //+----------------------------------------------------------------------------
  2016. //
  2017. // Function: OpenFileMappingAU
  2018. //
  2019. // Synopsis: Unicode to Ansi wrapper for the win32 OpenFileMapping API.
  2020. //
  2021. // Arguments: See the win32 API definition
  2022. //
  2023. // Returns: See the win32 API definition
  2024. //
  2025. // History: quintinb Created 6/24/99
  2026. //
  2027. //+----------------------------------------------------------------------------
  2028. HANDLE WINAPI OpenFileMappingAU(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
  2029. {
  2030. HANDLE hReturn = NULL;
  2031. if (lpName)
  2032. {
  2033. LPSTR pszAnsiName = WzToSzWithAlloc(lpName);
  2034. if (pszAnsiName)
  2035. {
  2036. hReturn = OpenFileMappingA(dwDesiredAccess, bInheritHandle, pszAnsiName);
  2037. }
  2038. CmFree(pszAnsiName);
  2039. }
  2040. return hReturn;
  2041. }
  2042. //+----------------------------------------------------------------------------
  2043. //
  2044. // Function: RegCreateKeyExAU
  2045. //
  2046. // Synopsis: Unicode to Ansi wrapper for the win32 RegCreateKeyEx API.
  2047. //
  2048. // Arguments: See the win32 API definition
  2049. //
  2050. // Returns: See the win32 API definition
  2051. //
  2052. // History: quintinb Created 6/24/99
  2053. //
  2054. //+----------------------------------------------------------------------------
  2055. LONG APIENTRY RegCreateKeyExAU(IN HKEY hKey, IN LPCWSTR lpSubKey, IN DWORD Reserved, IN LPWSTR lpClass,
  2056. IN DWORD dwOptions, IN REGSAM samDesired, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  2057. OUT PHKEY phkResult, OUT LPDWORD lpdwDisposition)
  2058. {
  2059. LONG lReturn = ERROR_INVALID_PARAMETER;
  2060. if (lpSubKey)
  2061. {
  2062. LPSTR pszAnsiSubKey = WzToSzWithAlloc(lpSubKey);
  2063. LPSTR pszAnsiClass = lpClass ? WzToSzWithAlloc(lpClass) : NULL;
  2064. if (pszAnsiSubKey && (pszAnsiClass || !lpClass))
  2065. {
  2066. lReturn = RegCreateKeyExA(hKey, pszAnsiSubKey, Reserved, pszAnsiClass,
  2067. dwOptions, samDesired, lpSecurityAttributes,
  2068. phkResult, lpdwDisposition);
  2069. }
  2070. else
  2071. {
  2072. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2073. }
  2074. CmFree(pszAnsiSubKey);
  2075. CmFree(pszAnsiClass);
  2076. }
  2077. CMASSERTMSG(ERROR_SUCCESS == lReturn, TEXT("RegCreateKeyExAU Failed."));
  2078. return lReturn;
  2079. }
  2080. //+----------------------------------------------------------------------------
  2081. //
  2082. // Function: RegDeleteKeyAU
  2083. //
  2084. // Synopsis: Unicode to Ansi wrapper for the win32 RegDeleteKey API.
  2085. //
  2086. // Arguments: See the win32 API definition
  2087. //
  2088. // Returns: See the win32 API definition
  2089. //
  2090. // History: quintinb Created 6/24/99
  2091. //
  2092. //+----------------------------------------------------------------------------
  2093. LONG APIENTRY RegDeleteKeyAU(IN HKEY hKey, IN LPCWSTR lpSubKey)
  2094. {
  2095. LONG lReturn = ERROR_INVALID_PARAMETER;
  2096. if (lpSubKey)
  2097. {
  2098. LPSTR pszAnsiSubKey = WzToSzWithAlloc(lpSubKey);
  2099. if (pszAnsiSubKey)
  2100. {
  2101. lReturn = RegDeleteKeyA(hKey, pszAnsiSubKey);
  2102. }
  2103. else
  2104. {
  2105. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2106. }
  2107. CmFree(pszAnsiSubKey);
  2108. }
  2109. CMASSERTMSG(ERROR_SUCCESS == lReturn, TEXT("RegDeleteKeyAU Failed."));
  2110. return lReturn;
  2111. }
  2112. //+----------------------------------------------------------------------------
  2113. //
  2114. // Function: RegDeleteValueAU
  2115. //
  2116. // Synopsis: Unicode to Ansi wrapper for the win32 RegDeleteValue API.
  2117. //
  2118. // Arguments: See the win32 API definition
  2119. //
  2120. // Returns: See the win32 API definition
  2121. //
  2122. // History: quintinb Created 6/24/99
  2123. //
  2124. //+----------------------------------------------------------------------------
  2125. LONG APIENTRY RegDeleteValueAU(IN HKEY hKey, IN LPCWSTR lpValueName)
  2126. {
  2127. LONG lReturn = ERROR_INVALID_PARAMETER;
  2128. if (lpValueName)
  2129. {
  2130. LPSTR pszAnsiValueName = WzToSzWithAlloc(lpValueName);
  2131. if (pszAnsiValueName)
  2132. {
  2133. lReturn = RegDeleteValueA(hKey, pszAnsiValueName);
  2134. CmFree(pszAnsiValueName);
  2135. }
  2136. else
  2137. {
  2138. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2139. }
  2140. }
  2141. return lReturn;
  2142. }
  2143. //+----------------------------------------------------------------------------
  2144. //
  2145. // Function: RegEnumKeyExAU
  2146. //
  2147. // Synopsis: Unicode to Ansi wrapper for the win32 RegEnumKeyEx API.
  2148. //
  2149. // Arguments: See the win32 API definition
  2150. //
  2151. // Returns: See the win32 API definition
  2152. //
  2153. // History: quintinb Created 6/24/99
  2154. //
  2155. //+----------------------------------------------------------------------------
  2156. LONG RegEnumKeyExAU(IN HKEY hKey, IN DWORD dwIndex, OUT LPWSTR lpName, IN OUT LPDWORD lpcbName, IN LPDWORD lpReserved, IN OUT LPWSTR lpClass, IN OUT LPDWORD lpcbClass, OUT PFILETIME lpftLastWriteTime)
  2157. {
  2158. LONG lReturn = ERROR_INVALID_PARAMETER;
  2159. if (lpcbName)
  2160. {
  2161. MYDBGASSERT((lpName && *lpcbName) || ((NULL == lpName) && (0 == *lpcbName)));
  2162. LPSTR pszAnsiClass = lpClass ? WzToSzWithAlloc(lpClass) : NULL;
  2163. LPSTR pszTmpBuffer = lpName ? (LPSTR)CmMalloc(*lpcbName) : NULL;
  2164. DWORD dwSizeTmp = lpName ? *lpcbName : 0;
  2165. if (pszTmpBuffer || (NULL == lpName))
  2166. {
  2167. lReturn = RegEnumKeyExA(hKey, dwIndex, pszTmpBuffer, &dwSizeTmp, lpReserved, pszAnsiClass, lpcbClass, lpftLastWriteTime);
  2168. if ((ERROR_SUCCESS == lReturn) && pszTmpBuffer)
  2169. {
  2170. if (!SzToWz(pszTmpBuffer, lpName, (*lpcbName)))
  2171. {
  2172. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2173. }
  2174. else
  2175. {
  2176. *lpcbName = (lstrlenAU((WCHAR*)lpName) + 1);
  2177. }
  2178. }
  2179. }
  2180. else
  2181. {
  2182. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2183. }
  2184. CmFree(pszTmpBuffer);
  2185. }
  2186. return lReturn;
  2187. }
  2188. //+----------------------------------------------------------------------------
  2189. //
  2190. // Function: RegisterClassExAU
  2191. //
  2192. // Synopsis: Unicode to Ansi wrapper for the win32 RegisterClassEx API. Note
  2193. // that we don't deal with the lpszMenuName parameter. If this is
  2194. // needed then conversion code will have to be written.
  2195. //
  2196. // Arguments: See the win32 API definition
  2197. //
  2198. // Returns: See the win32 API definition
  2199. //
  2200. // History: quintinb Created 6/24/99
  2201. //
  2202. //+----------------------------------------------------------------------------
  2203. ATOM WINAPI RegisterClassExAU(CONST WNDCLASSEXW *lpWcw)
  2204. {
  2205. WNDCLASSEXA wca;
  2206. CHAR szClassName[MAX_PATH];
  2207. ATOM ReturnAtom = 0;
  2208. if (lpWcw->lpszClassName)
  2209. {
  2210. if (WzToSz(lpWcw->lpszClassName, szClassName, MAX_PATH))
  2211. {
  2212. wca.cbSize = sizeof(WNDCLASSEXA);
  2213. wca.lpfnWndProc = lpWcw->lpfnWndProc;
  2214. wca.style = lpWcw->style;
  2215. wca.cbClsExtra = lpWcw->cbClsExtra;
  2216. wca.cbWndExtra = lpWcw->cbWndExtra;
  2217. wca.hInstance = lpWcw->hInstance;
  2218. wca.hIcon = lpWcw->hIcon;
  2219. wca.hCursor = lpWcw->hCursor;
  2220. wca.hbrBackground = lpWcw->hbrBackground;
  2221. wca.hIconSm = lpWcw->hIconSm;
  2222. wca.lpszClassName = szClassName;
  2223. MYDBGASSERT(NULL == lpWcw->lpszMenuName);
  2224. wca.lpszMenuName = NULL;
  2225. //
  2226. // Now register the class.
  2227. //
  2228. ReturnAtom = RegisterClassExA(&wca);
  2229. if (0 == ReturnAtom)
  2230. {
  2231. //
  2232. // We want to assert failure unless we failed because the class
  2233. // was already registered. This can happen if something
  2234. // calls two CM entry points without exiting first. A prime
  2235. // example of this is rasrcise.exe. Unfortunately, GetLastError()
  2236. // returns 0 when we try to register the class twice. Thus I
  2237. // will only assert if the ReturnAtom is 0 and dwError is non-zero.
  2238. //
  2239. DWORD dwError = GetLastError();
  2240. CMASSERTMSG(!dwError, TEXT("RegisterClassExAU Failed."));
  2241. }
  2242. }
  2243. }
  2244. return ReturnAtom;
  2245. }
  2246. //+----------------------------------------------------------------------------
  2247. //
  2248. // Function: RegisterWindowMessageAU
  2249. //
  2250. // Synopsis: Unicode to Ansi wrapper for the win32 RegisterWindowMessage API. Note
  2251. // that we expect the message name to fit within MAX_PATH characters.
  2252. //
  2253. // Arguments: See the win32 API definition
  2254. //
  2255. // Returns: See the win32 API definition
  2256. //
  2257. // History: quintinb Created 6/24/99
  2258. //
  2259. //+----------------------------------------------------------------------------
  2260. UINT WINAPI RegisterWindowMessageAU(IN LPCWSTR lpString)
  2261. {
  2262. UINT uReturn = 0;
  2263. if (lpString)
  2264. {
  2265. MYDBGASSERT(MAX_PATH > lstrlenAU(lpString));
  2266. CHAR szAnsiString [MAX_PATH+1];
  2267. if (WzToSz(lpString, szAnsiString, MAX_PATH))
  2268. {
  2269. uReturn = RegisterWindowMessageA(szAnsiString);
  2270. }
  2271. }
  2272. return uReturn;
  2273. }
  2274. //+----------------------------------------------------------------------------
  2275. //
  2276. // Function: RegOpenKeyExAU
  2277. //
  2278. // Synopsis: Unicode to Ansi wrapper for the win32 RegOpenKeyEx API.
  2279. //
  2280. // Arguments: See the win32 API definition
  2281. //
  2282. // Returns: See the win32 API definition
  2283. //
  2284. // History: quintinb Created 6/24/99
  2285. //
  2286. //+----------------------------------------------------------------------------
  2287. LONG APIENTRY RegOpenKeyExAU(IN HKEY hKey, IN LPCWSTR lpSubKey, IN DWORD ulOptions,
  2288. IN REGSAM samDesired, OUT PHKEY phkResult)
  2289. {
  2290. LONG lReturn = ERROR_INVALID_PARAMETER;
  2291. if (lpSubKey)
  2292. {
  2293. LPSTR pszAnsiSubKey = WzToSzWithAlloc(lpSubKey);
  2294. if (pszAnsiSubKey)
  2295. {
  2296. lReturn = RegOpenKeyExA(hKey, pszAnsiSubKey, ulOptions, samDesired, phkResult);
  2297. }
  2298. else
  2299. {
  2300. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2301. }
  2302. CmFree(pszAnsiSubKey);
  2303. }
  2304. // CMASSERTMSG(ERROR_SUCCESS == lReturn, TEXT("RegOpenKeyExAU Failed."));
  2305. return lReturn;
  2306. }
  2307. //+----------------------------------------------------------------------------
  2308. //
  2309. // Function: RegQueryValueExAU
  2310. //
  2311. // Synopsis: Unicode to Ansi wrapper for the win32 RegQueryValueEx API. Note that
  2312. // we don't handle the REG_MULTI_SZ type. We would have to have
  2313. // special code to handle it and we currently don't need it. Be careful
  2314. // modifying this function unless you have read and thoroughly understood
  2315. // all of the comments.
  2316. //
  2317. // Arguments: See the win32 API definition
  2318. //
  2319. // Returns: See the win32 API definition
  2320. //
  2321. // History: quintinb Created 6/24/99
  2322. //
  2323. //+----------------------------------------------------------------------------
  2324. LONG APIENTRY RegQueryValueExAU(IN HKEY hKey, IN LPCWSTR lpValueName, IN LPDWORD lpReserved,
  2325. OUT LPDWORD lpType, IN OUT LPBYTE lpData, IN OUT LPDWORD lpcbData)
  2326. {
  2327. LONG lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2328. //
  2329. // lpValueName could be NULL or it could be "". In either case they are after the default
  2330. // entry so just pass NULL (don't convert "").
  2331. //
  2332. LPSTR pszAnsiValueName = (lpValueName && lpValueName[0]) ? WzToSzWithAlloc(lpValueName) : NULL;
  2333. if (pszAnsiValueName || !lpValueName || (TEXT('\0') == lpValueName[0]))
  2334. {
  2335. //
  2336. // lpData could also be NULL, they may not actually want the value just to see if it exists
  2337. //
  2338. LPSTR pszTmpBuffer = lpData ? (LPSTR)CmMalloc(*lpcbData) : NULL;
  2339. if (pszTmpBuffer || !lpData)
  2340. {
  2341. DWORD dwTemp = *lpcbData; // we don't want the original value overwritten
  2342. lReturn = RegQueryValueExA(hKey, pszAnsiValueName, lpReserved, lpType,
  2343. (LPBYTE)pszTmpBuffer, &dwTemp);
  2344. if ((ERROR_SUCCESS == lReturn) && pszTmpBuffer)
  2345. {
  2346. if ((REG_SZ == *lpType) || (REG_EXPAND_SZ == *lpType))
  2347. {
  2348. if (!SzToWz(pszTmpBuffer, (WCHAR*)lpData, (*lpcbData)/sizeof(WCHAR)))
  2349. {
  2350. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2351. }
  2352. else
  2353. {
  2354. *lpcbData = (lstrlenAU((WCHAR*)lpData) + 1) * sizeof(WCHAR);
  2355. }
  2356. }
  2357. else if (REG_MULTI_SZ == *lpType)
  2358. {
  2359. //
  2360. // We currently don't have the parsing logic to convert a Multi_SZ.
  2361. // Since CM doesn't query any keys that return this type, this shouldn't
  2362. // be a problem. However, someday we may need to fill in this code. For
  2363. // now, just assert.
  2364. //
  2365. CMASSERTMSG(FALSE, TEXT("RegQueryValueExAU -- Converion and Parsing code for REG_MULTI_SZ UNIMPLEMENTED."));
  2366. lReturn = ERROR_CALL_NOT_IMPLEMENTED; // closest I could find to E_NOTIMPL
  2367. }
  2368. else
  2369. {
  2370. //
  2371. // Non - text data, nothing to convert so just copy it over
  2372. //
  2373. *lpcbData = dwTemp;
  2374. memcpy(lpData, pszTmpBuffer, dwTemp);
  2375. }
  2376. }
  2377. else
  2378. {
  2379. *lpcbData = dwTemp;
  2380. }
  2381. CmFree (pszTmpBuffer);
  2382. }
  2383. }
  2384. CmFree(pszAnsiValueName);
  2385. // CMASSERTMSG(ERROR_SUCCESS == lReturn, TEXT("RegOpenKeyExAU Failed."));
  2386. return lReturn;
  2387. }
  2388. //+----------------------------------------------------------------------------
  2389. //
  2390. // Function: RegSetValueExAU
  2391. //
  2392. // Synopsis: Unicode to Ansi wrapper for the win32 RegSetValueEx API. Note that
  2393. // this wrapper doesn't support writing REG_MULTI_SZ, this code will
  2394. // have to be implemented if we ever need it.
  2395. //
  2396. // Arguments: See the win32 API definition
  2397. //
  2398. // Returns: See the win32 API definition
  2399. //
  2400. // History: quintinb Created 6/24/99
  2401. //
  2402. //+----------------------------------------------------------------------------
  2403. LONG APIENTRY RegSetValueExAU(IN HKEY hKey, IN LPCWSTR lpValueName, IN DWORD Reserved,
  2404. IN DWORD dwType, IN CONST BYTE* lpData, IN DWORD cbData)
  2405. {
  2406. LONG lReturn = ERROR_INVALID_PARAMETER;
  2407. if (lpData)
  2408. {
  2409. LPSTR pszAnsiValueName = (lpValueName && lpValueName[0]) ? WzToSzWithAlloc(lpValueName) : NULL;
  2410. LPSTR pszTmpData = NULL;
  2411. DWORD dwTmpCbData;
  2412. if (pszAnsiValueName || !lpValueName || (TEXT('\0') == lpValueName[0]))
  2413. {
  2414. if ((REG_EXPAND_SZ == dwType) || (REG_SZ == dwType))
  2415. {
  2416. pszTmpData = WzToSzWithAlloc((WCHAR*)lpData);
  2417. if (pszTmpData)
  2418. {
  2419. dwTmpCbData = lstrlenA(pszTmpData) + 1;
  2420. }
  2421. else
  2422. {
  2423. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2424. }
  2425. }
  2426. else if (REG_MULTI_SZ == dwType)
  2427. {
  2428. // We currently don't have the parsing logic to convert a Multi_SZ.
  2429. // Since CM doesn't set any keys that use this type, this shouldn't
  2430. // be a problem. However, someday we may need to fill in this code. For
  2431. // now, just assert.
  2432. //
  2433. CMASSERTMSG(FALSE, TEXT("RegSetValueExAU -- Converion and Parsing code for REG_MULTI_SZ UNIMPLEMENTED."));
  2434. lReturn = ERROR_CALL_NOT_IMPLEMENTED; // closest I could find to E_NOTIMPL
  2435. }
  2436. else
  2437. {
  2438. //
  2439. // No text data, leave the buffer alone
  2440. //
  2441. pszTmpData = (LPSTR)lpData;
  2442. dwTmpCbData = cbData;
  2443. }
  2444. if (pszTmpData)
  2445. {
  2446. lReturn = RegSetValueExA(hKey, pszAnsiValueName, Reserved, dwType,
  2447. (LPBYTE)pszTmpData, dwTmpCbData);
  2448. if ((REG_EXPAND_SZ == dwType) || (REG_SZ == dwType))
  2449. {
  2450. CmFree(pszTmpData);
  2451. }
  2452. }
  2453. CmFree(pszAnsiValueName);
  2454. }
  2455. else
  2456. {
  2457. lReturn = ERROR_NOT_ENOUGH_MEMORY;
  2458. }
  2459. }
  2460. return lReturn;
  2461. }
  2462. //+----------------------------------------------------------------------------
  2463. //
  2464. // Function: SearchPathAU
  2465. //
  2466. // Synopsis: Unicode to Ansi wrapper for the win32 SearchPath API. Note that
  2467. // this wrapper uses wcsrchr to fix up the lpFilePart parameter in
  2468. // the converted return buffer.
  2469. //
  2470. // Arguments: See the win32 API definition
  2471. //
  2472. // Returns: See the win32 API definition
  2473. //
  2474. // History: quintinb Created 6/24/99
  2475. //
  2476. //+----------------------------------------------------------------------------
  2477. DWORD WINAPI SearchPathAU(IN LPCWSTR lpPath, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension,
  2478. IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
  2479. {
  2480. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  2481. if (lpFileName && (L'\0' != lpFileName[0]))
  2482. {
  2483. CHAR szAnsiPath[MAX_PATH+1];
  2484. CHAR szAnsiFileName[MAX_PATH+1];
  2485. CHAR szAnsiExt[MAX_PATH+1];
  2486. LPSTR pszAnsiPath;
  2487. LPSTR pszAnsiExt;
  2488. int iChars;
  2489. //
  2490. // Convert the path if it exists
  2491. //
  2492. if (lpPath && (L'\0' != lpPath[0]))
  2493. {
  2494. pszAnsiPath = szAnsiPath;
  2495. MYVERIFY(0 != WzToSz(lpPath, pszAnsiPath, MAX_PATH));
  2496. }
  2497. else
  2498. {
  2499. pszAnsiPath = NULL;
  2500. }
  2501. //
  2502. // Convert the extension if it exists
  2503. //
  2504. if (lpExtension && (L'\0' != lpExtension[0]))
  2505. {
  2506. pszAnsiExt = szAnsiExt;
  2507. MYVERIFY(0 != WzToSz(lpExtension, pszAnsiExt, MAX_PATH));
  2508. }
  2509. else
  2510. {
  2511. pszAnsiExt = NULL;
  2512. }
  2513. //
  2514. // Convert the file name, which must exist
  2515. //
  2516. iChars = WzToSz(lpFileName, szAnsiFileName, MAX_PATH);
  2517. if (iChars && (MAX_PATH >= iChars))
  2518. {
  2519. LPSTR pszAnsiBuffer = (LPSTR)CmMalloc(nBufferLength);
  2520. if (pszAnsiBuffer)
  2521. {
  2522. dwReturn = SearchPathA(pszAnsiPath, szAnsiFileName, pszAnsiExt, nBufferLength,
  2523. pszAnsiBuffer, NULL);
  2524. if (dwReturn && lpBuffer)
  2525. {
  2526. //
  2527. // We have a successful search. Now convert the output buffer
  2528. //
  2529. iChars = SzToWz(pszAnsiBuffer, lpBuffer, nBufferLength);
  2530. if (!iChars || (nBufferLength < (DWORD)iChars))
  2531. {
  2532. dwReturn = ERROR_NOT_ENOUGH_MEMORY;
  2533. }
  2534. else
  2535. {
  2536. //
  2537. // Fix up lpFilePart
  2538. //
  2539. if (lpFilePart)
  2540. {
  2541. //
  2542. // Find the last slash
  2543. //
  2544. *lpFilePart = wcsrchr(lpBuffer, L'\\');
  2545. if (*lpFilePart)
  2546. {
  2547. //
  2548. // Increment
  2549. //
  2550. (*lpFilePart)++;
  2551. }
  2552. }
  2553. }
  2554. }
  2555. CmFree(pszAnsiBuffer);
  2556. }
  2557. }
  2558. }
  2559. return dwReturn;
  2560. }
  2561. //+----------------------------------------------------------------------------
  2562. //
  2563. // Function: SendDlgItemMessageAU
  2564. //
  2565. // Synopsis: Unicode to Ansi wrapper for the win32 SendDlgItemMessage API. Note that
  2566. // this wrapper uses GetDlgItem and SendMessage just as the Win32
  2567. // implementation of the API does.
  2568. //
  2569. // Arguments: See the win32 API definition
  2570. //
  2571. // Returns: See the win32 API definition
  2572. //
  2573. // History: quintinb Created 6/24/99
  2574. //
  2575. //+----------------------------------------------------------------------------
  2576. LONG_PTR WINAPI SendDlgItemMessageAU(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam)
  2577. {
  2578. LONG lReturn = 0;
  2579. HWND hWnd = GetDlgItem(hDlg, nIDDlgItem);
  2580. if (hWnd)
  2581. {
  2582. //
  2583. // Rather than going through SendDlgItemMessageA, we just
  2584. // do what the system does, i.e., go through
  2585. // SendMessage
  2586. //
  2587. lReturn = SendMessageAU(hWnd, Msg, wParam, lParam);
  2588. }
  2589. return lReturn;
  2590. }
  2591. //+----------------------------------------------------------------------------
  2592. //
  2593. // Function: SendMessageAU
  2594. //
  2595. // Synopsis: Unicode to Ansi wrapper for the win32 SendMessage API. This
  2596. // wrapper attempts to handle all of the Windows Messages that
  2597. // need conversion, either before the message is sent or after it
  2598. // returns. Obviously this is an inexact science. I have checked
  2599. // and tested all of the message types currently in CM but new ones
  2600. // may be added at some point. I owe much of this function to
  2601. // F. Avery Bishop and his sample code.
  2602. //
  2603. // Arguments: See the win32 API definition
  2604. //
  2605. // Returns: See the win32 API definition
  2606. //
  2607. // History: quintinb Created 6/24/99
  2608. //
  2609. //+----------------------------------------------------------------------------
  2610. LRESULT WINAPI SendMessageAU(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  2611. {
  2612. LRESULT lResult = 0;
  2613. LPVOID lpTempBuffer = NULL;
  2614. int nLength = 0;
  2615. CHAR cCharA[3] ;
  2616. WCHAR cCharW[3] ;
  2617. //
  2618. // Preprocess messages that pass chars and strings via wParam and lParam
  2619. //
  2620. switch (Msg)
  2621. {
  2622. //
  2623. // Single Unicode Character in wParam. Convert Unicode character
  2624. // to ANSI and pass lParam as is.
  2625. //
  2626. case EM_SETPASSWORDCHAR: // wParam is char, lParam = 0
  2627. case WM_CHAR: //*wParam is char, lParam = key data
  2628. case WM_SYSCHAR: // wParam is char, lParam = key data
  2629. // Note that we don't handle LeadByte and TrailBytes for
  2630. // these two cases. An application should send WM_IME_CHAR
  2631. // in these cases anyway
  2632. case WM_DEADCHAR: // wParam is char, lParam = key data
  2633. case WM_SYSDEADCHAR: // wParam is char, lParam = key data
  2634. case WM_IME_CHAR: //*
  2635. cCharW[0] = (WCHAR) wParam ;
  2636. cCharW[1] = L'\0' ;
  2637. if (!WzToSz(cCharW, cCharA, 3))
  2638. {
  2639. return FALSE;
  2640. }
  2641. if(Msg == WM_IME_CHAR)
  2642. {
  2643. wParam = (cCharA[1] & 0x00FF) | (cCharA[0] << 8);
  2644. }
  2645. else
  2646. {
  2647. wParam = cCharA[0];
  2648. }
  2649. wParam &= 0x0000FFFF;
  2650. break;
  2651. //
  2652. // In the following cases, lParam is pointer to an IN buffer containing
  2653. // text to send to window.
  2654. // Preprocess by converting from Unicode to ANSI
  2655. //
  2656. case CB_ADDSTRING: // wParam = 0, lParm = lpStr, buffer to add
  2657. case LB_ADDSTRING: // wParam = 0, lParm = lpStr, buffer to add
  2658. case CB_DIR: // wParam = file attributes, lParam = lpszFileSpec buffer
  2659. case LB_DIR: // wParam = file attributes, lParam = lpszFileSpec buffer
  2660. case CB_FINDSTRING: // wParam = start index, lParam = lpszFind
  2661. case LB_FINDSTRING: // wParam = start index, lParam = lpszFind
  2662. case CB_FINDSTRINGEXACT: // wParam = start index, lParam = lpszFind
  2663. case LB_FINDSTRINGEXACT: // wParam = start index, lParam = lpszFind
  2664. case CB_INSERTSTRING: //*wParam = index, lParam = lpszString to insert
  2665. case LB_INSERTSTRING: //*wParam = index, lParam = lpszString to insert
  2666. case CB_SELECTSTRING: // wParam = start index, lParam = lpszFind
  2667. case LB_SELECTSTRING: // wParam = start index, lParam = lpszFind
  2668. case WM_SETTEXT: //*wParam = 0, lParm = lpStr, buffer to set
  2669. {
  2670. if (NULL != (LPWSTR) lParam)
  2671. {
  2672. nLength = 2*lstrlenAU((LPWSTR)lParam) + 1; // Need double length for DBCS characters
  2673. lpTempBuffer = (LPVOID)CmMalloc(nLength);
  2674. }
  2675. if (!lpTempBuffer || (!WzToSz((LPWSTR)lParam, (LPSTR)lpTempBuffer, nLength)))
  2676. {
  2677. CmFree(lpTempBuffer);
  2678. return FALSE;
  2679. }
  2680. lParam = (LPARAM) lpTempBuffer;
  2681. break ;
  2682. }
  2683. }
  2684. // This is where the actual SendMessage takes place
  2685. lResult = SendMessageA(hWnd, Msg, wParam, lParam) ;
  2686. nLength = 0;
  2687. if(lResult > 0)
  2688. {
  2689. switch (Msg)
  2690. {
  2691. //
  2692. // For these cases, lParam is a pointer to an OUT buffer that received text from
  2693. // SendMessageA in ANSI. Convert to Unicode and send back.
  2694. //
  2695. case WM_GETTEXT: // wParam = numCharacters, lParam = lpBuff to RECEIVE string
  2696. case WM_ASKCBFORMATNAME: // wParam = nBufferSize, lParam = lpBuff to RECEIVE string
  2697. nLength = (int) wParam;
  2698. if(!nLength)
  2699. {
  2700. break;
  2701. }
  2702. case CB_GETLBTEXT: // wParam = index, lParam = lpBuff to RECEIVE string
  2703. case EM_GETLINE: // wParam = Line no, lParam = lpBuff to RECEIVE string
  2704. if(!nLength)
  2705. {
  2706. nLength = lstrlenA((LPSTR) lParam) + 1 ;
  2707. }
  2708. lpTempBuffer = (LPVOID) CmMalloc(nLength*sizeof(WCHAR));
  2709. if(!lpTempBuffer || (!SzToWz((LPCSTR) lParam, (LPWSTR) lpTempBuffer, nLength)))
  2710. {
  2711. *((LPWSTR) lParam) = L'\0';
  2712. CmFree(lpTempBuffer);
  2713. return FALSE;
  2714. }
  2715. lstrcpyAU((LPWSTR) lParam, (LPWSTR) lpTempBuffer) ;
  2716. }
  2717. }
  2718. if(lpTempBuffer != NULL)
  2719. {
  2720. CmFree(lpTempBuffer);
  2721. }
  2722. return lResult;
  2723. }
  2724. //+----------------------------------------------------------------------------
  2725. //
  2726. // Function: SetCurrentDirectoryAU
  2727. //
  2728. // Synopsis: Unicode to Ansi wrapper for the win32 SetCurrentDirectory API.
  2729. // Note that we expect the directory path to fit in MAX_PATH chars.
  2730. //
  2731. // Arguments: See the win32 API definition
  2732. //
  2733. // Returns: See the win32 API definition
  2734. //
  2735. // History: quintinb Created 6/24/99
  2736. //
  2737. //+----------------------------------------------------------------------------
  2738. BOOL SetCurrentDirectoryAU(LPCWSTR pszwPathName)
  2739. {
  2740. BOOL bReturn = FALSE;
  2741. if (pszwPathName && (L'\0' != pszwPathName[0]))
  2742. {
  2743. CHAR szAnsiPath[MAX_PATH+1];
  2744. int iChars = WzToSz(pszwPathName, szAnsiPath, MAX_PATH);
  2745. if (iChars && (MAX_PATH >= iChars))
  2746. {
  2747. bReturn = SetCurrentDirectoryA(szAnsiPath);
  2748. }
  2749. }
  2750. return bReturn;
  2751. }
  2752. //+----------------------------------------------------------------------------
  2753. //
  2754. // Function: SetDlgItemTextAU
  2755. //
  2756. // Synopsis: Unicode to Ansi wrapper for the win32 SetDlgItemText API.
  2757. // This function calls SendMessageAU with a WM_SETTEXT and the
  2758. // appropriate Dialog Item from GetDlgItem.
  2759. //
  2760. // Arguments: See the win32 API definition
  2761. //
  2762. // Returns: See the win32 API definition
  2763. //
  2764. // History: quintinb Created 6/24/99
  2765. //
  2766. //+----------------------------------------------------------------------------
  2767. BOOL WINAPI SetDlgItemTextAU(IN HWND hDlg, IN int nIDDlgItem, IN LPCWSTR pszwString)
  2768. {
  2769. return (BOOL) (0 < SendMessageAU(GetDlgItem(hDlg, nIDDlgItem), WM_SETTEXT, (WPARAM) 0, (LPARAM) pszwString));
  2770. }
  2771. //+----------------------------------------------------------------------------
  2772. //
  2773. // Function: SetWindowTextAU
  2774. //
  2775. // Synopsis: Unicode to Ansi wrapper for the win32 SetWindowText API.
  2776. // This function calls SendMessageAU with a WM_SETTEXT.
  2777. //
  2778. // Arguments: See the win32 API definition
  2779. //
  2780. // Returns: See the win32 API definition
  2781. //
  2782. // History: quintinb Created 6/24/99
  2783. //
  2784. //+----------------------------------------------------------------------------
  2785. BOOL WINAPI SetWindowTextAU(HWND hWnd, LPCWSTR pszwString)
  2786. {
  2787. return (BOOL) (0 < SendMessageAU(hWnd, WM_SETTEXT, 0, (LPARAM) pszwString));
  2788. }
  2789. //+----------------------------------------------------------------------------
  2790. //
  2791. // Function: UnregisterClassAU
  2792. //
  2793. // Synopsis: Unicode to Ansi wrapper for the win32 UnregisterClass API.
  2794. //
  2795. // Arguments: See the win32 API definition
  2796. //
  2797. // Returns: See the win32 API definition
  2798. //
  2799. // History: quintinb Created 6/24/99
  2800. //
  2801. //+----------------------------------------------------------------------------
  2802. BOOL WINAPI UnregisterClassAU(IN LPCWSTR lpClassName, IN HINSTANCE hInstance)
  2803. {
  2804. BOOL bReturn = FALSE;
  2805. if (lpClassName)
  2806. {
  2807. LPSTR pszAnsiClassName = WzToSzWithAlloc(lpClassName);
  2808. if (pszAnsiClassName)
  2809. {
  2810. bReturn = UnregisterClassA(pszAnsiClassName, hInstance);
  2811. }
  2812. CmFree(pszAnsiClassName);
  2813. }
  2814. return bReturn;
  2815. }
  2816. //+----------------------------------------------------------------------------
  2817. //
  2818. // Function: WinHelpAU
  2819. //
  2820. // Synopsis: Unicode to Ansi wrapper for the win32 WinHelp API.
  2821. //
  2822. // Arguments: See the win32 API definition
  2823. //
  2824. // Returns: See the win32 API definition
  2825. //
  2826. // History: quintinb Created 6/24/99
  2827. //
  2828. //+----------------------------------------------------------------------------
  2829. BOOL WINAPI WinHelpAU(IN HWND hWndMain, IN LPCWSTR lpszHelp, IN UINT uCommand, IN ULONG_PTR dwData)
  2830. {
  2831. BOOL bReturn = FALSE;
  2832. if (lpszHelp)
  2833. {
  2834. LPSTR pszAnsiHelp = WzToSzWithAlloc(lpszHelp);
  2835. if (pszAnsiHelp)
  2836. {
  2837. bReturn = WinHelpA(hWndMain, pszAnsiHelp, uCommand, dwData);
  2838. }
  2839. CmFree(pszAnsiHelp);
  2840. }
  2841. return bReturn;
  2842. }
  2843. //+----------------------------------------------------------------------------
  2844. //
  2845. // Function: WritePrivateProfileStringAU
  2846. //
  2847. // Synopsis: Unicode to Ansi wrapper for the win32 WritePrivateProfileString API.
  2848. // Note that we expect lpAppName, lpKeyName, and lpFileName to all
  2849. // fit in MAX_PATH chars.
  2850. //
  2851. // Arguments: See the win32 API definition
  2852. //
  2853. // Returns: See the win32 API definition
  2854. //
  2855. // History: quintinb Created 6/24/99
  2856. //
  2857. //+----------------------------------------------------------------------------
  2858. BOOL WINAPI WritePrivateProfileStringAU(IN LPCWSTR lpAppName, IN LPCWSTR lpKeyName,
  2859. IN LPCWSTR lpString, IN LPCWSTR lpFileName)
  2860. {
  2861. BOOL bReturn = FALSE;
  2862. //
  2863. // Check inputs, but note that either lpKeyName or lpString could be NULL
  2864. //
  2865. if (lpAppName && lpFileName)
  2866. {
  2867. CHAR szAnsiAppName[MAX_PATH+1];
  2868. CHAR szAnsiFileName[MAX_PATH+1];
  2869. CHAR szAnsiKeyName[MAX_PATH+1];
  2870. LPSTR pszAnsiKeyName = NULL;
  2871. LPSTR pszAnsiString;
  2872. if (WzToSz(lpAppName, szAnsiAppName, MAX_PATH))
  2873. {
  2874. if (WzToSz(lpFileName, szAnsiFileName, MAX_PATH))
  2875. {
  2876. if (lpKeyName)
  2877. {
  2878. pszAnsiKeyName = szAnsiKeyName;
  2879. WzToSz(lpKeyName, pszAnsiKeyName, MAX_PATH);
  2880. }
  2881. // else pszAnsiKeyName was already init-ed to NULL
  2882. if (pszAnsiKeyName || !lpKeyName)
  2883. {
  2884. pszAnsiString = lpString ? WzToSzWithAlloc(lpString) : NULL;
  2885. if (pszAnsiString || (!lpString))
  2886. {
  2887. bReturn = WritePrivateProfileStringA(szAnsiAppName, pszAnsiKeyName,
  2888. pszAnsiString, szAnsiFileName);
  2889. CmFree(pszAnsiString);
  2890. }
  2891. }
  2892. }
  2893. }
  2894. }
  2895. else
  2896. {
  2897. SetLastError(ERROR_INVALID_PARAMETER);
  2898. }
  2899. CMASSERTMSG(bReturn, TEXT("WritePrivateProfileStringAU Failed."));
  2900. return bReturn;
  2901. }
  2902. //+----------------------------------------------------------------------------
  2903. //
  2904. // Function: wsprintfAU
  2905. //
  2906. // Synopsis: Unicode to Ansi wrapper for the win32 wsprintf API.
  2907. // Note that it uses a va_list and calls wvsprintfAU.
  2908. //
  2909. // Arguments: See the win32 API definition
  2910. //
  2911. // Returns: See the win32 API definition
  2912. //
  2913. // History: quintinb Created 6/24/99
  2914. //
  2915. //+----------------------------------------------------------------------------
  2916. int WINAPIV wsprintfAU(OUT LPWSTR pszwDest, IN LPCWSTR pszwFmt, ...)
  2917. {
  2918. va_list arglist;
  2919. int ret;
  2920. va_start(arglist, pszwFmt);
  2921. ret = wvsprintfAU(pszwDest, pszwFmt, arglist);
  2922. va_end(arglist);
  2923. return ret;
  2924. }
  2925. //+----------------------------------------------------------------------------
  2926. //
  2927. // Function: wvsprintfAU
  2928. //
  2929. // Synopsis: Unicode to Ansi wrapper for the win32 wvsprintf API. In order to
  2930. // avoid parsing the format string to convert the %s to %S and the
  2931. // %c to %C and then calling wvsprintfA, which is originally how this
  2932. // function was written but which isn't really very safe because
  2933. // we don't know the size of the Dest buffer, we will call the
  2934. // C runtime function vswprintf to directly handle a Unicode string.
  2935. //
  2936. // Arguments: See the win32 API definition
  2937. //
  2938. // Returns: See the win32 API definition
  2939. //
  2940. // History: quintinb Created 6/24/99
  2941. // quintinb Changed algorithm to use
  2942. // the C runtime vswprintf 02/05/00
  2943. //
  2944. //+----------------------------------------------------------------------------
  2945. int WINAPI wvsprintfAU(OUT LPWSTR pszwDest, IN LPCWSTR pszwFmt, IN va_list arglist)
  2946. {
  2947. int iReturn = 0;
  2948. if (pszwDest && pszwFmt)
  2949. {
  2950. //
  2951. // Use the C runtime version of the function
  2952. //
  2953. iReturn = vswprintf(pszwDest, pszwFmt, arglist);
  2954. }
  2955. return iReturn;
  2956. }
  2957. //+----------------------------------------------------------------------------
  2958. //
  2959. // Function: InitCmUToA
  2960. //
  2961. // Synopsis: This function is called once cmutoa.dll is loaded. It will init
  2962. // the passed in UAPIINIT struct with the appropriate function pointers.
  2963. //
  2964. // Arguments: PUAPIINIT pUAInit -- pointer to a UAInit struct which contains memory
  2965. // for all the requested function pointers.
  2966. //
  2967. // Returns: BOOL -- always returns TRUE
  2968. //
  2969. // History: quintinb Created 6/24/99
  2970. //
  2971. //+----------------------------------------------------------------------------
  2972. BOOL InitCmUToA(PUAPIINIT pUAInit)
  2973. {
  2974. //
  2975. // Note that we don't need any translation here, the prototype is the same for A or W
  2976. //
  2977. *(pUAInit->pCallWindowProcU) = CallWindowProcA;
  2978. *(pUAInit->pDefWindowProcU) = DefWindowProcA;
  2979. *(pUAInit->pDispatchMessageU) = DispatchMessageA;
  2980. *(pUAInit->pGetClassLongU) = GetClassLongA;
  2981. *(pUAInit->pGetMessageU) = GetMessageA;
  2982. *(pUAInit->pGetWindowLongU) = GetWindowLongA;
  2983. *(pUAInit->pGetWindowTextLengthU) = GetWindowTextLengthA;
  2984. *(pUAInit->pIsDialogMessageU) = IsDialogMessageA;
  2985. *(pUAInit->pPeekMessageU) = PeekMessageA;
  2986. *(pUAInit->pPostMessageU) = PostMessageA;
  2987. *(pUAInit->pPostThreadMessageU) = PostThreadMessageA;
  2988. *(pUAInit->pSetWindowLongU) = SetWindowLongA;
  2989. //
  2990. // Whereas we need wrappers here to do parameter conversion here
  2991. //
  2992. *(pUAInit->pCharLowerU) = CharLowerAU;
  2993. *(pUAInit->pCharNextU) = CharNextAU;
  2994. *(pUAInit->pCharPrevU) = CharPrevAU;
  2995. *(pUAInit->pCharUpperU) = CharUpperAU;
  2996. *(pUAInit->pCompareStringU) = CompareStringAU;
  2997. *(pUAInit->pCreateDialogParamU) = CreateDialogParamAU;
  2998. *(pUAInit->pCreateDirectoryU) = CreateDirectoryAU;
  2999. *(pUAInit->pCreateEventU) = CreateEventAU;
  3000. *(pUAInit->pCreateFileU) = CreateFileAU;
  3001. *(pUAInit->pCreateFileMappingU) = CreateFileMappingAU;
  3002. *(pUAInit->pCreateMutexU) = CreateMutexAU;
  3003. *(pUAInit->pCreateProcessU) = CreateProcessAU;
  3004. *(pUAInit->pCreateWindowExU) = CreateWindowExAU;
  3005. *(pUAInit->pDeleteFileU) = DeleteFileAU;
  3006. *(pUAInit->pDialogBoxParamU) = DialogBoxParamAU;
  3007. *(pUAInit->pExpandEnvironmentStringsU) = ExpandEnvironmentStringsAU;
  3008. *(pUAInit->pFindResourceExU) = FindResourceExAU;
  3009. *(pUAInit->pFindWindowExU) = FindWindowExAU;
  3010. *(pUAInit->pGetDateFormatU) = GetDateFormatAU;
  3011. *(pUAInit->pGetDlgItemTextU) = GetDlgItemTextAU;
  3012. *(pUAInit->pGetFileAttributesU) = GetFileAttributesAU;
  3013. *(pUAInit->pGetModuleFileNameU) = GetModuleFileNameAU;
  3014. *(pUAInit->pGetModuleHandleU) = GetModuleHandleAU;
  3015. *(pUAInit->pGetPrivateProfileIntU) = GetPrivateProfileIntAU;
  3016. *(pUAInit->pGetPrivateProfileStringU) = GetPrivateProfileStringAU;
  3017. *(pUAInit->pGetStringTypeExU) = GetStringTypeExAU;
  3018. *(pUAInit->pGetSystemDirectoryU) = GetSystemDirectoryAU;
  3019. *(pUAInit->pGetTempFileNameU) = GetTempFileNameAU;
  3020. *(pUAInit->pGetTempPathU) = GetTempPathAU;
  3021. *(pUAInit->pGetTimeFormatU) = GetTimeFormatAU;
  3022. *(pUAInit->pGetUserNameU) = GetUserNameAU;
  3023. *(pUAInit->pGetVersionExU) = GetVersionExAU;
  3024. *(pUAInit->pGetWindowTextU) = GetWindowTextAU;
  3025. *(pUAInit->pInsertMenuU) = InsertMenuAU;
  3026. *(pUAInit->pLoadCursorU) = LoadCursorAU;
  3027. *(pUAInit->pLoadIconU) = LoadIconAU;
  3028. *(pUAInit->pLoadImageU) = LoadImageAU;
  3029. *(pUAInit->pLoadLibraryExU) = LoadLibraryExAU;
  3030. *(pUAInit->pLoadMenuU) = LoadMenuAU;
  3031. *(pUAInit->pLoadStringU) = LoadStringAU;
  3032. *(pUAInit->plstrcatU) = lstrcatAU;
  3033. *(pUAInit->plstrcmpU) = lstrcmpAU;
  3034. *(pUAInit->plstrcmpiU) = lstrcmpiAU;
  3035. *(pUAInit->plstrcpyU) = lstrcpyAU;
  3036. *(pUAInit->plstrcpynU) = lstrcpynAU;
  3037. *(pUAInit->plstrlenU) = lstrlenAU;
  3038. *(pUAInit->pOpenEventU) = OpenEventAU;
  3039. *(pUAInit->pOpenFileMappingU) = OpenFileMappingAU;
  3040. *(pUAInit->pRegCreateKeyExU) = RegCreateKeyExAU;
  3041. *(pUAInit->pRegDeleteKeyU) = RegDeleteKeyAU;
  3042. *(pUAInit->pRegDeleteValueU) = RegDeleteValueAU;
  3043. *(pUAInit->pRegEnumKeyExU) = RegEnumKeyExAU;
  3044. *(pUAInit->pRegisterClassExU) = RegisterClassExAU;
  3045. *(pUAInit->pRegisterWindowMessageU) = RegisterWindowMessageAU;
  3046. *(pUAInit->pRegOpenKeyExU) = RegOpenKeyExAU;
  3047. *(pUAInit->pRegQueryValueExU) = RegQueryValueExAU;
  3048. *(pUAInit->pRegSetValueExU) = RegSetValueExAU;
  3049. *(pUAInit->pSearchPathU) = SearchPathAU;
  3050. *(pUAInit->pSendDlgItemMessageU) = SendDlgItemMessageAU;
  3051. *(pUAInit->pSendMessageU) = SendMessageAU;
  3052. *(pUAInit->pSetCurrentDirectoryU) = SetCurrentDirectoryAU;
  3053. *(pUAInit->pSetDlgItemTextU) = SetDlgItemTextAU;
  3054. *(pUAInit->pSetWindowTextU) = SetWindowTextAU;
  3055. *(pUAInit->pUnregisterClassU) = UnregisterClassAU;
  3056. *(pUAInit->pWinHelpU) = WinHelpAU;
  3057. *(pUAInit->pWritePrivateProfileStringU) = WritePrivateProfileStringAU;
  3058. *(pUAInit->pwsprintfU) = wsprintfAU;
  3059. *(pUAInit->pwvsprintfU) = wvsprintfAU;
  3060. //
  3061. // Currently this always returns TRUE because none of the above can really
  3062. // fail. However, in the future we may need more of a meaningful return
  3063. // value here.
  3064. //
  3065. return TRUE;
  3066. }
  3067. //+----------------------------------------------------------------------------
  3068. //
  3069. // Function: RasDeleteEntryUA
  3070. //
  3071. // Synopsis: Unicode to Ansi wrapper for the win32 RasDeleteEntry API.
  3072. //
  3073. // Arguments: See the win32 API definition
  3074. //
  3075. // Returns: See the win32 API definition
  3076. //
  3077. // History: quintinb Created 7/15/99
  3078. //
  3079. //+----------------------------------------------------------------------------
  3080. DWORD APIENTRY RasDeleteEntryUA(LPCWSTR pszwPhoneBook, LPCWSTR pszwEntry)
  3081. {
  3082. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3083. //
  3084. // The phonebook should always be NULL on win9x
  3085. //
  3086. MYDBGASSERT(NULL == pszwPhoneBook);
  3087. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3088. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3089. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnDeleteEntry);
  3090. if (pszwEntry && pAnsiRasLinkage && pAnsiRasLinkage->pfnDeleteEntry)
  3091. {
  3092. CHAR szAnsiEntry [RAS_MaxEntryName + 1];
  3093. int iChars = WzToSz(pszwEntry, szAnsiEntry, RAS_MaxEntryName);
  3094. if (iChars && (RAS_MaxEntryName >= iChars))
  3095. {
  3096. dwReturn = pAnsiRasLinkage->pfnDeleteEntry(NULL, szAnsiEntry);
  3097. }
  3098. }
  3099. return dwReturn;
  3100. }
  3101. //+----------------------------------------------------------------------------
  3102. //
  3103. // Function: RasGetEntryPropertiesUA
  3104. //
  3105. // Synopsis: Unicode to Ansi wrapper for the win32 RasGetEntryProperties API.
  3106. //
  3107. // Arguments: See the win32 API definition
  3108. //
  3109. // Returns: See the win32 API definition
  3110. //
  3111. // History: quintinb Created 7/15/99
  3112. //
  3113. //+----------------------------------------------------------------------------
  3114. DWORD APIENTRY RasGetEntryPropertiesUA(LPCWSTR pszwPhoneBook, LPCWSTR pszwEntry,
  3115. LPRASENTRYW pRasEntryW, LPDWORD pdwEntryInfoSize,
  3116. LPBYTE pbDeviceInfo, LPDWORD pdwDeviceInfoSize)
  3117. {
  3118. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3119. //
  3120. // The phonebook should always be NULL on win9x
  3121. //
  3122. MYDBGASSERT(NULL == pszwPhoneBook);
  3123. MYDBGASSERT(NULL == pbDeviceInfo); // We don't use or handle this TAPI param. If we need it,
  3124. // conversion must be implemented.
  3125. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3126. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3127. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnGetEntryProperties);
  3128. if (pszwEntry && pdwEntryInfoSize && pAnsiRasLinkage && pAnsiRasLinkage->pfnGetEntryProperties)
  3129. {
  3130. CHAR szAnsiEntry [RAS_MaxEntryName + 1];
  3131. RASENTRYA RasEntryA;
  3132. DWORD dwTmpEntrySize = sizeof(RASENTRYA);
  3133. ZeroMemory(&RasEntryA, sizeof(RASENTRYA));
  3134. int iChars = WzToSz(pszwEntry, szAnsiEntry, RAS_MaxEntryName);
  3135. if (iChars && (RAS_MaxEntryName >= iChars))
  3136. {
  3137. dwReturn = pAnsiRasLinkage->pfnGetEntryProperties(NULL, szAnsiEntry, &RasEntryA,
  3138. &dwTmpEntrySize, NULL, NULL);
  3139. if ((ERROR_SUCCESS == dwReturn) && pRasEntryW)
  3140. {
  3141. //
  3142. // Do conversion of RASENTRYA to RASENTRYW
  3143. //
  3144. // pRasEntryW->dwSize -- this param should already be set
  3145. pRasEntryW->dwfOptions = RasEntryA.dwfOptions;
  3146. //
  3147. // Location/phone number.
  3148. //
  3149. pRasEntryW->dwCountryID = RasEntryA.dwCountryID;
  3150. pRasEntryW->dwCountryCode = RasEntryA.dwCountryCode;
  3151. MYVERIFY(0 != SzToWz(RasEntryA.szAreaCode, pRasEntryW->szAreaCode, RAS_MaxAreaCode));
  3152. MYVERIFY(0 != SzToWz(RasEntryA.szLocalPhoneNumber, pRasEntryW->szLocalPhoneNumber, RAS_MaxPhoneNumber));
  3153. pRasEntryW->dwAlternateOffset = RasEntryA.dwAlternateOffset;
  3154. //
  3155. // PPP/Ip
  3156. //
  3157. memcpy(&(pRasEntryW->ipaddr), &(RasEntryA.ipaddr), sizeof(RASIPADDR));
  3158. memcpy(&(pRasEntryW->ipaddrDns), &(RasEntryA.ipaddrDns), sizeof(RASIPADDR));
  3159. memcpy(&(pRasEntryW->ipaddrDnsAlt), &(RasEntryA.ipaddrDnsAlt), sizeof(RASIPADDR));
  3160. memcpy(&(pRasEntryW->ipaddrWins), &(RasEntryA.ipaddrWins), sizeof(RASIPADDR));
  3161. memcpy(&(pRasEntryW->ipaddrWinsAlt), &(RasEntryA.ipaddrWinsAlt), sizeof(RASIPADDR));
  3162. //
  3163. // Framing
  3164. //
  3165. pRasEntryW->dwFrameSize = RasEntryA.dwFrameSize;
  3166. pRasEntryW->dwfNetProtocols = RasEntryA.dwfNetProtocols;
  3167. pRasEntryW->dwFramingProtocol = RasEntryA.dwFramingProtocol;
  3168. //
  3169. // Scripting
  3170. //
  3171. MYVERIFY(0 != SzToWz(RasEntryA.szScript, pRasEntryW->szScript, MAX_PATH));
  3172. //
  3173. // AutoDial
  3174. //
  3175. MYVERIFY(0 != SzToWz(RasEntryA.szAutodialDll, pRasEntryW->szAutodialDll, MAX_PATH));
  3176. MYVERIFY(0 != SzToWz(RasEntryA.szAutodialFunc, pRasEntryW->szAutodialFunc, MAX_PATH));
  3177. //
  3178. // Device
  3179. //
  3180. MYVERIFY(0 != SzToWz(RasEntryA.szDeviceType, pRasEntryW->szDeviceType, RAS_MaxDeviceType));
  3181. MYVERIFY(0 != SzToWz(RasEntryA.szDeviceName, pRasEntryW->szDeviceName, RAS_MaxDeviceName));
  3182. //
  3183. // X.25 -- we don't use x25
  3184. //
  3185. pRasEntryW->szX25PadType[0] = L'\0';
  3186. pRasEntryW->szX25Address[0] = L'\0';
  3187. pRasEntryW->szX25Facilities[0] = L'\0';
  3188. pRasEntryW->szX25UserData[0] = L'\0';
  3189. pRasEntryW->dwChannels = 0;
  3190. //
  3191. // Reserved
  3192. //
  3193. pRasEntryW->dwReserved1 = RasEntryA.dwReserved1;
  3194. pRasEntryW->dwReserved2 = RasEntryA.dwReserved2;
  3195. }
  3196. else if ((ERROR_BUFFER_TOO_SMALL == dwReturn) || !pRasEntryW)
  3197. {
  3198. //
  3199. // We don't know the actual size since we are passing a RASENTRYA, but
  3200. // the user only knows about RASENTRYW. Thus double the returned size.
  3201. //
  3202. *pdwEntryInfoSize = 2*dwTmpEntrySize;
  3203. }
  3204. }
  3205. }
  3206. return dwReturn;
  3207. }
  3208. //+----------------------------------------------------------------------------
  3209. //
  3210. // Function: RasSetEntryPropertiesUA
  3211. //
  3212. // Synopsis: Unicode to Ansi wrapper for the win32 RasSetEntryProperties API.
  3213. // Note that we do not support the pbDeviceInfo
  3214. // parameter, if you need it you will have to implement it.
  3215. //
  3216. // Arguments: See the win32 API definition
  3217. //
  3218. // Returns: See the win32 API definition
  3219. //
  3220. // History: quintinb Created 7/15/99
  3221. //
  3222. //+----------------------------------------------------------------------------
  3223. DWORD APIENTRY RasSetEntryPropertiesUA(LPCWSTR pszwPhoneBook, LPCWSTR pszwEntry, LPRASENTRYW pRasEntryW,
  3224. DWORD dwEntryInfoSize, LPBYTE pbDeviceInfo, DWORD dwDeviceInfoSize)
  3225. {
  3226. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3227. //
  3228. // We don't use or handle this TAPI param. If we need it, conversion must be implemented.
  3229. // Note that 1 is a special value for Windows Millennium (see Millennium bug 127371)
  3230. //
  3231. MYDBGASSERT((NULL == pbDeviceInfo) || ((LPBYTE)1 == pbDeviceInfo));
  3232. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3233. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3234. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnSetEntryProperties);
  3235. if (pszwEntry && dwEntryInfoSize && pRasEntryW && pAnsiRasLinkage && pAnsiRasLinkage->pfnSetEntryProperties)
  3236. {
  3237. //
  3238. // The phonebook should always be NULL on Win9x.
  3239. //
  3240. MYDBGASSERT(NULL == pszwPhoneBook);
  3241. CHAR szAnsiEntry [RAS_MaxEntryName + 1];
  3242. int iChars = WzToSz(pszwEntry, szAnsiEntry, RAS_MaxEntryName);
  3243. if (iChars && (RAS_MaxEntryName >= iChars))
  3244. {
  3245. //
  3246. // Figure out the correct size to use
  3247. //
  3248. MYDBGASSERT((sizeof(RASENTRYW) == pRasEntryW->dwSize) ||(sizeof(RASENTRYW_V401) == pRasEntryW->dwSize));
  3249. DWORD dwSize;
  3250. if ((sizeof (RASENTRYW_V401) == pRasEntryW->dwSize) && OS_MIL)
  3251. {
  3252. //
  3253. // Millennium uses the NT4 structure size
  3254. //
  3255. dwSize = sizeof(RASENTRYA_V401);
  3256. }
  3257. else
  3258. {
  3259. dwSize = sizeof(RASENTRYA);
  3260. }
  3261. //
  3262. // Allocate the RasEntryStructure
  3263. //
  3264. LPRASENTRYA pAnsiRasEntry = (LPRASENTRYA)CmMalloc(dwSize);
  3265. if (pAnsiRasEntry)
  3266. {
  3267. //
  3268. // Do conversion of RASENTRYA to RASENTRYW
  3269. //
  3270. pAnsiRasEntry->dwSize = dwSize;
  3271. pAnsiRasEntry->dwfOptions = pRasEntryW->dwfOptions;
  3272. //
  3273. // Location/phone number.
  3274. //
  3275. pAnsiRasEntry->dwCountryID = pRasEntryW->dwCountryID;
  3276. pAnsiRasEntry->dwCountryCode = pRasEntryW->dwCountryCode;
  3277. MYVERIFY(0 != WzToSz(pRasEntryW->szAreaCode, pAnsiRasEntry->szAreaCode, RAS_MaxAreaCode));
  3278. MYVERIFY(0 != WzToSz(pRasEntryW->szLocalPhoneNumber, pAnsiRasEntry->szLocalPhoneNumber, RAS_MaxPhoneNumber));
  3279. CMASSERTMSG(0 == pRasEntryW->dwAlternateOffset, TEXT("RasSetEntryPropertiesUA -- dwAlternateOffset != 0 is not supported. This will need to be implemented if used."));
  3280. pAnsiRasEntry->dwAlternateOffset = 0;
  3281. //
  3282. // PPP/Ip
  3283. //
  3284. memcpy(&(pAnsiRasEntry->ipaddr), &(pRasEntryW->ipaddr), sizeof(RASIPADDR));
  3285. memcpy(&(pAnsiRasEntry->ipaddrDns), &(pRasEntryW->ipaddrDns), sizeof(RASIPADDR));
  3286. memcpy(&(pAnsiRasEntry->ipaddrDnsAlt), &(pRasEntryW->ipaddrDnsAlt), sizeof(RASIPADDR));
  3287. memcpy(&(pAnsiRasEntry->ipaddrWins), &(pRasEntryW->ipaddrWins), sizeof(RASIPADDR));
  3288. memcpy(&(pAnsiRasEntry->ipaddrWinsAlt), &(pRasEntryW->ipaddrWinsAlt), sizeof(RASIPADDR));
  3289. //
  3290. // Framing
  3291. //
  3292. pAnsiRasEntry->dwFrameSize = pRasEntryW->dwFrameSize;
  3293. pAnsiRasEntry->dwfNetProtocols = pRasEntryW->dwfNetProtocols;
  3294. pAnsiRasEntry->dwFramingProtocol = pRasEntryW->dwFramingProtocol;
  3295. //
  3296. // Scripting
  3297. //
  3298. MYVERIFY(0 != WzToSz(pRasEntryW->szScript, pAnsiRasEntry->szScript, MAX_PATH));
  3299. //
  3300. // AutoDial
  3301. //
  3302. MYVERIFY(0 != WzToSz(pRasEntryW->szAutodialDll, pAnsiRasEntry->szAutodialDll, MAX_PATH));
  3303. MYVERIFY(0 != WzToSz(pRasEntryW->szAutodialFunc, pAnsiRasEntry->szAutodialFunc, MAX_PATH));
  3304. //
  3305. // Device
  3306. //
  3307. MYVERIFY(0 != WzToSz(pRasEntryW->szDeviceType, pAnsiRasEntry->szDeviceType, RAS_MaxDeviceType));
  3308. MYVERIFY(0 != WzToSz(pRasEntryW->szDeviceName, pAnsiRasEntry->szDeviceName, RAS_MaxDeviceName));
  3309. //
  3310. // X.25 -- we don't use x25
  3311. //
  3312. pAnsiRasEntry->szX25PadType[0] = '\0';
  3313. pAnsiRasEntry->szX25Address[0] = '\0';
  3314. pAnsiRasEntry->szX25Facilities[0] = '\0';
  3315. pAnsiRasEntry->szX25UserData[0] = '\0';
  3316. pAnsiRasEntry->dwChannels = 0;
  3317. //
  3318. // Reserved
  3319. //
  3320. pAnsiRasEntry->dwReserved1 = pRasEntryW->dwReserved1;
  3321. pAnsiRasEntry->dwReserved2 = pRasEntryW->dwReserved2;
  3322. if (sizeof(RASENTRYA_V401) == dwSize)
  3323. {
  3324. //
  3325. // Copy over the 4.01 data
  3326. //
  3327. LPRASENTRYA_V401 pAnsi401RasEntry = (LPRASENTRYA_V401)pAnsiRasEntry;
  3328. LPRASENTRYW_V401 pWide401RasEntry = (LPRASENTRYW_V401)pRasEntryW;
  3329. pAnsi401RasEntry->dwSubEntries = pWide401RasEntry->dwSubEntries;
  3330. pAnsi401RasEntry->dwDialMode = pWide401RasEntry->dwDialMode;
  3331. pAnsi401RasEntry->dwDialExtraPercent = pWide401RasEntry->dwDialExtraPercent;
  3332. pAnsi401RasEntry->dwDialExtraSampleSeconds = pWide401RasEntry->dwDialExtraSampleSeconds;
  3333. pAnsi401RasEntry->dwHangUpExtraPercent = pWide401RasEntry->dwHangUpExtraPercent;
  3334. pAnsi401RasEntry->dwHangUpExtraSampleSeconds = pWide401RasEntry->dwHangUpExtraSampleSeconds;
  3335. pAnsi401RasEntry->dwIdleDisconnectSeconds = pWide401RasEntry->dwIdleDisconnectSeconds;
  3336. }
  3337. dwReturn = pAnsiRasLinkage->pfnSetEntryProperties(NULL, szAnsiEntry, pAnsiRasEntry,
  3338. pAnsiRasEntry->dwSize, pbDeviceInfo, 0);
  3339. CmFree(pAnsiRasEntry);
  3340. }
  3341. }
  3342. }
  3343. return dwReturn;
  3344. }
  3345. //+----------------------------------------------------------------------------
  3346. //
  3347. // Function: RasDialParamsWtoRasDialParamsA
  3348. //
  3349. // Synopsis: Wrapper function to handle converting a RasDialParamsW struct to
  3350. // a RasDialParamsA Struct. Used by RasSetEntryDialParamsUA and
  3351. // RasDialUA.
  3352. //
  3353. // Arguments: LPRASDIALPARAMSW pRdpW - pointer to a RasDialParamsW
  3354. // LPRASDIALPARAMSA pRdpA - pointer to a RasDialParamsA
  3355. //
  3356. // Returns: Nothing
  3357. //
  3358. // History: quintinb Created 7/15/99
  3359. //
  3360. //+----------------------------------------------------------------------------
  3361. void RasDialParamsWtoRasDialParamsA (LPRASDIALPARAMSW pRdpW, LPRASDIALPARAMSA pRdpA)
  3362. {
  3363. pRdpA->dwSize = sizeof(RASDIALPARAMSA);
  3364. MYVERIFY(0 != WzToSz(pRdpW->szEntryName, pRdpA->szEntryName, RAS_MaxEntryName));
  3365. MYVERIFY(0 != WzToSz(pRdpW->szPhoneNumber, pRdpA->szPhoneNumber, RAS_MaxPhoneNumber));
  3366. MYVERIFY(0 != WzToSz(pRdpW->szCallbackNumber, pRdpA->szCallbackNumber, RAS_MaxCallbackNumber));
  3367. MYVERIFY(0 != WzToSz(pRdpW->szUserName, pRdpA->szUserName, UNLEN));
  3368. MYVERIFY(0 != WzToSz(pRdpW->szPassword, pRdpA->szPassword, PWLEN));
  3369. MYVERIFY(0 != WzToSz(pRdpW->szDomain, pRdpA->szDomain, DNLEN));
  3370. }
  3371. //+----------------------------------------------------------------------------
  3372. //
  3373. // Function: RasDialParamsAtoRasDialParamsW
  3374. //
  3375. // Synopsis: Wrapper function to handle converting a RasDialParamsA struct to
  3376. // a RasDialParamsW Struct. Used by RasGetEntryDialParamsUA.
  3377. //
  3378. // Arguments: LPRASDIALPARAMSW pRdpA - pointer to a RasDialParamsA
  3379. // LPRASDIALPARAMSA pRdpW - pointer to a RasDialParamsW
  3380. //
  3381. // Returns: Nothing
  3382. //
  3383. // History: quintinb Created 7/15/99
  3384. //
  3385. //+----------------------------------------------------------------------------
  3386. void RasDialParamsAtoRasDialParamsW (LPRASDIALPARAMSA pRdpA, LPRASDIALPARAMSW pRdpW)
  3387. {
  3388. pRdpW->dwSize = sizeof(RASDIALPARAMSW);
  3389. MYVERIFY(0 != SzToWz(pRdpA->szEntryName, pRdpW->szEntryName, RAS_MaxEntryName));
  3390. MYVERIFY(0 != SzToWz(pRdpA->szPhoneNumber, pRdpW->szPhoneNumber, RAS_MaxPhoneNumber));
  3391. MYVERIFY(0 != SzToWz(pRdpA->szCallbackNumber, pRdpW->szCallbackNumber, RAS_MaxCallbackNumber));
  3392. MYVERIFY(0 != SzToWz(pRdpA->szUserName, pRdpW->szUserName, UNLEN));
  3393. MYVERIFY(0 != SzToWz(pRdpA->szPassword, pRdpW->szPassword, PWLEN));
  3394. MYVERIFY(0 != SzToWz(pRdpA->szDomain, pRdpW->szDomain, DNLEN));
  3395. }
  3396. //+----------------------------------------------------------------------------
  3397. //
  3398. // Function: RasGetEntryDialParamsUA
  3399. //
  3400. // Synopsis: Unicode to Ansi wrapper for the win32 RasGetEntryDialParams API.
  3401. //
  3402. // Arguments: See the win32 API definition
  3403. //
  3404. // Returns: See the win32 API definition
  3405. //
  3406. // History: quintinb Created 7/15/99
  3407. //
  3408. //+----------------------------------------------------------------------------
  3409. DWORD APIENTRY RasGetEntryDialParamsUA(LPCWSTR pszwPhoneBook, LPRASDIALPARAMSW pRasDialParamsW, LPBOOL pbPassword)
  3410. {
  3411. DWORD dwReturn = ERROR_BUFFER_INVALID;
  3412. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3413. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3414. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnGetEntryDialParams);
  3415. if (pRasDialParamsW && pbPassword && pAnsiRasLinkage && pAnsiRasLinkage->pfnGetEntryDialParams)
  3416. {
  3417. //
  3418. // The phonebook should always be NULL on win9x
  3419. //
  3420. MYDBGASSERT(NULL == pszwPhoneBook);
  3421. RASDIALPARAMSA RasDialParamsA;
  3422. ZeroMemory(&RasDialParamsA, sizeof(RASDIALPARAMSA));
  3423. RasDialParamsA.dwSize = sizeof(RASDIALPARAMSA);
  3424. int iChars = WzToSz(pRasDialParamsW->szEntryName, RasDialParamsA.szEntryName, RAS_MaxEntryName);
  3425. if (iChars && (RAS_MaxEntryName >= iChars))
  3426. {
  3427. dwReturn = pAnsiRasLinkage->pfnGetEntryDialParams(NULL, &RasDialParamsA, pbPassword);
  3428. if (ERROR_SUCCESS == dwReturn)
  3429. {
  3430. RasDialParamsAtoRasDialParamsW(&RasDialParamsA, pRasDialParamsW);
  3431. }
  3432. }
  3433. }
  3434. return dwReturn;
  3435. }
  3436. //+----------------------------------------------------------------------------
  3437. //
  3438. // Function: RasSetEntryDialParamsUA
  3439. //
  3440. // Synopsis: Unicode to Ansi wrapper for the win32 RasSetEntryDialParams API.
  3441. //
  3442. // Arguments: See the win32 API definition
  3443. //
  3444. // Returns: See the win32 API definition
  3445. //
  3446. // History: quintinb Created 7/15/99
  3447. //
  3448. //+----------------------------------------------------------------------------
  3449. DWORD APIENTRY RasSetEntryDialParamsUA(LPCWSTR pszwPhoneBook, LPRASDIALPARAMSW pRasDialParamsW,
  3450. BOOL bRemovePassword)
  3451. {
  3452. DWORD dwReturn = ERROR_BUFFER_INVALID;
  3453. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3454. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3455. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnSetEntryDialParams);
  3456. if (pRasDialParamsW && pAnsiRasLinkage && pAnsiRasLinkage->pfnSetEntryDialParams)
  3457. {
  3458. //
  3459. // The phonebook should always be NULL on win9x
  3460. //
  3461. MYDBGASSERT(NULL == pszwPhoneBook);
  3462. RASDIALPARAMSA RasDialParamsA;
  3463. RasDialParamsWtoRasDialParamsA (pRasDialParamsW, &RasDialParamsA);
  3464. dwReturn = pAnsiRasLinkage->pfnSetEntryDialParams(NULL, &RasDialParamsA, bRemovePassword);
  3465. }
  3466. return dwReturn;
  3467. }
  3468. //+----------------------------------------------------------------------------
  3469. //
  3470. // Function: RasEnumDevicesUA
  3471. //
  3472. // Synopsis: Unicode to Ansi wrapper for the win32 RasEnumDevices API.
  3473. //
  3474. // Arguments: See the win32 API definition
  3475. //
  3476. // Returns: See the win32 API definition
  3477. //
  3478. // History: quintinb Created 7/15/99
  3479. //
  3480. //+----------------------------------------------------------------------------
  3481. DWORD RasEnumDevicesUA(LPRASDEVINFOW pRasDevInfo, LPDWORD pdwCb, LPDWORD pdwDevices)
  3482. {
  3483. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3484. DWORD dwSize;
  3485. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3486. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3487. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnEnumDevices);
  3488. if (pdwCb && pdwDevices && pAnsiRasLinkage && pAnsiRasLinkage->pfnEnumDevices)
  3489. {
  3490. LPRASDEVINFOA pAnsiDevInfo;
  3491. if ((NULL == pRasDevInfo) && (0 == *pdwCb))
  3492. {
  3493. //
  3494. // Then the caller is just trying to size the buffer
  3495. //
  3496. dwSize = 0;
  3497. pAnsiDevInfo = NULL;
  3498. }
  3499. else
  3500. {
  3501. dwSize = ((*pdwCb)/sizeof(RASDEVINFOW))*sizeof(RASDEVINFOA);
  3502. pAnsiDevInfo = (LPRASDEVINFOA)CmMalloc(dwSize);
  3503. if (NULL == pAnsiDevInfo)
  3504. {
  3505. return ERROR_NOT_ENOUGH_MEMORY;
  3506. }
  3507. pAnsiDevInfo[0].dwSize = sizeof(RASDEVINFOA);
  3508. }
  3509. dwReturn = pAnsiRasLinkage->pfnEnumDevices(pAnsiDevInfo, &dwSize, pdwDevices);
  3510. //
  3511. // Resize the buffer in terms of RASDEVINFOW structs
  3512. //
  3513. *pdwCb = ((dwSize)/sizeof(RASDEVINFOA))*sizeof(RASDEVINFOW);
  3514. if (ERROR_SUCCESS == dwReturn && pRasDevInfo)
  3515. {
  3516. //
  3517. // Then we need to convert the returned structs
  3518. //
  3519. MYDBGASSERT((*pdwDevices)*sizeof(RASDEVINFOW) <= *pdwCb);
  3520. for (DWORD dwIndex = 0; dwIndex < *pdwDevices; dwIndex++)
  3521. {
  3522. MYVERIFY(0 != SzToWz(pAnsiDevInfo[dwIndex].szDeviceType,
  3523. pRasDevInfo[dwIndex].szDeviceType, RAS_MaxDeviceType));
  3524. MYVERIFY(0 != SzToWz(pAnsiDevInfo[dwIndex].szDeviceName,
  3525. pRasDevInfo[dwIndex].szDeviceName, RAS_MaxDeviceName));
  3526. }
  3527. }
  3528. //
  3529. // Free the Ansi buffer
  3530. //
  3531. CmFree (pAnsiDevInfo);
  3532. }
  3533. return dwReturn;
  3534. }
  3535. //+----------------------------------------------------------------------------
  3536. //
  3537. // Function: RasDialUA
  3538. //
  3539. // Synopsis: Unicode to Ansi wrapper for the win32 RasDial API.
  3540. //
  3541. // Arguments: See the win32 API definition
  3542. //
  3543. // Returns: See the win32 API definition
  3544. //
  3545. // History: quintinb Created 7/15/99
  3546. //
  3547. //+----------------------------------------------------------------------------
  3548. DWORD APIENTRY RasDialUA(LPRASDIALEXTENSIONS pRasDialExt, LPCWSTR pszwPhoneBook,
  3549. LPRASDIALPARAMSW pRasDialParamsW, DWORD dwNotifierType, LPVOID pvNotifier,
  3550. LPHRASCONN phRasConn)
  3551. {
  3552. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3553. MYDBGASSERT(NULL == pszwPhoneBook);
  3554. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3555. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3556. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnDial);
  3557. if (pRasDialParamsW && phRasConn && pAnsiRasLinkage && pAnsiRasLinkage->pfnDial)
  3558. {
  3559. RASDIALPARAMSA RasDialParamsA;
  3560. RasDialParamsWtoRasDialParamsA (pRasDialParamsW, &RasDialParamsA);
  3561. dwReturn = pAnsiRasLinkage->pfnDial(pRasDialExt, NULL, &RasDialParamsA, dwNotifierType,
  3562. pvNotifier, phRasConn);
  3563. }
  3564. return dwReturn;
  3565. }
  3566. //+----------------------------------------------------------------------------
  3567. //
  3568. // Function: RasHangUpUA
  3569. //
  3570. // Synopsis: Unicode to Ansi wrapper for the win32 RasHangUp API. Which for
  3571. // some reason has an ANSI and Unicode form, not sure why.
  3572. //
  3573. // Arguments: See the win32 API definition
  3574. //
  3575. // Returns: See the win32 API definition
  3576. //
  3577. // History: quintinb Created 7/15/99
  3578. //
  3579. //+----------------------------------------------------------------------------
  3580. DWORD APIENTRY RasHangUpUA(HRASCONN hRasConn)
  3581. {
  3582. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3583. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3584. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3585. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnHangUp);
  3586. if (hRasConn && pAnsiRasLinkage && pAnsiRasLinkage->pfnHangUp)
  3587. {
  3588. dwReturn = pAnsiRasLinkage->pfnHangUp(hRasConn);
  3589. }
  3590. return dwReturn;
  3591. }
  3592. //+----------------------------------------------------------------------------
  3593. //
  3594. // Function: RasGetErrorStringUA
  3595. //
  3596. // Synopsis: Unicode to Ansi wrapper for the win32 RasGetErrorString API.
  3597. //
  3598. // Arguments: See the win32 API definition
  3599. //
  3600. // Returns: See the win32 API definition
  3601. //
  3602. // History: quintinb Created 7/15/99
  3603. //
  3604. //+----------------------------------------------------------------------------
  3605. DWORD APIENTRY RasGetErrorStringUA(UINT uErrorValue, LPWSTR pszwOutBuf, DWORD dwBufSize)
  3606. {
  3607. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3608. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3609. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3610. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnGetErrorString);
  3611. if (pszwOutBuf && dwBufSize && pAnsiRasLinkage && pAnsiRasLinkage->pfnGetErrorString)
  3612. {
  3613. LPSTR pszAnsiBuf = (LPSTR)CmMalloc(dwBufSize);
  3614. if (pszAnsiBuf)
  3615. {
  3616. dwReturn = pAnsiRasLinkage->pfnGetErrorString(uErrorValue, pszAnsiBuf, dwBufSize);
  3617. if (ERROR_SUCCESS == dwReturn)
  3618. {
  3619. int iChars = SzToWz(pszAnsiBuf, pszwOutBuf, dwBufSize);
  3620. if (!iChars || (dwBufSize < (DWORD)iChars))
  3621. {
  3622. dwReturn = ERROR_NOT_ENOUGH_MEMORY;
  3623. }
  3624. }
  3625. }
  3626. CmFree(pszAnsiBuf);
  3627. }
  3628. return dwReturn;
  3629. }
  3630. //+----------------------------------------------------------------------------
  3631. //
  3632. // Function: RasGetConnectStatusUA
  3633. //
  3634. // Synopsis: Unicode to Ansi wrapper for the win32 RasGetConnectStatus API.
  3635. //
  3636. // Arguments: See the win32 API definition
  3637. //
  3638. // Returns: See the win32 API definition
  3639. //
  3640. // History: quintinb Created 7/15/99
  3641. //
  3642. //+----------------------------------------------------------------------------
  3643. DWORD RasGetConnectStatusUA(HRASCONN hRasConn, LPRASCONNSTATUSW pRasConnStatusW)
  3644. {
  3645. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3646. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3647. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3648. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnGetConnectStatus);
  3649. if (pRasConnStatusW && pAnsiRasLinkage && pAnsiRasLinkage->pfnGetConnectStatus)
  3650. {
  3651. RASCONNSTATUSA RasConnStatusA;
  3652. ZeroMemory(&RasConnStatusA, sizeof(RASCONNSTATUSA));
  3653. RasConnStatusA.dwSize = sizeof(RASCONNSTATUSA);
  3654. dwReturn = pAnsiRasLinkage->pfnGetConnectStatus(hRasConn, &RasConnStatusA);
  3655. if (ERROR_SUCCESS == dwReturn)
  3656. {
  3657. pRasConnStatusW->rasconnstate = RasConnStatusA.rasconnstate;
  3658. pRasConnStatusW->dwError = RasConnStatusA.dwError;
  3659. int iChars = SzToWz(RasConnStatusA.szDeviceType, pRasConnStatusW->szDeviceType,
  3660. RAS_MaxDeviceType);
  3661. if (!iChars || (RAS_MaxDeviceType < iChars))
  3662. {
  3663. dwReturn = ERROR_NOT_ENOUGH_MEMORY;
  3664. }
  3665. else
  3666. {
  3667. iChars = SzToWz(RasConnStatusA.szDeviceName, pRasConnStatusW->szDeviceName,
  3668. RAS_MaxDeviceName);
  3669. if (!iChars || (RAS_MaxDeviceName < iChars))
  3670. {
  3671. dwReturn = ERROR_NOT_ENOUGH_MEMORY;
  3672. }
  3673. }
  3674. }
  3675. }
  3676. return dwReturn;
  3677. }
  3678. //+----------------------------------------------------------------------------
  3679. //
  3680. // Function: RasSetSubEntryPropertiesUA
  3681. //
  3682. // Synopsis: Unicode to Ansi wrapper for the win32 RasSetSubEntryProperties API.
  3683. //
  3684. // Arguments: See the win32 API definition
  3685. //
  3686. // Returns: See the win32 API definition
  3687. //
  3688. // History: SumitC Created 10/26/99
  3689. //
  3690. //-----------------------------------------------------------------------------
  3691. DWORD APIENTRY
  3692. RasSetSubEntryPropertiesUA(LPCWSTR pszwPhoneBook, LPCWSTR pszwSubEntry,
  3693. DWORD dwSubEntry, LPRASSUBENTRYW pRasSubEntryW,
  3694. DWORD dwSubEntryInfoSize, LPBYTE pbDeviceConfig,
  3695. DWORD dwcbDeviceConfig)
  3696. {
  3697. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3698. MYDBGASSERT(NULL == pbDeviceConfig); // must currently be NULL
  3699. MYDBGASSERT(0 == dwcbDeviceConfig); // must currently be 0
  3700. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3701. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3702. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnSetEntryProperties);
  3703. if (pszwSubEntry && dwSubEntryInfoSize && pRasSubEntryW && pAnsiRasLinkage && pAnsiRasLinkage->pfnSetSubEntryProperties)
  3704. {
  3705. //
  3706. // The phonebook should always be NULL on win9x
  3707. //
  3708. MYDBGASSERT(NULL == pszwPhoneBook);
  3709. CHAR szAnsiSubEntry [RAS_MaxEntryName + 1];
  3710. RASSUBENTRYA AnsiRasSubEntry;
  3711. ZeroMemory(&AnsiRasSubEntry, sizeof(RASSUBENTRYA));
  3712. DWORD dwTmpEntrySize = sizeof(RASSUBENTRYA);
  3713. int iChars = WzToSz(pszwSubEntry, szAnsiSubEntry, RAS_MaxEntryName);
  3714. if (iChars && (RAS_MaxEntryName >= iChars))
  3715. {
  3716. //
  3717. // Do conversion of RASSUBENTRYW to RASSUBENTRYA
  3718. //
  3719. AnsiRasSubEntry.dwSize = sizeof(RASSUBENTRYA);
  3720. AnsiRasSubEntry.dwfFlags = pRasSubEntryW->dwfFlags;
  3721. //
  3722. // Device
  3723. //
  3724. MYVERIFY(0 != WzToSz(pRasSubEntryW->szDeviceType, AnsiRasSubEntry.szDeviceType, RAS_MaxDeviceType));
  3725. MYVERIFY(0 != WzToSz(pRasSubEntryW->szDeviceName, AnsiRasSubEntry.szDeviceName, RAS_MaxDeviceName));
  3726. //
  3727. // Location/phone number.
  3728. //
  3729. MYVERIFY(0 != WzToSz(pRasSubEntryW->szLocalPhoneNumber, AnsiRasSubEntry.szLocalPhoneNumber, RAS_MaxPhoneNumber));
  3730. CMASSERTMSG(0 == pRasSubEntryW->dwAlternateOffset, TEXT("RasSetSubEntryPropertiesUA -- dwAlternateOffset != 0 is not supported. This will need to be implemented if used."));
  3731. AnsiRasSubEntry.dwAlternateOffset = 0;
  3732. dwReturn = pAnsiRasLinkage->pfnSetSubEntryProperties(NULL, szAnsiSubEntry, dwSubEntry,
  3733. &AnsiRasSubEntry, dwTmpEntrySize, NULL, 0);
  3734. }
  3735. }
  3736. return dwReturn;
  3737. }
  3738. //+----------------------------------------------------------------------------
  3739. //
  3740. // Function: RasDeleteSubEntryUA
  3741. //
  3742. // Synopsis: Unicode to Ansi wrapper for the win32 RasDeleteSubEntry API.
  3743. //
  3744. // Arguments: See the win32 API definition
  3745. //
  3746. // Returns: See the win32 API definition
  3747. //
  3748. // History: SumitC Created 12/14/99
  3749. //
  3750. //-----------------------------------------------------------------------------
  3751. DWORD APIENTRY
  3752. RasDeleteSubEntryUA(LPCWSTR pszwPhoneBook, LPCWSTR pszwEntry, DWORD dwSubEntryId)
  3753. {
  3754. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3755. //
  3756. // The phonebook should always be NULL on win9x
  3757. //
  3758. MYDBGASSERT(NULL == pszwPhoneBook);
  3759. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3760. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3761. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnDeleteSubEntry);
  3762. if (pszwEntry && pAnsiRasLinkage && pAnsiRasLinkage->pfnDeleteSubEntry)
  3763. {
  3764. CHAR szAnsiEntry [RAS_MaxEntryName + 1];
  3765. int iChars = WzToSz(pszwEntry, szAnsiEntry, RAS_MaxEntryName);
  3766. if (iChars && (RAS_MaxEntryName >= iChars))
  3767. {
  3768. dwReturn = pAnsiRasLinkage->pfnDeleteSubEntry(NULL, szAnsiEntry, dwSubEntryId);
  3769. }
  3770. }
  3771. return dwReturn;
  3772. }
  3773. //+----------------------------------------------------------------------------
  3774. //
  3775. // Function: RasGetProjectionInfoUA
  3776. //
  3777. // Synopsis: Unicode to Ansi wrapper for the win32 RasGetProjectionInfo API.
  3778. //
  3779. // Arguments: See the win32 API definition
  3780. //
  3781. // Returns: See the win32 API definition
  3782. //
  3783. // History: SumitC Created 02-Oct-2001
  3784. //
  3785. //-----------------------------------------------------------------------------
  3786. DWORD APIENTRY
  3787. RasGetProjectionInfoUA(HRASCONN hRasConn, RASPROJECTION RasProj, LPVOID lpprojection, LPDWORD lpcb)
  3788. {
  3789. DWORD dwReturn = ERROR_INVALID_PARAMETER;
  3790. MYDBGASSERT(RASP_PppIp == RasProj); // this is the only one we support for now.
  3791. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3792. MYDBGASSERT(NULL != pAnsiRasLinkage);
  3793. MYDBGASSERT(NULL != pAnsiRasLinkage->pfnGetProjectionInfo);
  3794. if ((RASP_PppIp == RasProj) && pAnsiRasLinkage && pAnsiRasLinkage->pfnGetProjectionInfo)
  3795. {
  3796. RASPPPIPA AnsiProjInfo;
  3797. DWORD dwBufSize = 0;
  3798. RASPPPIPW * p = (RASPPPIPW *) lpprojection;
  3799. if (p)
  3800. {
  3801. dwBufSize = sizeof(RASPPPIPA);
  3802. ZeroMemory(&AnsiProjInfo, dwBufSize);
  3803. AnsiProjInfo.dwSize = dwBufSize;
  3804. }
  3805. dwReturn = pAnsiRasLinkage->pfnGetProjectionInfo(hRasConn, RASP_PppIp, (p ? (PVOID)&AnsiProjInfo : NULL), &dwBufSize);
  3806. if ((ERROR_SUCCESS == dwReturn) && (NULL != p))
  3807. {
  3808. p->dwSize = sizeof(RASPPPIPW);
  3809. // copy any DWORDs over
  3810. p->dwError = AnsiProjInfo.dwError;
  3811. // but the 2 strings have to be converted
  3812. int iChars = SzToWz(AnsiProjInfo.szIpAddress, p->szIpAddress, RAS_MaxIpAddress);
  3813. if (!iChars || (iChars > RAS_MaxIpAddress))
  3814. {
  3815. dwReturn = GetLastError();
  3816. CMASSERTMSG(FALSE, TEXT("RasGetProjectionInfoUA -- Failed to convert szIpAddress to Unicode."));
  3817. }
  3818. else
  3819. {
  3820. iChars = SzToWz(AnsiProjInfo.szServerIpAddress, p->szServerIpAddress, RAS_MaxIpAddress);
  3821. if (!iChars || (iChars > RAS_MaxIpAddress))
  3822. {
  3823. dwReturn = GetLastError();
  3824. CMASSERTMSG(FALSE, TEXT("RasGetProjectionInfoUA -- Failed to convert szServerIpAddress to Unicode."));
  3825. }
  3826. }
  3827. }
  3828. }
  3829. return dwReturn;
  3830. }
  3831. //+----------------------------------------------------------------------------
  3832. //
  3833. // Function: FreeCmRasUtoA
  3834. //
  3835. // Synopsis: Unloads the RAS dlls (rasapi32.dll and rnaph.dll) and cleans up
  3836. // the RAS linkage structure. To get more details about the cmutoa
  3837. // RAS linkage see InitCmRasUtoA and cmdial\ras.cpp\LinkToRas.
  3838. //
  3839. // Arguments: Nothing
  3840. //
  3841. // Returns: Nothing
  3842. //
  3843. // History: quintinb Created 7/15/99
  3844. //
  3845. //+----------------------------------------------------------------------------
  3846. void FreeCmRasUtoA()
  3847. {
  3848. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3849. CMASSERTMSG(pAnsiRasLinkage, TEXT("FreeCmRasUtoA -- RasLinkage hasn't been established yet. Why are we calling FreeCmRasUtoA now?"));
  3850. if (pAnsiRasLinkage)
  3851. {
  3852. if (pAnsiRasLinkage->hInstRas)
  3853. {
  3854. FreeLibrary(pAnsiRasLinkage->hInstRas);
  3855. }
  3856. if (pAnsiRasLinkage->hInstRnaph)
  3857. {
  3858. FreeLibrary(pAnsiRasLinkage->hInstRnaph);
  3859. }
  3860. CmFree(pAnsiRasLinkage);
  3861. TlsSetValue(g_dwTlsIndex, (LPVOID)NULL);
  3862. }
  3863. }
  3864. //+----------------------------------------------------------------------------
  3865. //
  3866. // Function: InitCmRasUtoA
  3867. //
  3868. // Synopsis: Function to Initialize the Unicode to ANSI conversion layer for
  3869. // RAS functions. In order to make the LinkToRas stuff work the
  3870. // same on win9x and on NT (all come from one dll) we have Cmdial32.dll
  3871. // link to cmutoa and get all of the RAS Entry points through Cmutoa.dll.
  3872. // In order to make this work, we need to keep function pointers to all of
  3873. // the RAS Dll's in memory. In order to prevent two cmdial's on different
  3874. // threads from calling InitCmRasUtoA and FreeCmRasUtoA at the wrong times
  3875. // (one thread freeing right after another had initialized would leave
  3876. // the first thread in a broken state), we usesthread local storage
  3877. // to hold a pointer to a RasLinkageStructA. This makes us thread safe
  3878. // and allows us to only have to init the RAS pointers once per thread
  3879. // (having multiple Cmdials in the same thread is pretty unlikely anyway).
  3880. // See cmdial\ras.cpp\LinkToRas for more details on the cmdial side of
  3881. // things.
  3882. //
  3883. // Arguments: Nothing
  3884. //
  3885. // Returns: BOOL -- TRUE if all of the requested APIs were loaded properly.
  3886. //
  3887. // History: quintinb Created 7/15/99
  3888. //
  3889. //+----------------------------------------------------------------------------
  3890. BOOL InitCmRasUtoA()
  3891. {
  3892. BOOL bReturn = TRUE;
  3893. BOOL bTryRnaph = FALSE;
  3894. //
  3895. // First Try to get the RasLinkageStruct out of Thread Local Storage, we
  3896. // may already be initialized.
  3897. //
  3898. RasLinkageStructA* pAnsiRasLinkage = (RasLinkageStructA*)TlsGetValue(g_dwTlsIndex);
  3899. CMASSERTMSG(NULL == pAnsiRasLinkage, TEXT("InitCmRasUtoA -- RasLinkage Already established. Why are we calling InitCmRasUtoA more than once?"));
  3900. if (NULL == pAnsiRasLinkage)
  3901. {
  3902. //
  3903. // Then we haven't linked to RAS yet, first allocate the struct
  3904. //
  3905. pAnsiRasLinkage = (RasLinkageStructA*)CmMalloc(sizeof(RasLinkageStructA));
  3906. if (!pAnsiRasLinkage)
  3907. {
  3908. return FALSE;
  3909. }
  3910. //
  3911. // Now that we have a structure, lets start filling it in. Try getting all of
  3912. // the entry points out of RasApi32.dll first, then try rnaph.dll if necessary.
  3913. //
  3914. pAnsiRasLinkage->hInstRas = LoadLibraryExA("rasapi32.dll", NULL, 0);
  3915. CMASSERTMSG(NULL != pAnsiRasLinkage->hInstRas, TEXT("InitCmRasUtoA -- Unable to load rasapi32.dll. Failing Ras Link."));
  3916. // before doing this, fix up the array based on whether we are on
  3917. // Millennium or not. The function below exists only on Millennium
  3918. if (!OS_MIL)
  3919. {
  3920. c_ArrayOfRasFuncsA[11] = NULL; //RasSetSubEntryProperties
  3921. c_ArrayOfRasFuncsA[12] = NULL; //RasDeleteSubEntry
  3922. }
  3923. if (pAnsiRasLinkage->hInstRas)
  3924. {
  3925. for (int i = 0 ; c_ArrayOfRasFuncsA[i] ; i++)
  3926. {
  3927. pAnsiRasLinkage->apvPfnRas[i] = GetProcAddress(pAnsiRasLinkage->hInstRas, c_ArrayOfRasFuncsA[i]);
  3928. if (!(pAnsiRasLinkage->apvPfnRas[i]))
  3929. {
  3930. bTryRnaph = TRUE;
  3931. }
  3932. }
  3933. }
  3934. //
  3935. // If we missed a few, then we need to get them from rnaph.dll
  3936. //
  3937. if (bTryRnaph)
  3938. {
  3939. pAnsiRasLinkage->hInstRnaph = LoadLibraryExA("rnaph.dll", NULL, 0);
  3940. CMASSERTMSG(NULL != pAnsiRasLinkage->hInstRnaph, TEXT("InitCmRasUtoA -- Unable to load Rnaph.dll. Failing Ras Link."));
  3941. if (pAnsiRasLinkage->hInstRnaph)
  3942. {
  3943. for (int i = 0 ; c_ArrayOfRasFuncsA[i] ; i++)
  3944. {
  3945. if (NULL == pAnsiRasLinkage->apvPfnRas[i])
  3946. {
  3947. pAnsiRasLinkage->apvPfnRas[i] = GetProcAddress(pAnsiRasLinkage->hInstRnaph, c_ArrayOfRasFuncsA[i]);
  3948. if (!(pAnsiRasLinkage->apvPfnRas[i]))
  3949. {
  3950. bReturn = FALSE;
  3951. }
  3952. }
  3953. }
  3954. }
  3955. }
  3956. //
  3957. // Always save the pAnsiRasLinkage value to thread local storage, if the linkage wasn't successful
  3958. // we will call FreeCmRasUtoA to clean it up. If it was successful we need to maintain it for later
  3959. // use. Note that the first thing FreeCmRasUtoA does is get the Ras Linkage struct pointer out of
  3960. // thread local storage because that is were it would reside under normal operation.
  3961. //
  3962. TlsSetValue(g_dwTlsIndex, (LPVOID)pAnsiRasLinkage);
  3963. if (!bReturn)
  3964. {
  3965. //
  3966. // Ras Linkage failed for some reason. We need to free up any resources we
  3967. // may have partially filled in.
  3968. //
  3969. FreeCmRasUtoA();
  3970. }
  3971. }
  3972. return bReturn;
  3973. }
  3974. //+----------------------------------------------------------------------------
  3975. //
  3976. // Function: SHGetPathFromIDListUA
  3977. //
  3978. // Synopsis: Unicode to Ansi wrapper for the win32 SHGetPathFromIDList API.
  3979. //
  3980. // Arguments: See the win32 API definition
  3981. //
  3982. // Returns: See the win32 API definition
  3983. //
  3984. // History: quintinb Created 7/15/99
  3985. //
  3986. //+----------------------------------------------------------------------------
  3987. BOOL SHGetPathFromIDListUA(LPCITEMIDLIST pidl, LPWSTR pszPath)
  3988. {
  3989. BOOL bReturn = FALSE;
  3990. if (pidl && pszPath)
  3991. {
  3992. CHAR szAnsiPath[MAX_PATH+1];
  3993. bReturn = SHGetPathFromIDListA(pidl, szAnsiPath);
  3994. if (bReturn)
  3995. {
  3996. int iChars = SzToWz(szAnsiPath, pszPath, MAX_PATH); // don't know correct length but
  3997. // the API says the path should be at
  3998. // least MAX_PATH
  3999. if (!iChars || (MAX_PATH < (DWORD)iChars))
  4000. {
  4001. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  4002. bReturn = FALSE;
  4003. }
  4004. }
  4005. }
  4006. return bReturn;
  4007. }
  4008. //+----------------------------------------------------------------------------
  4009. //
  4010. // Function: SHGetSpecialFolderLocationUA
  4011. //
  4012. // Synopsis: While the win32 SHGetSpecialFolderLocation API doesn't actually
  4013. // require any conversion between Unicode and ANSI, CM's shell dll
  4014. // class can only take one dll to take entry points from. Thus I
  4015. // was forced to add these here so that the class could get all the
  4016. // shell APIs it needed from cmutoa.dll.
  4017. //
  4018. // Arguments: See the win32 API definition
  4019. //
  4020. // Returns: See the win32 API definition
  4021. //
  4022. // History: quintinb Created 7/15/99
  4023. //
  4024. //+----------------------------------------------------------------------------
  4025. HRESULT SHGetSpecialFolderLocationUA(HWND hwnd, int csidl, LPITEMIDLIST *ppidl)
  4026. {
  4027. return SHGetSpecialFolderLocation(hwnd, csidl, ppidl);
  4028. }
  4029. //+----------------------------------------------------------------------------
  4030. //
  4031. // Function: SHGetMallocUA
  4032. //
  4033. // Synopsis: While the win32 SHGetMalloc API doesn't actually
  4034. // require any conversion between Unicode and ANSI, CM's shell dll
  4035. // class can only take one dll to take entry points from. Thus I
  4036. // was forced to add these here so that the class could get all the
  4037. // shell APIs it needed from cmutoa.dll.
  4038. //
  4039. // Arguments: See the win32 API definition
  4040. //
  4041. // Returns: See the win32 API definition
  4042. //
  4043. // History: quintinb Created 7/15/99
  4044. //
  4045. //+----------------------------------------------------------------------------
  4046. HRESULT SHGetMallocUA(LPMALLOC * ppMalloc)
  4047. {
  4048. return SHGetMalloc(ppMalloc);
  4049. }
  4050. //+----------------------------------------------------------------------------
  4051. //
  4052. // Function: ShellExecuteExUA
  4053. //
  4054. // Synopsis: Unicode to Ansi wrapper for the win32 ShellExecuteEx API.
  4055. // Note that we do note convert the lpIDList param of the
  4056. // SHELLEXECUTEINFOW struct because it is just a binary blob. Thus
  4057. // figuring out how to convert it if we don't know what it is. If
  4058. // we need this in the future we will have to deal with it on a case
  4059. // by case basis.
  4060. //
  4061. // Arguments: See the win32 API definition
  4062. //
  4063. // Returns: See the win32 API definition
  4064. //
  4065. // History: quintinb Created 7/15/99
  4066. //
  4067. //+----------------------------------------------------------------------------
  4068. BOOL ShellExecuteExUA(LPSHELLEXECUTEINFOW pShellInfoW)
  4069. {
  4070. BOOL bReturn = FALSE;
  4071. SHELLEXECUTEINFOA ShellInfoA;
  4072. ZeroMemory(&ShellInfoA, sizeof(ShellInfoA));
  4073. if (pShellInfoW)
  4074. {
  4075. ShellInfoA.cbSize = sizeof(ShellInfoA);
  4076. ShellInfoA.fMask = pShellInfoW->fMask;
  4077. ShellInfoA.hwnd = pShellInfoW->hwnd;
  4078. if (pShellInfoW->lpVerb)
  4079. {
  4080. ShellInfoA.lpVerb = WzToSzWithAlloc(pShellInfoW->lpVerb);
  4081. if (NULL == ShellInfoA.lpVerb)
  4082. {
  4083. goto exit;
  4084. }
  4085. }
  4086. if (pShellInfoW->lpFile)
  4087. {
  4088. ShellInfoA.lpFile = WzToSzWithAlloc(pShellInfoW->lpFile);
  4089. if (NULL == ShellInfoA.lpFile)
  4090. {
  4091. goto exit;
  4092. }
  4093. }
  4094. if (pShellInfoW->lpParameters)
  4095. {
  4096. ShellInfoA.lpParameters = WzToSzWithAlloc(pShellInfoW->lpParameters);
  4097. if (NULL == ShellInfoA.lpParameters)
  4098. {
  4099. goto exit;
  4100. }
  4101. }
  4102. if (pShellInfoW->lpDirectory)
  4103. {
  4104. ShellInfoA.lpDirectory = WzToSzWithAlloc(pShellInfoW->lpDirectory);
  4105. if (NULL == ShellInfoA.lpDirectory)
  4106. {
  4107. goto exit;
  4108. }
  4109. }
  4110. ShellInfoA.nShow = pShellInfoW->nShow;
  4111. ShellInfoA.hInstApp = pShellInfoW->hInstApp;
  4112. //
  4113. // Since this is a binary blob conversion could be difficult.
  4114. // We also don't currently use it, so I won't spend the cycles implementing it now.
  4115. //
  4116. MYDBGASSERT(NULL == pShellInfoW->lpIDList);
  4117. ShellInfoA.lpIDList = NULL;
  4118. if (pShellInfoW->lpClass)
  4119. {
  4120. ShellInfoA.lpClass = WzToSzWithAlloc(pShellInfoW->lpClass);
  4121. if (NULL == ShellInfoA.lpClass)
  4122. {
  4123. goto exit;
  4124. }
  4125. }
  4126. ShellInfoA.hkeyClass = pShellInfoW->hkeyClass;
  4127. ShellInfoA.hIcon = pShellInfoW->hIcon; // hIcon/hMonitor is a union so we only need one of them to get the mem
  4128. // HANDLE hProcess this is a return param dealt with below.
  4129. //
  4130. // Finally call ShellExecuteExA
  4131. //
  4132. bReturn = ShellExecuteExA(&ShellInfoA);
  4133. if (ShellInfoA.hProcess)
  4134. {
  4135. //
  4136. // The Caller asked for the process handle so send it back.
  4137. //
  4138. pShellInfoW->hProcess = ShellInfoA.hProcess;
  4139. }
  4140. }
  4141. exit:
  4142. CmFree((void*)ShellInfoA.lpVerb);
  4143. CmFree((void*)ShellInfoA.lpFile);
  4144. CmFree((void*)ShellInfoA.lpParameters);
  4145. CmFree((void*)ShellInfoA.lpDirectory);
  4146. CmFree((void*)ShellInfoA.lpClass);
  4147. return bReturn;
  4148. }
  4149. //+----------------------------------------------------------------------------
  4150. //
  4151. // Function: Shell_NotifyIconUA
  4152. //
  4153. // Synopsis: Unicode to Ansi wrapper for the win32 Shell_NotifyIcon API.
  4154. //
  4155. // Arguments: See the win32 API definition
  4156. //
  4157. // Returns: See the win32 API definition
  4158. //
  4159. // History: quintinb Created 7/15/99
  4160. //
  4161. //+----------------------------------------------------------------------------
  4162. BOOL Shell_NotifyIconUA (DWORD dwMessage, PNOTIFYICONDATAW pnidW)
  4163. {
  4164. BOOL bReturn = FALSE;
  4165. if (pnidW)
  4166. {
  4167. NOTIFYICONDATAA nidA;
  4168. ZeroMemory (&nidA, sizeof(NOTIFYICONDATAA));
  4169. nidA.cbSize = sizeof(NOTIFYICONDATAA);
  4170. nidA.hWnd = pnidW->hWnd;
  4171. nidA.uID = pnidW->uID;
  4172. nidA.uFlags = pnidW->uFlags;
  4173. nidA.uCallbackMessage = pnidW->uCallbackMessage;
  4174. nidA.hIcon = pnidW->hIcon;
  4175. int iChars = WzToSz(pnidW->szTip, nidA.szTip, 64); // 64 is the length of the szTip in the 4.0 struct
  4176. if (!iChars || (64 < iChars))
  4177. {
  4178. nidA.szTip[0] = '\0';
  4179. }
  4180. bReturn = Shell_NotifyIconA(dwMessage, &nidA);
  4181. }
  4182. return bReturn;
  4183. }