Figure 1: Spying on an in-process COM server
HMODULE hMod = ::LoadLibrary (comname); if (NULL==hMod){ MessageBox (NULL, "Can't Find", comname, MB_OK); return 1; } HKEY hklm = 0; HKEY hkcr = 0; DWORD dwr=0; // Find DllregisterServer, prepare to call it ProcDllReg DLLRegisterServer = (ProcDllReg)::GetProcAddress( hMod,"DllRegisterServer" ) ; if (DLLRegisterServer != NULL) { long lc = RegCreateKeyEx (HKEY_CURRENT_USER, keycr, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkcr, &dwr); lc = RegOverridePredefKey (HKEY_CLASSES_ROOT, hkcr); lc = RegCreateKeyEx (HKEY_CURRENT_USER, keylm, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hklm, &dwr); lc = RegOverridePredefKey (HKEY_LOCAL_MACHINE, hklm); ProcDllReg DLLRegisterServer = (ProcDllReg)::GetProcAddress(hMod,"DllRegisterServer" ) ; HRESULT regResult = DLLRegisterServer() ; RegOverridePredefKey (HKEY_CLASSES_ROOT, NULL); RegOverridePredefKey (HKEY_LOCAL_MACHINE, NULL); RegCloseKey (hkcr); RegCloseKey (hklm); } else { MessageBox (NULL, "DllRegisterServer Not Exported", comname, MB_OK); } ::FreeLibrary (hMod); /* End of File */