Accessing a remote COM object through C #

I have an exe file written using unmanaged C ++ that contains a COM object. To access it from a C # managed application, I created the interop assembly. I was able to use this with great success when both applications were running on the same PC.

Now I have a requirement to make the C # application access the COM object on the remote PC, and the existing code gave me some problems. I had to make small changes, for example.

Type ReportItemSetup = Type.GetTypeFromProgID("ACME.REPORTITEMSETUP.1", remotePCName); RpiSetup = (IReportItemSetup)Activator.CreateInstance(ReportItemSetup); 

has become

 Guid gris = new Guid("{147FF3D1-8A00-11F0-9A6C-0000C099D00B}"); Type ReportItemSetup = Type.GetTypeFromCLSID(gris, remotePCName, true); RpiSetup = (IReportItemSetup)Activator.CreateInstance(ReportItemSetup); 

This allowed me to improve the code a bit, but then I ran into another problem.

I use:

 REPORTITEMSETUPClass rpis = new REPORTITEMSETUPClass(); 

where REPORTTIEMSETUPClass (edited for brevity)

 namespace Acme.ReportItemServers.Interop { [ClassInterface(ClassInterfaceType.None)] [TypeLibType(TypeLibTypeFlags.FAppObject | TypeLibTypeFlags.FCanCreate | TypeLibTypeFlags.FPreDeclId)] [ComConversionLoss] [Guid("147FF3D1-8A00-11F0-9A6C-0000C099D00B")] public class REPORTITEMSETUPClass : IReportItemSetup, REPORTITEMSETUP, INotifySrc { public REPORTITEMSETUPClass(); ... snip ... public virtual void INotifySrc_AddUser(INotify pNotify, string bstrUserName); ... snip ... } } 

I need to make an AddUser call on the INotifySrc interface, but a new call causes an error:

 Retrieving the COM class factory for component with CLSID {147FF3D1-8A00-11F0-9A6C-0000C099D00B} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). 

This error is absolutely correct, as it is not registered on the local machine.

My question is this: is it possible to use registration on a remote PC? Activator.CreateInstance had no problem that the class was not registered locally.

+4
source share
2 answers

I think you should write a serviced component to do this. This is due to some COM + magic and can be quite complicated. Check out the summary here: http://msdn.microsoft.com/en-us/library/3x7357ez%28v=vs.71%29.aspx

0
source

Subclass System.EnterpriseServices.ServicedComponent and then install it in COM + on the server, then export the COM + (msi) proxy from the server and install this proxy on the client.

0
source

Source: https://habr.com/ru/post/1340660/


All Articles