Dependence side by side between C ++ and C #

I am creating a browser plugin using the FireBreath Framework. Most of the logic is written in C # and to call from the browser I created a C ++ wrapper. Browsers are called C ++. The source code that invokes the "proxy" managed C ++ code, which invokes the real logic in a C # project.

So I have 3 dlls:

  • Start a native C ++ dll, which depends on managed C ++;
  • Managed C ++, which depends on C #;
  • C # dll that contains the core logic.

All 3 DLLs installed in the user directory (c: \ Users \\ AppData \ Roaming \ MyCompany \ MyApp \ 1.0.0.0)

The problem is that the browser does not load the C # dll. I use the Side by Side manifest to declare dependencies.

I tried to create a separate manifest file for the assembly declaration:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity name="MyAssembly" processorArchitecture="*" type="win32" version="1.0.0.0"/> <file name="FirstDependency.dll"/> <file name="SecondDependency.dll"/> </assembly> 

and added a link to this dependency to the main dll (Native C ++):

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <dependency> <dependentAssembly> <assemblyIdentity name="MyAssembly" processorArchitecture="*" type="win32" version="1.0.0.0"/> </dependentAssembly> </dependency> </assembly> 

Also I tried to declare the dependency directly in the dll head (Native C ++):

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <file name="FirstDependency.dll"/> <file name="SecondDependency.dll"/> </assembly> 

Tried to bind dependent dlls using the #pragma directive:

  #pragma comment(linker, "\"/manifestdependency:type='win32' name='FirstDependency' version='1.0.0.0' processorArchitecture='X86' language='*'\"") #pragma comment(linker, "\"/manifestdependency:type='win32' name='SecondDependency' version='1.0.0.0' processorArchitecture='X86' language='*'\"") 

I checked the dependencies using Dependency Walker and confirmed that the dependency between Managed C ++ and C # does not exist.

The plugin has access to the host dll (Native C ++), and it also loads Managed C ++, but when Managed C ++ causes the C # dll to fail, the plugin, the C # assembly cannot be found.

If I put C # dll in the same directory using a browser application (firefox.exe or chrome.exe) - it works.

It seems that the dependency between sites does not work between managed C ++ and C #.

How can I load dependent dlls for my plugin?

+4
source share
2 answers

I decided.

Added ResolveEventHandler handler for C ++ / CLI proxy assembly, which loads the C # assembly from the user's directory.

+2
source

I'm afraid I don't know anything about manifests about using Firebreath or assembling an assembly, but you have a potential workaround.

Have you considered using C ++ / CLI to provide a wrapper between native C ++ code and C #? If you are compiling on Windows in VisualStudio, C ++ lib can be done to allow mixed managed / native code by simply setting the / clr switch. You can then reference the C # assembly directly from your mixed C ++ / CLI library and call it directly. While the C # assembly is in the same directory, it should work.

In fact, you can go further and define the whole assembly as mixed C ++ / CLI - import all managed elements into this DLL. If you already have extended code in C #, I would not advise you to do this, but this is what you need to consider in the future.

Yours faithfully,

0
source

Source: https://habr.com/ru/post/1392422/


All Articles