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.

168 lines
4.9 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __ATLCONV_H__
  11. #error atlconv.cpp requires atlconv.h to be included first
  12. #endif
  13. #ifndef _ATL_NO_CONVERSIONS
  14. /////////////////////////////////////////////////////////////////////////////
  15. // Global UNICODE<>ANSI translation helpers
  16. LPWSTR WINAPI AtlA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars)
  17. {
  18. _ASSERTE(lpa != NULL);
  19. _ASSERTE(lpw != NULL);
  20. if (lpw == NULL || lpa == NULL)
  21. return NULL;
  22. // verify that no illegal character present
  23. // since lpw was allocated based on the size of lpa
  24. // don't worry about the number of chars
  25. lpw[0] = '\0';
  26. int ret = MultiByteToWideChar(CP_ACP, 0, lpa, -1, lpw, nChars);
  27. if(ret == 0)
  28. {
  29. _ASSERTE(FALSE);
  30. return NULL;
  31. }
  32. return lpw;
  33. }
  34. LPSTR WINAPI AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars)
  35. {
  36. _ASSERTE(lpw != NULL);
  37. _ASSERTE(lpa != NULL);
  38. if (lpa == NULL || lpw == NULL)
  39. return NULL;
  40. // verify that no illegal character present
  41. // since lpa was allocated based on the size of lpw
  42. // don't worry about the number of chars
  43. lpa[0] = '\0';
  44. int ret = WideCharToMultiByte(CP_ACP, 0, lpw, -1, lpa, nChars, NULL, NULL);
  45. if(ret == 0)
  46. {
  47. _ASSERTE(FALSE);
  48. return NULL;
  49. }
  50. return lpa;
  51. }
  52. #if defined(_WINGDI_) && !defined(NOGDI)
  53. // don't include this code when building DLL
  54. LPDEVMODEW AtlDevModeA2W(LPDEVMODEW lpDevModeW, LPDEVMODEA lpDevModeA)
  55. {
  56. if (lpDevModeA == NULL || lpDevModeW == NULL)
  57. return NULL;
  58. _ASSERTE(lpDevModeW != NULL);
  59. AtlA2WHelper(lpDevModeW->dmDeviceName, (LPCSTR)lpDevModeA->dmDeviceName, 32);
  60. memcpy(&lpDevModeW->dmSpecVersion, &lpDevModeA->dmSpecVersion,
  61. offsetof(DEVMODEW, dmFormName) - offsetof(DEVMODEW, dmSpecVersion));
  62. AtlA2WHelper(lpDevModeW->dmFormName, (LPCSTR)lpDevModeA->dmFormName, 32);
  63. memcpy(&lpDevModeW->dmLogPixels, &lpDevModeA->dmLogPixels,
  64. sizeof(DEVMODEW) - offsetof(DEVMODEW, dmLogPixels));
  65. if (lpDevModeA->dmDriverExtra != 0)
  66. memcpy(lpDevModeW+1, lpDevModeA+1, lpDevModeA->dmDriverExtra);
  67. lpDevModeW->dmSize = sizeof(DEVMODEW);
  68. return lpDevModeW;
  69. }
  70. LPTEXTMETRICW AtlTextMetricA2W(LPTEXTMETRICW lptmW, LPTEXTMETRICA lptmA)
  71. {
  72. if (lptmA == NULL || lptmW == NULL)
  73. return NULL;
  74. _ASSERTE(lptmW != NULL);
  75. memcpy(lptmW, lptmA, sizeof(LONG) * 11);
  76. memcpy(&lptmW->tmItalic, &lptmA->tmItalic, sizeof(BYTE) * 5);
  77. if(MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmFirstChar, 1, &lptmW->tmFirstChar, 1) == 0)
  78. {
  79. _ASSERTE(FALSE);
  80. return NULL;
  81. }
  82. if(MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmLastChar, 1, &lptmW->tmLastChar, 1) == 0)
  83. {
  84. _ASSERTE(FALSE);
  85. return NULL;
  86. }
  87. if(MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmDefaultChar, 1, &lptmW->tmDefaultChar, 1) == 0)
  88. {
  89. _ASSERTE(FALSE);
  90. return NULL;
  91. }
  92. if(MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmBreakChar, 1, &lptmW->tmBreakChar, 1) == 0)
  93. {
  94. _ASSERTE(FALSE);
  95. return NULL;
  96. }
  97. return lptmW;
  98. }
  99. LPTEXTMETRICA AtlTextMetricW2A(LPTEXTMETRICA lptmA, LPTEXTMETRICW lptmW)
  100. {
  101. if (lptmW == NULL || lptmA == NULL)
  102. return NULL;
  103. _ASSERTE(lptmA != NULL);
  104. memcpy(lptmA, lptmW, sizeof(LONG) * 11);
  105. memcpy(&lptmA->tmItalic, &lptmW->tmItalic, sizeof(BYTE) * 5);
  106. if(WideCharToMultiByte(CP_ACP, 0, &lptmW->tmFirstChar, 1, (LPSTR)&lptmA->tmFirstChar, 1, NULL, NULL) == 0)
  107. {
  108. _ASSERTE(FALSE);
  109. return NULL;
  110. }
  111. if(WideCharToMultiByte(CP_ACP, 0, &lptmW->tmLastChar, 1, (LPSTR)&lptmA->tmLastChar, 1, NULL, NULL) == 0)
  112. {
  113. _ASSERTE(FALSE);
  114. return NULL;
  115. }
  116. if(WideCharToMultiByte(CP_ACP, 0, &lptmW->tmDefaultChar, 1, (LPSTR)&lptmA->tmDefaultChar, 1, NULL, NULL) == 0)
  117. {
  118. _ASSERTE(FALSE);
  119. return NULL;
  120. }
  121. if(WideCharToMultiByte(CP_ACP, 0, &lptmW->tmBreakChar, 1, (LPSTR)&lptmA->tmBreakChar, 1, NULL, NULL) == 0)
  122. {
  123. _ASSERTE(FALSE);
  124. return NULL;
  125. }
  126. return lptmA;
  127. }
  128. LPDEVMODEA AtlDevModeW2A(LPDEVMODEA lpDevModeA, LPDEVMODEW lpDevModeW)
  129. {
  130. if (lpDevModeW == NULL || lpDevModeA == NULL)
  131. return NULL;
  132. _ASSERTE(lpDevModeA != NULL);
  133. AtlW2AHelper((LPSTR)lpDevModeA->dmDeviceName, lpDevModeW->dmDeviceName, 32);
  134. memcpy(&lpDevModeA->dmSpecVersion, &lpDevModeW->dmSpecVersion,
  135. offsetof(DEVMODEA, dmFormName) - offsetof(DEVMODEA, dmSpecVersion));
  136. AtlW2AHelper((LPSTR)lpDevModeA->dmFormName, lpDevModeW->dmFormName, 32);
  137. memcpy(&lpDevModeA->dmLogPixels, &lpDevModeW->dmLogPixels,
  138. sizeof(DEVMODEA) - offsetof(DEVMODEA, dmLogPixels));
  139. if (lpDevModeW->dmDriverExtra != 0)
  140. memcpy(lpDevModeA+1, lpDevModeW+1, lpDevModeW->dmDriverExtra);
  141. lpDevModeA->dmSize = sizeof(DEVMODEA);
  142. return lpDevModeA;
  143. }
  144. #endif //_WINGDI_
  145. #endif //!_ATL_NO_CONVERSIONS