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.

151 lines
3.3 KiB

  1. //*************************************************************
  2. //
  3. // DLL loading functions
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1995 - 2000
  7. // All rights reserved
  8. //
  9. //*************************************************************
  10. #include "rsop.hxx"
  11. //
  12. // file global variables containing pointers to APIs and
  13. // loaded modules
  14. //
  15. OLE32_API g_Ole32Api;
  16. CRITICAL_SECTION g_ApiDLLCritSec;
  17. //*************************************************************
  18. //
  19. // InitializeAPIs()
  20. //
  21. // Purpose: initializes API structures for delay loaded
  22. // modules
  23. //
  24. // Parameters: none
  25. //
  26. //
  27. // Return: none
  28. //
  29. //*************************************************************
  30. void InitializeAPIs( void )
  31. {
  32. ZeroMemory( &g_Ole32Api, sizeof( OLE32_API ) );
  33. }
  34. //*************************************************************
  35. //
  36. // InitializeApiDLLsCritSec()
  37. //
  38. // Purpose: initializes a CRITICAL_SECTION for synch'ing
  39. // DLL loads
  40. //
  41. // Parameters: none
  42. //
  43. //
  44. // Return: none
  45. //
  46. //*************************************************************
  47. void InitializeApiDLLsCritSec( void )
  48. {
  49. InitializeCriticalSection( &g_ApiDLLCritSec );
  50. }
  51. //*************************************************************
  52. //
  53. // CloseApiDLLsCritSec()
  54. //
  55. // Purpose: clean up CRITICAL_SECTION for synch'ing
  56. // DLL loads
  57. //
  58. // Parameters: none
  59. //
  60. //
  61. // Return: none
  62. //
  63. //*************************************************************
  64. void CloseApiDLLsCritSec( void )
  65. {
  66. DeleteCriticalSection( &g_ApiDLLCritSec );
  67. }
  68. //*************************************************************
  69. //
  70. // LoadOle32Api()
  71. //
  72. // Purpose: Loads ole32.dll
  73. //
  74. // Parameters: none
  75. //
  76. // Return: pointer to OLE32_API
  77. //
  78. //*************************************************************
  79. POLE32_API LoadOle32Api()
  80. {
  81. BOOL bResult = FALSE;
  82. OLE32_API *pOle32Api = &g_Ole32Api;
  83. if ( pOle32Api->hInstance ) {
  84. //
  85. // module already loaded and initialized
  86. //
  87. return pOle32Api;
  88. }
  89. pOle32Api->hInstance = LoadLibrary (TEXT("ole32.dll"));
  90. if (!pOle32Api->hInstance) {
  91. goto Exit;
  92. }
  93. pOle32Api->pfnCoCreateInstance = (PFNCOCREATEINSTANCE) GetProcAddress (pOle32Api->hInstance,
  94. "CoCreateInstance");
  95. if (!pOle32Api->pfnCoCreateInstance) {
  96. goto Exit;
  97. }
  98. pOle32Api->pfnCoInitializeEx = (PFNCOINITIALIZEEX) GetProcAddress (pOle32Api->hInstance,
  99. "CoInitializeEx");
  100. if (!pOle32Api->pfnCoInitializeEx) {
  101. goto Exit;
  102. }
  103. pOle32Api->pfnCoUnInitialize = (PFNCOUNINITIALIZE) GetProcAddress (pOle32Api->hInstance,
  104. "CoUninitialize");
  105. if (!pOle32Api->pfnCoUnInitialize) {
  106. goto Exit;
  107. }
  108. //
  109. // Success
  110. //
  111. bResult = TRUE;
  112. Exit:
  113. if (!bResult) {
  114. if ( pOle32Api->hInstance ) {
  115. FreeLibrary( pOle32Api->hInstance );
  116. }
  117. ZeroMemory( pOle32Api, sizeof( OLE32_API ) );
  118. pOle32Api = 0;
  119. }
  120. return pOle32Api;
  121. }