Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create COM Surrogate server (exe) in C#

Tags:

c#

.net

com

I know how to create a COM DLL (a Class Library) in C#. Is it possible to create a COM Surrogate EXE using C#?

This would be a standalone server capable of launching and hosting COM objects, which would then be accessible to COM clients.

like image 770
santhosh Avatar asked May 18 '09 14:05

santhosh


People also ask

Is Dllhost exe COM Surrogate a virus?

It is a Trojan virus. The person with malicious intentions basically installed these types to monitor the activities of the user and to also steal sensitive data. This virus is linked to the file named “Dllhost.exe” and the pop-up for this error states “COM surrogate has stopped working”.

What is COM Surrogate exe?

The COM Surrogate is a fancy name for Sacrificial process for a COM object that is run outside of the process that requested it. Explorer uses the COM Surrogate when extracting thumbnails, for example.

What will happen if I end task com surrogate?

If the extension crashes, the Surrogate process will take the blow and not the software which was running it. As handy as it may seem, sometimes the COM Surrogate itself stops working and can cause you a lot of disconfort. Check out the article below to quickly find the right solutions to fix it.


2 Answers

The default surrogate process for COM - the thing that hosts COM DLLs, aka the COM Surrogate - is dllhost.exe. It is possible to create a surrogate process in C++. This article explains how.

But those APIs are not exposed in wrappers as part of the base class library in the .NET Framework. If you want to write to write only managed code, you need something else.

I see a couple options.

  1. The Visual Studio SDK, a free download that is intended for devs who want to extend Visual Studio. Within that SDK, there's a class lib that has such wrappers. In particular, look at the ISurrogate class.
    BUT, the VS SDK license says that the SDK is ok to use only for products that extend or add value to Visual Studio. I am no lawyer, but that is my understanding of the license, which is pretty clear. These terms means the VS SDK would not be useful for general app building.
    The one remaining question is, exactly how do you use the VS SDK technically to produce a COM Surrogate using only C# code? Again, here I don't know. I looked in the docs briefly for guides on using the ISurrogate wrapper, but found none.
  2. Use the code in this article.
    The article explores a bunch of different aspects around COM and .NET interop. Towards the end of the article it offers source code for building your own COM server in C#, complete with all the p/invoke calls to CoRegisterClassObject() and friends.
like image 130
Cheeso Avatar answered Sep 27 '22 17:09

Cheeso


I wanted to make same thing and found excellent project example CSExeCOMServer on All-In-One Code Framework. It actually reconstructs normal COM server logic by means of .NET and native calls to Windows API. But it looks all still overcomplicated. I suppose there is no simple and fast way to expose .NET objects as COM in out-of-process server and it is not the architecture of choice.

like image 22
Boris Zinchenko Avatar answered Sep 27 '22 18:09

Boris Zinchenko