Source code of Windows XP (NT5)
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.

63 lines
1.3 KiB

  1. #define DELAY_LOAD_HLINK
  2. struct Hlink
  3. {
  4. #ifdef DELAY_LOAD_HLINK
  5. #define DELAYHLINKAPI(_fn, _args, _nargs) \
  6. HRESULT _fn _args { \
  7. HRESULT hres = _Init(); \
  8. if (SUCCEEDED(hres)) \
  9. hres = _pfn##_fn _nargs; \
  10. return hres; } \
  11. HRESULT (STDAPICALLTYPE* _pfn##_fn) _args;
  12. HRESULT _Init(void);
  13. // _fInited must be the first member
  14. BOOL _fInited;
  15. HMODULE _hmod;
  16. #else
  17. #define DELAYHLINKAPI(_fn, _args, _nargs) \
  18. HRESULT _fn _args { return ::#_fn _nargs; }
  19. #endif
  20. DELAYHLINKAPI(CreateURLMoniker,
  21. (LPCWSTR pwsURL, IMoniker ** ppimk),
  22. (pwsURL, ppimk));
  23. DELAYHLINKAPI(HlinkParseDisplayName,
  24. (LPBC pbc, LPCOLESTR pozDisplayName, ULONG* pcchEaten, IMoniker** ppimk),
  25. (pbc, pozDisplayName, pcchEaten, ppimk));
  26. };
  27. #ifdef DELAY_LOAD_HLINK
  28. HRESULT Hlink::_Init(void)
  29. {
  30. if (_fInited) {
  31. return S_OK;
  32. }
  33. _fInited = TRUE;
  34. _hmod = LoadLibrary(TEXT("HLINKD.DLL"));
  35. if (!_hmod) {
  36. return E_UNEXPECTED;
  37. }
  38. #define CHECKAPI(_fn) \
  39. *(FARPROC*)&(_pfn##_fn) = GetProcAddress(_hmod, #_fn); \
  40. if (!(_pfn##_fn)) return E_UNEXPECTED;
  41. CHECKAPI(CreateURLMoniker);
  42. CHECKAPI(HlinkParseDisplayName);
  43. return S_OK;
  44. }
  45. #endif
  46. #ifdef DELAY_LOAD_HLINK
  47. Hlink g_hlinkdll = { FALSE } ;
  48. #else // DELAY_LOAD_HLINK
  49. Hlink g_hlinkdll;
  50. #endif // DELAY_LOAD_HLINK