English 中文(简体)
How a native C++ plug-in DLL can load a private assembly located in a specific directory
原标题:

I have a native C++ DLL which is used as a plug-in in another application. This DLL has an embedded manifest and depends on a private assembly located in a folder external to the application. The application fails to load my plug-in DLL because my DLL depends on a private assembly which is never found (it is not located in the application directory, nor in the winsxs folder but in my plug-in directory whose location is not controlled by the application). The question is: how is it possible to make the system find my private assembly which is located in my own specific directory ? As an analogy, I would need an equivalent of setDllDirectory() but for assemblies. Or another way so that the system find my private assembly.

Constraints:

Because my DLL is a plug-in, I cannot install anything in the directory and sub-directories of the application. I also cannot modify the behavior of the application.
I would like to avoid sharing the assembly in winsxs.
I also have to use an assembly and not a simple DLL (that I could load with LoadLibrary) to avoid version conflicts.

Thanks.

问题回答

you need to have a global location where you could give a list of directories that form your (from java-terminology) class-path. Once you have this list just traverse the directories looking for dll s.

I have used the Registry in windows for this. An environment variable or the /etc folder under linux would also do.

This is how linkers do it, and this is one way that the .NET GAC does (it specifies a list of directories in a registry key).

-- edit 1 --

Your problem seems quite a uncomfortable mix, it s like trying to eat with a straight jacket on :P. Why don t you drop the assembly requirement and have a function in a native DLL that returns a version identifier (name-version), and then have some application logic to determine if it may use the DLL.

For example file-name (fn) = monkey-1-1 and a function call returns a struct:

struct version-id
{
   const char * name;
   int major_number;
   int minor_number;
};

Then fn monkey-1-2 would not conflict on file-name or internal conversioning. and your programming conventions or application logic would make sure no adverse collisions occur.





相关问题
jQuery - ScrollTo and Serial Scroll not working together

I have tested the scrollTo() plugin, but I need a way to stop the scrolling animation, so I am looking at serialScroll(). Here is what I used with scrollTo: $( #scroller ).scrollTo( 1000px , 3000); ...

jQuery deconstructors for plugins?

I m using the Galleria plugin inside an Accordion plugin to display images in a super cool way. A problem occurs, however, when I open up a new tab (in the accordion) then come back to the gallery tab....

XPCOM Security issues

I m developing a Firefox plugin using XPCOM, I ve not yet read all the docs, but as far as I can see, A plugin is simply a DLL that provides services via a XPCOM interface and interacts with the ...

Ruby on Rails plugin development process

I m considering developing aspects of a website as Rails plugins for reuse. My question is about the development process. Since each of these plugins will provide a "slice" of functionality, should ...

help mongrel wont start

I have decided to switch from Restful authentication to authlogic.. so what I did was delete every file and folder that got installed when I downloaded the plugin.. now when I try to "ruby script/...

Basic MEF workflow/usage

I m looking to a framework which will allow me to have a simple plugin system in my .NET application. It seems MEF is the framework which Microsoft is endorsing, and will become part of .NET 4 (it ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

java plugin cache and dynamic IP host

I m trying to use Amazon S3 and Amazon Cloudfront CDN to deliver the jar files of my applet application. I m seeing several cache misses of my jars by the java plugin. This is a show-stopper for me, ...

热门标签