Selecting a COM+ server at run time
Monday, July 26, 2004 05:58 PM
I just spent a couple of hours trying to figure this out. A customer of mine has a COM+ object (plain Win32 code, written in Delphi 5). They've started using Delphi 8, and needed to access the old objects from their .NET applications. It's easy enough when the object runs locally, or when a proxy is registered for the object. The problem was trying to select the server name at run time.
In Win32, this is easy: the CoCreateInstanceEx function lets you specify the server name. Searching MSDN Library and the web, however, only gave me information about using Marshal.BindToMoniker to connect to COM+ queued components. Unfortunately, the component in question was not queued.
Of course, the answer turned out to be painfully (literally) simple:
Obj := Activator.CreateInstance(
&Type.GetTypeFromProgID('MyDLL.MyInterface', 'ServerName', True));
You still have to register the interface on the client, but the actual instance will run on the selected server.