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.

160 lines
1.8 KiB

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