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.

165 lines
3.3 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File:
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "JetBlue.h"
  13. //----------------------------------------------------------------
  14. BOOL
  15. ConvertMJBstrToMWstr(
  16. JB_STRING in,
  17. DWORD length,
  18. LPTSTR* out
  19. )
  20. /*
  21. */
  22. {
  23. #if defined(UNICODE) && !defined(JET_BLUE_SUPPORT_UNICODE)
  24. if(in == NULL)
  25. {
  26. *out = NULL;
  27. return TRUE;
  28. }
  29. int bufSize;
  30. bufSize = MultiByteToWideChar(
  31. GetACP(),
  32. MB_PRECOMPOSED,
  33. in,
  34. length,
  35. NULL,
  36. 0
  37. );
  38. if(bufSize == 0)
  39. {
  40. return FALSE;
  41. }
  42. *out = (LPTSTR)LocalAlloc(LPTR, bufSize * sizeof(TCHAR));
  43. if(*out == NULL)
  44. {
  45. return FALSE;
  46. }
  47. return (MultiByteToWideChar(
  48. GetACP(),
  49. MB_PRECOMPOSED,
  50. in,
  51. length,
  52. *out,
  53. bufSize
  54. ) != 0);
  55. #else
  56. *out = in;
  57. return TRUE;
  58. #endif
  59. }
  60. //----------------------------------------------------------------
  61. BOOL
  62. ConvertJBstrToWstr(
  63. JB_STRING in,
  64. LPTSTR* out
  65. )
  66. /*
  67. */
  68. {
  69. return ConvertMJBstrToMWstr(in, -1, out);
  70. }
  71. //----------------------------------------------------------------
  72. BOOL
  73. ConvertMWstrToMJBstr(
  74. LPCTSTR in,
  75. DWORD length,
  76. JB_STRING* out
  77. )
  78. /*
  79. */
  80. {
  81. #if defined(UNICODE) && !defined(JET_BLUE_SUPPORT_UNICODE)
  82. if(in == NULL)
  83. {
  84. *out = NULL;
  85. return TRUE;
  86. }
  87. int bufSize;
  88. bufSize = WideCharToMultiByte(
  89. GetACP(),
  90. 0,
  91. in,
  92. length,
  93. NULL,
  94. 0,
  95. NULL,
  96. NULL
  97. );
  98. if(bufSize == 0)
  99. {
  100. return FALSE;
  101. }
  102. *out = (LPSTR)LocalAlloc(LPTR, bufSize);
  103. if(*out == NULL)
  104. {
  105. return FALSE;
  106. }
  107. return (WideCharToMultiByte( GetACP(),
  108. 0,
  109. in,
  110. length,
  111. *out,
  112. bufSize,
  113. NULL,
  114. NULL) != 0);
  115. #else
  116. *out = in;
  117. return TRUE;
  118. #endif
  119. }
  120. //----------------------------------------------------------------
  121. BOOL
  122. ConvertWstrToJBstr(
  123. LPCTSTR in,
  124. JB_STRING* out
  125. )
  126. {
  127. return ConvertMWstrToMJBstr( in, -1, out );
  128. }
  129. //----------------------------------------------------------------
  130. void
  131. FreeJBstr( JB_STRING pstr )
  132. {
  133. #if defined(UNICODE) && !defined(JET_BLUE_SUPPORT_UNICODE)
  134. if(pstr)
  135. LocalFree(pstr);
  136. #endif
  137. }