简体   繁体   中英

Registration-free COM and DLL location

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM