3

I am learning how to implement an out-of-process COM server and came across this Code Project article, Building a LOCAL COM Server and Client: A Step by Step Example.

I can build it, and it runs fine, but where is the proxy/stub DLL? All I can see is the IDL file from which the proxy/stub code is generated during the build. But how is the DLL built, and where is it?

Richard Chambers
  • 16,643
  • 4
  • 81
  • 106
Dabbler
  • 9,733
  • 5
  • 41
  • 64

2 Answers2

6

The short answer is that all the interfaces are marked "oleautomation", so oleaut32.dll performs the marshaling, since COM knows how to marshal all the types used in the interfaces.

If "oleautomation" were missing, or a type was specified that COM doesn't know how to marshal by default (see the list here), your nondefault marshaler and its stub would be required.

Steve
  • 169
  • 6
4

You need Proxy/Stub project to help COM marshal your interfaces. When you create ATL C++ project with Visual Studio you typically have a secondary project with PS suffix created automatically, and this is your Proxy/Stub DLL. However, you might be doing fine without it at all (I personally never ever had to build and use it, even though I did have to deal with things like custom marshaling). If you provide type library with your project, it is registered and certain conditions are met - COM will supply automatic proxy/stub pair for you.

Bonus reading:

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Ok, thanks. I'll read up on the links you provided, and since the proxy/stub DLL seems to be optional, I'll consider the question answered. Can you recommend any books on learning COM? I have Inside COM by Dale Rogerson, which I think does a very good job of explaining in-process servers, but gets a bit superficial when it gets to servers in EXEs. – Dabbler Oct 20 '12 at 09:43
  • I think it is the only book on COM I ever read, and I think it was good. It is had for me to advise anything else off the cuff, I suppose one can do quite good with basics only, and making steps carefully, understanding what one's doing. EXE servers are not really that much different from in-procs and all APIs are well documented on MSDN. – Roman R. Oct 20 '12 at 11:24
  • It's not that simple, you still have to register the `HKCR\Interface\{iid}\ProxyStubClsid32` and TypeLib keys to get the standard marshaller that uses the type library. The CLSID is {00000320-0000-0000-C000-000000000046}. If you didn't and it still works then high odds that you are violating apartment rules by not marshaling the interface pointer. – Hans Passant Oct 20 '12 at 12:46
  • @HansPassant: You don't need to do it yourself, it comes "for free" with regular type library registration, provided that interface itself is `dual` (and/or `oleautomation` - not sure). – Roman R. Oct 20 '12 at 12:48
  • No, there's no way COM can find the type library from the interface IID if you don't add these keys. – Hans Passant Oct 20 '12 at 12:49
  • It perfectly finds without adding keys explicitly. – Roman R. Oct 20 '12 at 12:50
  • `ProxyStubClsid32` is created automatically: http://stackoverflow.com/a/1741981/868014 – Roman R. Oct 20 '12 at 12:59