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.

159 lines
2.0 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: loadlib.inl
  4. // Copyright (C) 1994-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. //
  8. //
  9. //-----------------------------------------------------------------------------
  10. inline
  11. CLoadLibrary::CLoadLibrary(void)
  12. {
  13. m_hDll = NULL;
  14. }
  15. inline
  16. HINSTANCE
  17. CLoadLibrary::GetHandle(void)
  18. const
  19. {
  20. return m_hDll;
  21. }
  22. inline
  23. CLoadLibrary::operator HINSTANCE(void)
  24. const
  25. {
  26. return GetHandle();
  27. }
  28. inline
  29. HINSTANCE
  30. CLoadLibrary::ExtractHandle(void)
  31. {
  32. HINSTANCE hReturn;
  33. hReturn = m_hDll;
  34. m_strFileName.Empty();
  35. m_hDll = NULL;
  36. return hReturn;
  37. }
  38. inline
  39. const CString &
  40. CLoadLibrary::GetFileName(void)
  41. const
  42. {
  43. return m_strFileName;
  44. }
  45. inline
  46. BOOL
  47. CLoadLibrary::LoadLibrary(
  48. const TCHAR *szFileName)
  49. {
  50. LTASSERT(m_hDll == NULL);
  51. m_strFileName = szFileName;
  52. m_hDll = AfxLoadLibrary(m_strFileName);
  53. return (m_hDll != NULL);
  54. }
  55. inline
  56. void
  57. CLoadLibrary::WrapLibrary(
  58. HINSTANCE hDll)
  59. {
  60. m_hDll = hDll;
  61. }
  62. inline
  63. CLoadLibrary::CLoadLibrary(
  64. const CLoadLibrary &llSource)
  65. {
  66. m_hDll = NULL;
  67. if (llSource.GetHandle() != NULL)
  68. {
  69. LoadLibrary(llSource.GetFileName());
  70. }
  71. }
  72. inline
  73. void
  74. CLoadLibrary::operator=(
  75. const CLoadLibrary &llSource)
  76. {
  77. LTASSERT(m_hDll == NULL);
  78. if (llSource.GetHandle() != NULL)
  79. {
  80. LoadLibrary(llSource.GetFileName());
  81. }
  82. }
  83. inline
  84. FARPROC
  85. CLoadLibrary::GetProcAddress(
  86. const TCHAR *szProcName)
  87. const
  88. {
  89. FARPROC fpFunction = NULL;
  90. if (m_hDll != NULL)
  91. {
  92. fpFunction = ::GetProcAddress(m_hDll, szProcName);
  93. }
  94. return fpFunction;
  95. }
  96. inline
  97. BOOL
  98. CLoadLibrary::FreeLibrary(void)
  99. {
  100. BOOL fRetVal = TRUE;
  101. if (m_hDll != NULL)
  102. {
  103. fRetVal = AfxFreeLibrary(m_hDll);
  104. m_hDll = NULL;
  105. m_strFileName.Empty();
  106. }
  107. return fRetVal;
  108. }
  109. inline
  110. CLoadLibrary::~CLoadLibrary()
  111. {
  112. FreeLibrary();
  113. }