1
votes

I have several components (multiple .dlls, one .exe) which I need to use registration free. In my sxs manifest I've listed the dll files as;

<file name="xxx.dll"
  <comClass
    description="xxx component"
    clsid="{xxx-xxx}"
    threadingModel="Apartment" />
</file>

I have created and activated an Activation context and can call CoCreateInstance(); on these dll components without issue.

However, I also have a COM server singleton (as an .exe) that I need to run and I believe that you can only put dll files in the sxs manifest. I have its CLSID.

I'm restricted in that using regsvr is not an option for this, so is there an alternative way of being able to achieve this? Ideally having everything done programatically in the same place as where I am creating these other components.

1

1 Answers

0
votes

That is a bridge too far...to try and do it through manifests. However, you can do it manually. But, what you have to do is what the OS does. You have to:

  1. Call CreateProcess() with all the correct command line options
  2. Call WaitForInputIdle() on the process
  3. Make your COM calls

You'll probably also have to have entries for the interfaces you use if they are custom. I would probably recommend making them IDispatch compatible if at all possible.

To know what command line options are necessary, you'll have to register the server on your build machine and then look up the LocalServer32 registry key for the CLSID(s) and see what the arguments are. They can be a little different from each other if they are MFC or ATL, but usually ATL arguments are always the same unless you do something custom.

If for some reason the CreateObject() fails, then you probably will have to call TerminateProcess() on the process you created, otherwise you will have a bunch of orphaned processes. If you successfully create the object, the normal COM reference counting should be sufficient to shutdown the server process automatically.