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.

146 lines
3.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: SDLL.hxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 04-23-97 DanpoZ (Danpo Zhang) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef SDLL_HXX_
  18. #define SDLL_HXX_
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Class: CShellDll
  22. //
  23. // Purpose: class wrapper for calling API from delay
  24. // loaded shell32.dll
  25. //
  26. // Interface:
  27. //
  28. //
  29. // History: 04-24-97 DanpoZ (Danpo Zhang) Created
  30. //
  31. // Notes:
  32. //
  33. //----------------------------------------------------------------------------
  34. class CShellDll
  35. {
  36. public:
  37. #define DELAYSHELLAPI(_fn, _args, _nargs) \
  38. HINSTANCE _fn _args { \
  39. HRESULT hres = Init(); \
  40. HINSTANCE hI = NULL; \
  41. if (SUCCEEDED(hres)) { \
  42. hI = _pfn##_fn _nargs; \
  43. } \
  44. return hI; } \
  45. HINSTANCE (STDAPICALLTYPE* _pfn##_fn) _args;
  46. HRESULT Init();
  47. CShellDll();
  48. ~CShellDll();
  49. DELAYSHELLAPI( ShellExecuteA,
  50. ( HWND hwnd,
  51. LPCSTR lpOperation,
  52. LPCSTR lpFile,
  53. LPCSTR lpParameters,
  54. LPCSTR lpDirectory,
  55. INT nShowCmd
  56. ),
  57. ( hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd )
  58. )
  59. private:
  60. BOOL _fInited;
  61. HMODULE _hMod;
  62. };
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Method: CShellDll::CShellDll
  66. //
  67. // Synopsis:
  68. //
  69. // History: 04-24-97 DanpoZ (Danpo Zhang) Created
  70. //
  71. // Notes:
  72. //
  73. //----------------------------------------------------------------------------
  74. inline
  75. CShellDll::CShellDll()
  76. {
  77. _fInited = FALSE;
  78. _hMod = NULL;
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Method: CShellDll::~CShellDll
  83. //
  84. // Synopsis:
  85. //
  86. // History: 04-24-97 DanpoZ (Danpo Zhang) Created
  87. //
  88. // Notes:
  89. //
  90. //----------------------------------------------------------------------------
  91. inline
  92. CShellDll::~CShellDll()
  93. {
  94. if( _fInited)
  95. FreeLibrary(_hMod);
  96. }
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Method: CShellDll::Init
  100. //
  101. // Synopsis:
  102. //
  103. // History: 04-24-97 DanpoZ (Danpo Zhang) Created
  104. //
  105. // Notes:
  106. //
  107. //----------------------------------------------------------------------------
  108. inline
  109. HRESULT CShellDll::Init()
  110. {
  111. HRESULT hr = S_OK;
  112. if( !_fInited )
  113. {
  114. _hMod = LoadLibrary("shell32.dll");
  115. if( !_hMod )
  116. hr = HRESULT_FROM_WIN32(GetLastError());
  117. else
  118. {
  119. #define CHECKAPI(_fn) \
  120. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(_hMod, #_fn); \
  121. if( !(_pfn##_fn)) hr = E_UNEXPECTED;
  122. CHECKAPI(ShellExecuteA);
  123. }
  124. }
  125. if( hr == S_OK )
  126. _fInited = TRUE;
  127. return hr;
  128. }
  129. #endif