Simulating SideBySide for Out of Process ActiveX

怎甘沉沦 提交于 2019-12-04 13:09:00

It is possible to do. What is needed:

  • An application needs to start a server itself rather than relying on COM to do it. You don't need the extra indirection provided by the registry, just use CreateProcess().
  • A server should register its class factories in its main() method with CoRegisterClassObject().
  • Important: the CLSID it uses for each factory should be altered to be unique for each service instance. This ensures that the client connects to the correct server. I simply XOR the process ID with a class factory CLSID. The client knows the process ID as well so can make the same alteration.
  • The application should call CoCreateInstance() in a loop with a Sleep() call to wait for the object factory to appear. Don't declare failure until at least 60 seconds have passed (that bit me).
  • Both the application and the server need a manifest that contains a <file> element for each proxy/stub DLL and <comInterfaceExternProxyStub> elements for each interface that is remoted.

Alex,

nobugz is right, you can access the Running Object Table to create an instance of a COM Object from a currently running process of your Delphi automation exe.

However I have found a big issue that I cant explain. I can only access the object via the variant dispatch method when working this way.

Basically if my Active X exe is not registered, I get an "Interface Not Supported" error if I try to instance the object through interfaces for example:

WebUpdate : IAutomation;

WebUpdate := CoAutomation.Create; <-- Wont Work Error


WebUpdate : Variant;

WebUpdate := CreateOleObject('WebUpdate.Automation'); <-- Works Fine

If I register the active x exe using regserver the problem goes away!!

Go Figure!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!