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.

100 lines
2.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994.
  5. //
  6. // File: hkLdInP.h
  7. //
  8. // Contents: Inline function to load the DLL of an inproc server
  9. //
  10. // Functions:
  11. //
  12. // History: 01-Sep-94 Don Wright Created
  13. // 08-Sep-94 Garry Lenz Separate into two functions
  14. // 14-Nov-94 Don Wright Make LogEvent messages more complete
  15. //
  16. //--------------------------------------------------------------------------
  17. #ifndef _LDINPROC_H_
  18. #define _LDINPROC_H_
  19. #include <Windows.h>
  20. #include <TChar.h>
  21. #include "hkregkey.h"
  22. #include "hkLogEvt.h"
  23. #include "hkole32x.h"
  24. #define MAX_CLSID 39 // Length of CLSID string including zero terminator
  25. enum ELOGEVENT
  26. {
  27. eDontLogEvents,
  28. eLogEvents
  29. };
  30. inline HINSTANCE LOADINPROCSERVER(WCHAR* wszClsid, ELOGEVENT eLog=eLogEvents)
  31. {
  32. WCHAR szEventSource[] = L"HookOleLoadInprocServer";
  33. CHAR szInProc32[] = "InprocServer32";
  34. CHAR szClsidKey[MAX_PATH];
  35. CHAR szDllName[MAX_PATH];
  36. WCHAR wszDllName[MAX_PATH];
  37. CHAR szClsid[MAX_CLSID];
  38. WCHAR szMessageBuff[1024];
  39. long lSize = sizeof(szDllName);
  40. LONG lRegResults;
  41. HINSTANCE hDll = NULL;
  42. strcpy(szClsidKey,szCLSIDKey);
  43. strcat(szClsidKey,KEY_SEP);
  44. WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, wszClsid, -01, szClsid, sizeof (szClsid), NULL, NULL);
  45. strcat(szClsidKey,szClsid);
  46. strcat(szClsidKey,KEY_SEP);
  47. strcat(szClsidKey,szInProc32);
  48. lRegResults = RegQueryValueA(HKEY_CLASSES_ROOT,
  49. szClsidKey,
  50. szDllName,
  51. &lSize);
  52. if (lRegResults == ERROR_SUCCESS)
  53. {
  54. if (hDll == 0)
  55. {
  56. hDll = LoadLibraryA(szDllName);
  57. if ((eLog == eLogEvents) && (hDll == 0))
  58. {
  59. lstrcpyW(szMessageBuff,L"Error loading library - ");
  60. MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, szDllName, -1, wszDllName, lstrlenA(szDllName)+1);
  61. lstrcatW(szMessageBuff,wszDllName);
  62. lstrcatW(szMessageBuff,L" for CLSID ");
  63. lstrcatW(szMessageBuff,wszClsid);
  64. LogEvent(szEventSource,szMessageBuff);
  65. }
  66. }
  67. }
  68. else if (eLog == eLogEvents)
  69. {
  70. lstrcpyW(szMessageBuff,L"Error reading registry for CLSID!");
  71. lstrcatW(szMessageBuff,wszClsid);
  72. LogEvent(szEventSource,szMessageBuff);
  73. }
  74. return hDll;
  75. }
  76. inline HINSTANCE LOADINPROCSERVER(REFCLSID rclsid, ELOGEVENT eLog=eLogEvents)
  77. {
  78. WCHAR szClsid[MAX_CLSID];
  79. HRESULT hResult;
  80. HINSTANCE hDll = NULL;
  81. hResult = StringFromGUID2(rclsid,szClsid,sizeof(szClsid));
  82. if (SUCCEEDED(hResult))
  83. {
  84. hDll = LOADINPROCSERVER(szClsid, eLogEvents);
  85. }
  86. return hDll;
  87. }
  88. #endif //_LDINPROC_H_