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.

230 lines
5.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: nt.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <windows.h>
  11. #include "unicode.h"
  12. #include "crtem.h" // bring in malloc+free definitions
  13. #ifdef _M_IX86
  14. BOOL WINAPI GetUserName9x(
  15. LPWSTR lpBuffer, // address of name buffer
  16. LPDWORD nSize // address of size of name buffer
  17. ) {
  18. char rgch[_MAX_PATH];
  19. char *szBuffer;
  20. DWORD cbBuffer;
  21. int cchW;
  22. BOOL fResult;
  23. szBuffer = rgch;
  24. cbBuffer = sizeof(rgch);
  25. fResult = GetUserNameA(
  26. szBuffer,
  27. &cbBuffer);
  28. if (!fResult)
  29. return FALSE;
  30. cbBuffer++; // count the NULL terminator
  31. if (sizeof(rgch) < cbBuffer)
  32. {
  33. szBuffer = (char *) malloc(cbBuffer);
  34. if(!szBuffer)
  35. {
  36. SetLastError(ERROR_OUTOFMEMORY);
  37. return FALSE;
  38. }
  39. fResult = GetUserNameA(
  40. szBuffer,
  41. &cbBuffer);
  42. cbBuffer++; // count the NULL terminator
  43. }
  44. if(fResult)
  45. {
  46. cchW = MultiByteToWideChar(
  47. 0, // codepage
  48. 0, // dwFlags
  49. szBuffer,
  50. cbBuffer,
  51. lpBuffer,
  52. *nSize);
  53. if(cchW == 0)
  54. fResult = FALSE;
  55. else
  56. *nSize = cchW - 1; // does not include NULL
  57. }
  58. if(szBuffer != rgch)
  59. free(szBuffer);
  60. return(fResult);
  61. }
  62. BOOL WINAPI GetUserNameU(
  63. LPWSTR lpBuffer, // address of name buffer
  64. LPDWORD nSize // address of size of name buffer
  65. ) {
  66. if(FIsWinNT())
  67. return( GetUserNameW(lpBuffer, nSize));
  68. else
  69. return( GetUserName9x(lpBuffer, nSize));
  70. }
  71. BOOL WINAPI GetComputerName9x(
  72. LPWSTR lpBuffer, // address of name buffer
  73. LPDWORD nSize // address of size of name buffer
  74. ) {
  75. char rgch[_MAX_PATH];
  76. char *szBuffer;
  77. DWORD cbBuffer;
  78. int cchW;
  79. BOOL fResult;
  80. szBuffer = rgch;
  81. cbBuffer = sizeof(rgch);
  82. fResult = GetComputerNameA(
  83. szBuffer,
  84. &cbBuffer);
  85. if (!fResult)
  86. return fResult;
  87. cbBuffer++; // count the NULL terminator
  88. if (sizeof(rgch) < cbBuffer)
  89. {
  90. szBuffer = (char *) malloc(cbBuffer);
  91. if(!szBuffer)
  92. {
  93. SetLastError(ERROR_OUTOFMEMORY);
  94. return FALSE;
  95. }
  96. fResult = GetComputerNameA(
  97. szBuffer,
  98. &cbBuffer);
  99. cbBuffer++; // count the NULL terminator
  100. }
  101. if(fResult)
  102. {
  103. cchW = MultiByteToWideChar(
  104. 0, // codepage
  105. 0, // dwFlags
  106. szBuffer,
  107. cbBuffer,
  108. lpBuffer,
  109. *nSize);
  110. if(cchW == 0)
  111. fResult = FALSE;
  112. else
  113. *nSize = cchW - 1; // does not include NULL
  114. }
  115. if(szBuffer != rgch)
  116. free(szBuffer);
  117. return(fResult);
  118. }
  119. BOOL WINAPI GetComputerNameU(
  120. LPWSTR lpBuffer, // address of name buffer
  121. LPDWORD nSize // address of size of name buffer
  122. ) {
  123. if(FIsWinNT())
  124. return( GetComputerNameW(lpBuffer, nSize));
  125. else
  126. return( GetComputerName9x(lpBuffer, nSize));
  127. }
  128. DWORD WINAPI GetModuleFileName9x(
  129. HMODULE hModule, // handle to module to find filename for
  130. LPWSTR lpFilename, // pointer to buffer for module path
  131. DWORD nSize // size of buffer, in characters
  132. ) {
  133. char rgch[_MAX_PATH];
  134. DWORD cbBuffer;
  135. DWORD cch;
  136. cbBuffer = sizeof(rgch);
  137. cch = GetModuleFileNameA(
  138. hModule,
  139. rgch,
  140. cbBuffer);
  141. if(cch == 0)
  142. return 0;
  143. return MultiByteToWideChar(
  144. 0, // codepage
  145. 0, // dwFlags
  146. rgch,
  147. cbBuffer,
  148. lpFilename,
  149. nSize);
  150. }
  151. DWORD WINAPI GetModuleFileNameU(
  152. HMODULE hModule, // handle to module to find filename for
  153. LPWSTR lpFilename, // pointer to buffer for module path
  154. DWORD nSize // size of buffer, in characters
  155. ) {
  156. if(FIsWinNT())
  157. return( GetModuleFileNameW(hModule, lpFilename, nSize));
  158. else
  159. return( GetModuleFileName9x(hModule, lpFilename, nSize));
  160. }
  161. HMODULE WINAPI GetModuleHandle9x(
  162. LPCWSTR lpModuleName // address of module name to return handle for
  163. ) {
  164. char * szBuffer = NULL;
  165. BYTE rgb1[_MAX_PATH];
  166. DWORD cbBuffer;
  167. HMODULE hModule;
  168. hModule = NULL;
  169. if(MkMBStr(rgb1, _MAX_PATH, lpModuleName, &szBuffer) )
  170. hModule = GetModuleHandleA(
  171. szBuffer);
  172. FreeMBStr(rgb1, szBuffer);
  173. return hModule;
  174. }
  175. HMODULE WINAPI GetModuleHandleU(
  176. LPCWSTR lpModuleName // address of module name to return handle for
  177. ) {
  178. if(FIsWinNT())
  179. return( GetModuleHandleW(lpModuleName));
  180. else
  181. return( GetModuleHandle9x(lpModuleName));
  182. }
  183. #endif // _M_IX86