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

108 lines
4.1 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. // verify that no illegal character present
  21. // since lpw was allocated based on the size of lpa
  22. // don't worry about the number of chars
  23. lpw[0] = '\0';
  24. MultiByteToWideChar(CP_ACP, 0, lpa, -1, lpw, nChars);
  25. return lpw;
  26. }
  27. LPSTR WINAPI AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars)
  28. {
  29. _ASSERTE(lpw != NULL);
  30. _ASSERTE(lpa != NULL);
  31. // verify that no illegal character present
  32. // since lpa was allocated based on the size of lpw
  33. // don't worry about the number of chars
  34. lpa[0] = '\0';
  35. WideCharToMultiByte(CP_ACP, 0, lpw, -1, lpa, nChars, NULL, NULL);
  36. return lpa;
  37. }
  38. #if defined(_WINGDI_) && !defined(NOGDI)
  39. // don't include this code when building DLL
  40. LPDEVMODEW AtlDevModeA2W(LPDEVMODEW lpDevModeW, LPDEVMODEA lpDevModeA)
  41. {
  42. if (lpDevModeA == NULL)
  43. return NULL;
  44. _ASSERTE(lpDevModeW != NULL);
  45. AtlA2WHelper(lpDevModeW->dmDeviceName, (LPCSTR)lpDevModeA->dmDeviceName, 32*sizeof(WCHAR));
  46. memcpy(&lpDevModeW->dmSpecVersion, &lpDevModeA->dmSpecVersion,
  47. offsetof(DEVMODEW, dmFormName) - offsetof(DEVMODEW, dmSpecVersion));
  48. AtlA2WHelper(lpDevModeW->dmFormName, (LPCSTR)lpDevModeA->dmFormName, 32*sizeof(WCHAR));
  49. memcpy(&lpDevModeW->dmLogPixels, &lpDevModeA->dmLogPixels,
  50. sizeof(DEVMODEW) - offsetof(DEVMODEW, dmLogPixels));
  51. if (lpDevModeA->dmDriverExtra != 0)
  52. memcpy(lpDevModeW+1, lpDevModeA+1, lpDevModeA->dmDriverExtra);
  53. lpDevModeW->dmSize = sizeof(DEVMODEW);
  54. return lpDevModeW;
  55. }
  56. LPTEXTMETRICW AtlTextMetricA2W(LPTEXTMETRICW lptmW, LPTEXTMETRICA lptmA)
  57. {
  58. if (lptmA == NULL)
  59. return NULL;
  60. _ASSERTE(lptmW != NULL);
  61. memcpy(lptmW, lptmA, sizeof(LONG) * 11);
  62. memcpy(&lptmW->tmItalic, &lptmA->tmItalic, sizeof(BYTE) * 5);
  63. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmFirstChar, 1, &lptmW->tmFirstChar, 1);
  64. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmLastChar, 1, &lptmW->tmLastChar, 1);
  65. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmDefaultChar, 1, &lptmW->tmDefaultChar, 1);
  66. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmBreakChar, 1, &lptmW->tmBreakChar, 1);
  67. return lptmW;
  68. }
  69. LPTEXTMETRICA AtlTextMetricW2A(LPTEXTMETRICA lptmA, LPTEXTMETRICW lptmW)
  70. {
  71. if (lptmW == NULL)
  72. return NULL;
  73. _ASSERTE(lptmA != NULL);
  74. memcpy(lptmA, lptmW, sizeof(LONG) * 11);
  75. memcpy(&lptmA->tmItalic, &lptmW->tmItalic, sizeof(BYTE) * 5);
  76. WideCharToMultiByte(CP_ACP, 0, &lptmW->tmFirstChar, 1, (LPSTR)&lptmA->tmFirstChar, 1, NULL, NULL);
  77. WideCharToMultiByte(CP_ACP, 0, &lptmW->tmLastChar, 1, (LPSTR)&lptmA->tmLastChar, 1, NULL, NULL);
  78. WideCharToMultiByte(CP_ACP, 0, &lptmW->tmDefaultChar, 1, (LPSTR)&lptmA->tmDefaultChar, 1, NULL, NULL);
  79. WideCharToMultiByte(CP_ACP, 0, &lptmW->tmBreakChar, 1, (LPSTR)&lptmA->tmBreakChar, 1, NULL, NULL);
  80. return lptmA;
  81. }
  82. LPDEVMODEA AtlDevModeW2A(LPDEVMODEA lpDevModeA, LPDEVMODEW lpDevModeW)
  83. {
  84. if (lpDevModeW == NULL)
  85. return NULL;
  86. _ASSERTE(lpDevModeA != NULL);
  87. AtlW2AHelper((LPSTR)lpDevModeA->dmDeviceName, lpDevModeW->dmDeviceName, 32*sizeof(char));
  88. memcpy(&lpDevModeA->dmSpecVersion, &lpDevModeW->dmSpecVersion,
  89. offsetof(DEVMODEA, dmFormName) - offsetof(DEVMODEA, dmSpecVersion));
  90. AtlW2AHelper((LPSTR)lpDevModeA->dmFormName, lpDevModeW->dmFormName, 32*sizeof(char));
  91. memcpy(&lpDevModeA->dmLogPixels, &lpDevModeW->dmLogPixels,
  92. sizeof(DEVMODEA) - offsetof(DEVMODEA, dmLogPixels));
  93. if (lpDevModeW->dmDriverExtra != 0)
  94. memcpy(lpDevModeA+1, lpDevModeW+1, lpDevModeW->dmDriverExtra);
  95. lpDevModeA->dmSize = sizeof(DEVMODEA);
  96. return lpDevModeA;
  97. }
  98. #endif //_WINGDI_
  99. #endif //!_ATL_NO_CONVERSIONS