[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 667
  • Last Modified:

What is the best way to make an inproc COM server out of proc?

I have the inproc COM object that I do not have the source for. I want to make it an out of proc so I can share one instance between all processes. I want to do this the most efficient way possible from a performance standpoint. The inproc COM object can be assumed thread and process safe for simplicity.

I could of course simply wrap* the COM object with my own out of proc server but is there a better solution? Just for example aggregation or something (I don't know much about COM aggregation so it may not even apply).


*Just as a note a fellow developer was telling me that inproc COM calls have a small amount of performace overhead. I'm not sure if I totally believe that but if it is the case, perhaps wrapping the inproc object will do just fine.

0
code_snake
Asked:
code_snake
  • 4
  • 4
1 Solution
 
JohnBPriceCommented:
Inproc COM calls (DLL style) have a much smaller perfromance overhead than out of proc (EXE style), if that is what you mean.  

Windows has a built-in inproc COM surrogate host to make in-proc into out-of-proc calls, called DLLHost.exe, which is used primarily when you have a distributed DLL style COM object.  The host computer needs a process to load the DLL, so DLLHost is used.  You could probably configure your in-proc COM object to "look like" a remote COM object by fiddling with dcomcnfg and the registry, but that might be more complicated than writing your own wrapper.
0
 
code_snakeAuthor Commented:
Well since I did not make the statement "inproc COM calls have a small amount of performace overhead" I am not totally sure what was meant by it or what it is relative to. I was looking at it as relative to no COM interface, such as direct DLL method invocation.

I'll have to look in to this DLLHost COM surrogate. Will it work for just any COM object, or does the COM object have to be written specially? Are there other types of COM "surrogates?"

Thanks.
0
 
JohnBPriceCommented:
I believe DLLHost will work for any COM object that obeys COM standards (string types and what not), but I'm not sure if it will work as a local host for a local object because it was designed to be a host on a separate machine.  Essentially on the client, when the COM object is registered, it is registered with DLLHost.exe as the executable name.  If you have the actual COM object already registered with the .DLL name, it might mess things up.  It might work if you explicitly ask for a remote object, e.g. in VB you do 'CreateObject  "MyProject.MyClass", "MachineName"' to create a remote object.  I don't know what would happen if you use the local machine for MachineName, it might just use the in-proc version.  I don't know of any others except what you write yourself.  Out-of-proc COM objects can add a lot of overhead if there are a lot of public properties that have to be marshalled between processes.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
code_snakeAuthor Commented:
I looked into it and that's actually not how it works.  It works fine for LocalServer. The COM object is registered just as normal but there is an added DllSurrogate value under the AppID key. It's that simple.

I've gotten it to work but not how I would like. The COM server does start in the surrogate but a new server is started for every object. I want one shared object.
0
 
JohnBPriceCommented:
Cool, how did you register it so as to get the DllSurrogate?
0
 
code_snakeAuthor Commented:
0
 
JohnBPriceCommented:
Neat, much easier than I expected.  Did you see this paragraph?

"It is best to configure a DLL server that is designed to run alone in its own surrogate process and to service multiple clients across a network with a RunAs value specified under the AppID registry key. Whether the RunAs specifies "Interactive User" or a specific user identity depends upon the user interface, security, and other server requirements. When a RunAs value is specified, only one instance of the server is loaded to service all of the clients, regardless of the identity of the client. On the other hand, do not configure the server with RunAs if the intention is to have one instance of the DLL server running in surrogate to service each remote client identity."
0
 
code_snakeAuthor Commented:
Yeah, I will have to try that later. I am running in to another issue now.

With the DLL Surrogate the COM server is not forced to run out of process, it just has the ability to do so through the surrogate. If a consumer creates an object still using the CLSCTX_INPROC_SERVER flag, the server is still created in proc. This is apparently how Internet Explorer crates objects. Strangely last night I could have swore that IE started mine out of process. I don't know, it was late and I was probably hallucinating.

So now the task is how to force COM consumers to create the COM object as CLSCTX_LOCAL_SERVER
0
 
moduloCommented:
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now