Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling native COM client stub in client, using VS2010

I'm new to COM programming, and creating a basic native COM server / client pair from Visual Studio 2010. Both the client and the server projects live in the same solution. I'd like to know what the most appropriate way is to include the generated client stub and header file in the client project. I've created the MIDL in my server project, and when I compile the project the _h.h, _i.c, and _p.c files are generated in my project source directory.

  • Do I need to compile both of the .c files in my client project?
  • Is the best way to compile these in the client project by adding them as linked files in the client project from the source directory of the server project?
  • Is there a way for Visual Studio to know that the _h.h, _i.c, and _p.c files are out of date when I modify the MIDL, or do I need to remember to recompile the server project any time I touch the MIDL?
  • Where's the best place for the .h file to go - can it go in the stdafx.h file in the server project? If so, is it proper to add the source directory of the server project to the header include directories of the client project?
  • Should the client project have a "Reference" (in the Visual Studio Reference sense) to the server project?

Additionally - I'd like to make this registration free. Is there anything extra I need to do in this case, besides having manifests for my client and server?

..

edit

Looking at the MSDN article here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366830(v=vs.85).aspx, it appears that of the files generated, if I only want to support in-proc reg-free activation, I only need to compile the _i.c and include the _h.h files in my client program.

dlldata.c, and _p.c appear to be used to create a proxy DLL, which supports registration on a remote computer (for activation by a remote computer? or also local computer, out of proc? If it's required for local computer, out of proc, why is it needed given that the COM server's dll is registered? The COM server DLL is different from the proxy DLL, yes?)

Thanks very much,

--Matt

like image 561
Matt Avatar asked Apr 17 '12 06:04

Matt


1 Answers

The generated _p.c and dlldata.c must be compiled into a separate project to build the proxy/stub DLL. You don't always need one, only when you marshal calls across apartments or processes.

The generated _i.c file provides the GUID values. Compile it into the server and the proxy/stub. Compiling it into the client is okay but using the __uuidof keyword is easiest.

The generated _i.h file contains the interface and coclass declarations. You'll need to #include it in the server and the client.

Midl.exe should automatically regenerate these files when you change the .idl. Which in turn ensures that client, server and proxy/stub get rebuilt.

stdafx.h is fine, yes on the include directory.

No on the "reference", the client and server have no link dependency.

You'll have to write the manifest for reg-free com and embed it in the client.

like image 90
Hans Passant Avatar answered Jan 22 '23 04:01

Hans Passant