0

My C++ app was required to communicate with a web application. Since writing in C++ was hard I wrote the web application client in C# (DLL), COM enabled it, and called it from C++ app and it worked.

But the C++ app can be installed on a server PC, its folder shared over a network, mapped to a drive on a client PC, and run from there. When I tried running so, it doesn't run because it is expecting the C# DLL to be registered on the client PC. I would like to avoid it. I would like to keep them both on the server. Is it possible to do it using registration-free COM? If yes, can the C# DLL (and its dependent DLLs) be placed in a folder different to the C++ EXE folder?

  • 1
    *Is it possible to do it using registration-free COM?* Yes. *Can the C# DLL (and its dependent DLLs) be placed in a folder different to the C++ EXE folder?* Yes. – David Heffernan Oct 05 '15 at 10:41
  • That makes no sense at all. You are having this problem because the EXE has a hard time finding the DLL. Putting in a different folder just gives it, you know, a hard time finding the DLL. Only putting it in the same folder as the EXE makes sense so the manifest doesn't have to specify the path. – Hans Passant Oct 05 '15 at 10:55
  • From the comment of @DavidHeffernan, a Google search for *registration-free COM* would have given following links on SO: http://stackoverflow.com/q/465882/ and http://stackoverflow.com/q/9162817/ - before reading this comment I strongly believed it was not possible :-( – Serge Ballesta Oct 05 '15 at 12:40

1 Answers1

2

I see this is an outdated post. Hope you had found out a solution or a workaround. Anyhow, I shall answer as it may help someone with the same problem.

Is it possible to do it using registration-free COM?

Yes, it is. Follow this MSDN article. You will have to create a manifest for the c# com dll and embed the manifest into it. Which would be with the help of a RT_MANIFEST resource. That article is a little outdated, so you may face problem with .net framework version. If you did, you will need to specify the .net framework version in your machine. You can simply replace the clrclass line with this :

<clrClass
            clsid="{16AD5303-E154-44B4-A72B-C129859714AD}"
            progid="SideBySide.SideBySide"
            threadingModel="Both"
            name="SideBySide.SideBySideClass"
            runtimeVersion="v4.0.30319" >

can the C# DLL (and its dependent DLLs) be placed in a folder different to the C++ EXE folder?

Yes, it can be. But I wouldn't recommend it. According to this resource, the assembly loader searches for assembly manifests in the following order :

Side-by-side searches the WinSxS folder.
\\<appdir>\<assemblyname>.DLL
\\<appdir>\<assemblyname>.manifest
\\<appdir>\<assemblyname>\<assemblyname>.DLL
\\<appdir>\<assemblyname>\<assemblyname>.manifest

The above locations are respective to the application (appdir). If you want your dll to be elsewhere, then you can use the file element of the assembly manifest (the name attribute can include a path), see here for more details and other elements.

Hope this helps someone.

Shameel Mohamed
  • 607
  • 5
  • 23