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.

174 lines
2.8 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  3. Module Name:
  4. ntutil.c
  5. Abstract:
  6. This is provides basic utilities for the NT DLL.
  7. Author:
  8. Steven Zeck (stevez) 03/04/92
  9. --*/
  10. #include <nsi.h>
  11. #include <string.h>
  12. void
  13. AsciiToUnicodeNT(
  14. OUT unsigned short *String,
  15. IN unsigned char *AsciiString
  16. )
  17. /*++
  18. Routine Description:
  19. Convert a ASCII string to unicode via the NT librarys
  20. Arguments:
  21. String - place to put result
  22. AsciiString - string to convert
  23. --*/
  24. {
  25. while(*String++ = RtlAnsiCharToUnicodeChar ((PUCHAR *) &AsciiString)) ;
  26. }
  27. int
  28. UnicodeToAscii(
  29. unsigned short *WideCharString
  30. )
  31. /*++
  32. Routine Description:
  33. Make a ASCII string from an UNICODE string. This is done in
  34. place so the string becomes ASCII.
  35. Arguments:
  36. UnicodeString - unicode string to convert
  37. Returns:
  38. RPC_S_OK, RPC_S_OUT_OF_MEMORY
  39. --*/
  40. {
  41. NTSTATUS NtStatus;
  42. UNICODE_STRING UnicodeString;
  43. ANSI_STRING AnsiString;
  44. RtlInitUnicodeString(&UnicodeString, WideCharString);
  45. NtStatus = RtlUnicodeStringToAnsiString(&AnsiString,&UnicodeString,TRUE);
  46. if (!NT_SUCCESS(NtStatus))
  47. return(RPC_S_OUT_OF_MEMORY);
  48. strcpy((char *)WideCharString, AnsiString.Buffer);
  49. RtlFreeAnsiString(&AnsiString);
  50. return(RPC_S_OK);
  51. }
  52. static RTL_CRITICAL_SECTION GlobalMutex;
  53. extern "C" {
  54. int
  55. InitializeDLL (
  56. IN void * DllHandle,
  57. IN ULONG Reason,
  58. IN PCONTEXT Context OPTIONAL
  59. )
  60. /*++
  61. Routine Description:
  62. NT DLL initialization function. Allocate/free the global MUTEX.
  63. Arguments:
  64. DllHandle - my module handle
  65. Reason - why this funciton is being called
  66. Context - the context pointer.
  67. Returns:
  68. 0 if there were no error during initialization, non 0 otherwise.
  69. --*/
  70. {
  71. NTSTATUS Status;
  72. UNUSED(Context);
  73. if (Reason == DLL_PROCESS_ATTACH)
  74. {
  75. #ifndef RPC_NT31
  76. // API added for NT 3.11, don't call when building for NT 3.1
  77. DisableThreadLibraryCalls((HMODULE)DllHandle);
  78. #endif
  79. Status = RtlInitializeCriticalSection(&GlobalMutex);
  80. if (! NT_SUCCESS(Status) )
  81. return(FALSE);
  82. }
  83. if (Reason == DLL_PROCESS_DETACH)
  84. {
  85. Status = RtlDeleteCriticalSection(&GlobalMutex);
  86. }
  87. return(TRUE);
  88. }
  89. }
  90. void
  91. GlobalMutexRequest (
  92. void
  93. )
  94. /*++
  95. Routine Description:
  96. Request the global mutex.
  97. --*/
  98. {
  99. NTSTATUS Status;
  100. Status = RtlEnterCriticalSection(&GlobalMutex);
  101. }
  102. void
  103. GlobalMutexClear (
  104. void
  105. )
  106. /*++
  107. Routine Description:
  108. Clear the global mutex.
  109. --*/
  110. {
  111. NTSTATUS Status;
  112. Status = RtlLeaveCriticalSection(&GlobalMutex);
  113. }