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.

101 lines
2.1 KiB

  1. #ifdef __cplusplus
  2. // VERSION.DLL delay load
  3. class CVersion
  4. {
  5. public:
  6. #define DELAYVERAPI(_fn, _args, _nargs) \
  7. DWORD _fn _args { \
  8. HRESULT hres = Init(); \
  9. DWORD dwRet = 0; \
  10. if (SUCCEEDED(hres)) { \
  11. dwRet = _pfn##_fn _nargs; \
  12. } \
  13. return dwRet; } \
  14. DWORD (STDAPICALLTYPE* _pfn##_fn) _args;
  15. HRESULT Init(void);
  16. CVersion();
  17. ~CVersion();
  18. BOOL m_fInited;
  19. HMODULE m_hMod;
  20. DELAYVERAPI( VerInstallFileA,
  21. (DWORD uFlags,
  22. LPSTR szSrcFileName,
  23. LPSTR szDestFileName,
  24. LPSTR szSrcDir,
  25. LPSTR szDestDir,
  26. LPSTR szCurDir,
  27. LPSTR szTmpFile,
  28. PUINT lpuTmpFileLen),
  29. (uFlags, szSrcFileName, szDestFileName, szSrcDir, szDestDir,
  30. szCurDir, szTmpFile, lpuTmpFileLen));
  31. DELAYVERAPI( VerQueryValueA,
  32. (const LPVOID pBlock,
  33. LPSTR lpSubBlock,
  34. LPVOID * lplpBuffer,
  35. PUINT puLen),
  36. (pBlock, lpSubBlock, lplpBuffer, puLen));
  37. DELAYVERAPI( GetFileVersionInfoA,
  38. (LPSTR lptstrFilename,
  39. DWORD dwHandle,
  40. DWORD dwLen,
  41. LPVOID lpData),
  42. (lptstrFilename, dwHandle, dwLen, lpData));
  43. DELAYVERAPI( GetFileVersionInfoSizeA,
  44. (LPSTR lptstrFilename,
  45. LPDWORD lpdwHandle),
  46. (lptstrFilename, lpdwHandle));
  47. };
  48. inline
  49. CVersion::CVersion()
  50. {
  51. m_fInited = FALSE;
  52. }
  53. inline
  54. CVersion::~CVersion()
  55. {
  56. if (m_fInited) {
  57. FreeLibrary(m_hMod);
  58. }
  59. }
  60. inline
  61. HRESULT
  62. CVersion::Init(void)
  63. {
  64. if (m_fInited) {
  65. return S_OK;
  66. }
  67. m_hMod = LoadLibrary( "VERSION.DLL" );
  68. if (!m_hMod) {
  69. return HRESULT_FROM_WIN32(GetLastError());
  70. }
  71. #define CHECKAPI(_fn) \
  72. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(m_hMod, #_fn); \
  73. if (!(_pfn##_fn)) return E_UNEXPECTED;
  74. CHECKAPI(VerInstallFileA);
  75. CHECKAPI(VerQueryValueA);
  76. CHECKAPI(GetFileVersionInfoSizeA);
  77. CHECKAPI(GetFileVersionInfoA);
  78. m_fInited = TRUE;
  79. return S_OK;
  80. }
  81. #endif