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.

161 lines
5.1 KiB

  1. #pragma warning(disable: 4201) // nameless struct/union
  2. #pragma warning(disable: 4514) // unreferenced inline function removed
  3. // --------------------------------------------------------------------------------
  4. // Includes
  5. // --------------------------------------------------------------------------------
  6. #include "pch.hxx"
  7. #include "shlwapi.h"
  8. //#include "shared.h"
  9. #define IMPLEMENT_LOADER_FUNCTIONS
  10. #include "demand.h"
  11. // --------------------------------------------------------------------------------
  12. // CRIT_GET_PROC_ADDR
  13. // --------------------------------------------------------------------------------
  14. #define CRIT_GET_PROC_ADDR(h, fn, temp) \
  15. temp = (TYP_##fn) GetProcAddress(h, #fn); \
  16. if (temp) \
  17. VAR_##fn = temp; \
  18. else \
  19. { \
  20. goto error; \
  21. }
  22. // --------------------------------------------------------------------------------
  23. // RESET
  24. // --------------------------------------------------------------------------------
  25. #define RESET(fn) VAR_##fn = LOADER_##fn;
  26. // --------------------------------------------------------------------------------
  27. // GET_PROC_ADDR
  28. // --------------------------------------------------------------------------------
  29. #define GET_PROC_ADDR(h, fn) \
  30. VAR_##fn = (TYP_##fn) GetProcAddress(h, #fn);
  31. // --------------------------------------------------------------------------------
  32. // GET_PROC_ADDR_ORDINAL
  33. // --------------------------------------------------------------------------------
  34. #define GET_PROC_ADDR_ORDINAL(h, fn, ord) \
  35. VAR_##fn = (TYP_##fn) GetProcAddress(h, MAKEINTRESOURCE(ord)); \
  36. Assert(VAR_##fn != NULL);
  37. // --------------------------------------------------------------------------------
  38. // GET_PROC_ADDR3
  39. // --------------------------------------------------------------------------------
  40. #define GET_PROC_ADDR3(h, fn, varname) \
  41. VAR_##varname = (TYP_##varname) GetProcAddress(h, #fn); \
  42. Assert(VAR_##varname != NULL);
  43. // --------------------------------------------------------------------------------
  44. // Static Globals
  45. // --------------------------------------------------------------------------------
  46. HMODULE s_hINetComm = 0;
  47. // --------------------------------------------------------------------------------
  48. // FreeDemandLoadedLibs
  49. // --------------------------------------------------------------------------------
  50. void FreeDemandLoadedLibs(void)
  51. {
  52. if (s_hINetComm)
  53. {
  54. FreeLibrary(s_hINetComm);
  55. s_hINetComm=NULL;
  56. }
  57. }
  58. // --------------------------------------------------------------------------------
  59. // SmartLoadLibrary
  60. // --------------------------------------------------------------------------------
  61. HINSTANCE SmartLoadLibrary(HKEY hKeyRoot, LPCSTR pszRegRoot, LPCSTR pszRegValue,
  62. LPCSTR pszDllName)
  63. {
  64. // Locals
  65. BOOL fProblem=FALSE;
  66. HINSTANCE hInst=NULL;
  67. HKEY hKey=NULL, hKey2 = NULL;
  68. CHAR szPath[MAX_PATH];
  69. DWORD cb=MAX_PATH;
  70. DWORD dwT;
  71. LPSTR pszPath=szPath;
  72. CHAR szT[MAX_PATH];
  73. // Try to open the regkey
  74. if (ERROR_SUCCESS != RegOpenKeyEx(hKeyRoot, pszRegRoot, 0, KEY_QUERY_VALUE, &hKey))
  75. goto exit;
  76. // Query the Value
  77. if (ERROR_SUCCESS != RegQueryValueEx(hKey, pszRegValue, 0, &dwT, (LPBYTE)szPath, &cb))
  78. goto exit;
  79. // Remove the file name from the path
  80. PathRemoveFileSpecA(szPath);
  81. PathAppendA(szPath, pszDllName);
  82. // Expand Sz ?
  83. if (REG_EXPAND_SZ == dwT)
  84. {
  85. // Expand It
  86. cb = ExpandEnvironmentStrings(szPath, szT, MAX_PATH);
  87. // Failure
  88. if (cb == 0 || cb > MAX_PATH)
  89. {
  90. goto exit;
  91. }
  92. // Change pszPath
  93. pszPath = szT;
  94. }
  95. // Try to Load Library the Dll
  96. hInst = LoadLibrary(pszPath);
  97. // Failure ?
  98. if (NULL == hInst)
  99. {
  100. // If we are not going to try the GetModuleFName, just try the dll name
  101. hInst = LoadLibrary(pszDllName);
  102. // We really failed
  103. if (NULL == hInst)
  104. {
  105. goto exit;
  106. }
  107. }
  108. exit:
  109. // Cleanup
  110. if (hKey)
  111. RegCloseKey(hKey);
  112. // Done
  113. return hInst;
  114. }
  115. // --------------------------------------------------------------------------------
  116. // DemandLoadINETCOMM
  117. // --------------------------------------------------------------------------------
  118. BOOL DemandLoadINETCOMM(void)
  119. {
  120. BOOL fRet = TRUE;
  121. if (0 == s_hINetComm)
  122. {
  123. s_hINetComm = SmartLoadLibrary(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Outlook Express\\Inetcomm", "DllPath", "INETCOMM.DLL");
  124. if (0 == s_hINetComm)
  125. fRet = FALSE;
  126. else
  127. {
  128. GET_PROC_ADDR(s_hINetComm, MimeEditViewSource);
  129. GET_PROC_ADDR(s_hINetComm, MimeEditCreateMimeDocument);
  130. }
  131. }
  132. return fRet;
  133. }