Move manifest file to dll? - c++

I'm using a third party component in my application that is distributed either as a COM component, or can be referenced using a .manifest file. Either way it is loaded using CoCreateInstance(). The files needed for the third party component reside in a subfolder. The component developer told me to include a .manifest file in the Visual Studio 2010 settings (in the "Manifest" section) of the executable, and loading the component works without problems.
Now I'm using the third party component from a DLL only, to encapsulate the features used from the third party component. I'm loading the DLL dynamically, using LoadLibrary(). Using the component still works, I can use the component from within the DLL that is loaded by the EXE that has the manifest file referenced.
To further separate the EXE from the third pary component, I'd like to move the manifest to the DLL, too, where is the only place the component is used. In this way every new EXE I'd like to write can use the DLL and indirectly use the features. For now, I have to add the mainfest to every new EXE, but I don't want to do that.
Is there a way to move the manifest used by the EXE to a DLL?

You can put the manifest in the DLL, but it may not be activated automatically. You may need to do that manually using the activation context API. I think a lot depends on what the manifest is being used for. I suspect you are trying to use registration free COM, but that's only a guess.
Anyway, these links may well be useful to you:
RT_MANIFEST resource, and ISOLATION_AWARE_ENABLED (Junfeng Zhang)
Isolating Components (MSDN)

Related

C++ how to dynamically load a 3rd party DLL file

I need to integrate a 3rd party DLL file with my application, I have only the .DLL and the .pdf documentation of the DLL.
This is the pdf of the dll: http://www.whiteboxrobotics.com/Support/pdf/PC-BOT_dotNet_v1.0_documentation.pdf
I can load the DLL in Visual Studio just by dragging it into the toolbox, BUT, I would like to know how that is done in coding.
Since I only have the DLL, I guess the only option is dynamic loading, using the LoadLibrary() and GetProcAddress().
But it seems to be such a hassle, and I can't figure out how I would load any of the functions which receive some custom (enum) parameters, e.g. in the .pdf the function SendMessage(...) which takes PCBOTEventArgs.messageType as one of the parameters.
Yet loading the DLL through the design view is so simple and extracts the whole DLL.
Why is that?
Is there something else besides using function pointers and GetProcAddress()?
A dotNET = (Mircosoft) .NET Framework is not the same as a "normal" dll, you can't use GetProcAddress and LoadLibrary with .NET dlls
.Net Dlls are normally packed classes, by dragging the dll into your workspace you just import the dlls scope, see for your self in the object browser
to load a .net dll (Assembly) during runtime, for example for a plugin, look here http://support.microsoft.com/kb/837908
3rd Party integration is done using connectivity of what you want to connect for ex you want to add a service to your website, For installing that particular DLL to your website ,first of all read the documentation and connectivity required and than copy paste the DLL files to your projects.
You can make more clear when you can specify the services which want to opt as 3rd party integration

Can different versions of DLL be loaded in same application?

My application uses one version of library (a.dll), I am using another DLL(b.dll) which in-turn uses older version of the same library (a.dll) that i use. I am building the application by embedding a manifest file. The DLL i use is also using a embedded manifest file. I am having both the versions of the library in my WinSXS folder. My application is not able to load the appropriate versions of DLLs.
Will having a separate manifest file (not embedding into DLL) help resolving the problem? What is the work around?
Your situation is exactly the situation WinSxS is supposed to solve. It should be working.
Either: The manifest files are pointing to the same version, or one of the manifest files is not embedded properly, or
The shared assembly in WinSxS was installed with a configuration policy that automatically redirects requests for v1.0 to v1.1
Some clarifications are needed: App.exe and b.dll are implicitly linked against a.dll? Or do they load it via LoadLibrary.
If B.DLL loads A.DLL explicitly using LoadLibrary then you need to add ISOLATION_AWARE_ENABLED to your pre-processor definitions to ensure that LoadLibrary calls made by B.DLL look in the correct activation context. Otherwise they will be made in the context of the default activation context which was created by the EXE's manifest.
It will depend on what the duplicated DLLs do and if their versions are compatible. (e.g. Do they both access shared objects in memory? If so, there's a good chance something will blow up.)
It will also depend on how those two same-named DLLs are loaded. If it's anything other than an explicit LoadLibrary with a full path then things probably will not work. There's an ongoing discussion of this here: Determine the loaded path for DLLs
In general, it might work if you're lucky. The fact it may go catastrophically wrong is a good reason to avoid the issue entirely, if you can. (In the worst case, you could host one of the modules in another process and proxy all the calls to it. Ideally, just be able to use the same DLL version in both modules.)

COM Object DLL Load Issue

I am working on a Qt DLL that is used as a plugin for a large application. This DLL depends on other DLLs that are sadly not located in the same folder and hence will only load if the current working directory has been set correctly (which the large application does prior to calling LoadLibrary on the DLL). I have no control over this behaviour.
I have been asked to add a simple COM object to this plugin which I have done but I now have the problem that the DLL cannot be registered or used by a 3rd-party application unless the current working directory is set correctly - because any LoadLibrary calls on the plugin fail due to the missing dependencies. Obviously I have no control over the current working directory used by 3rd-party apps and at this stage I am not allowed to modify the PATH to ensure the dependencies can be found.
I have tried using /DELAYLOAD for the dependent DLLs but this fails with 'cannot delay-load foo.dll due to import of data symbol...' errors. Again, I cannot easily change the way these dependent DLLs are used.
Currently I think the only solution is to move the COM object into a stand-alone DLL that doesn't depend on anything else but I am under pressure to find a solution and leave the COM object in the plugin DLL. I can't see how this is possible so I thought I'd see if anyone else has any ideas. Some form of system-wide SetDllDirectory call would help or some registry hack that could set the working directory when a 3rd-party app calls LoadLibrary on my plugin.
IMO separating the COM object into a separate .dll is the cleanest solution - anyone would expect an in-proc COM server to be registered by using regsvr32 and that requires no fancy dependencies in that COM server.
I don't know if it's precisely a solution to your problem, but maybe this can help you: try to look at the possibilities offered by manifest files. I hope it will help.
You could use a runtime registration model.
The Dll could register itself as a COM server in its own initialisation code.
This only requires that loadlibrary is guaranteed to be called before the dll is used as a COM server.

Windows: Changing the DLL search order for an Exe

I have a C++ Exe in an application directory which contains the DLLs used by it. Now, for some testing purpose I need to modify an existing DLL and use that instead of the original one. But in order to not modify the existing installation I cannot backup the existing DLL and replace it with the modified one or move the existing one elsewhere. I also cannot change the Exe. The 2 DLLs need to exist side by side. The only change should be that the Exe should transparently load the modified DLL which is in some other folder rather than the existing DLL which is in the same folder as the Exe. Is there some elegant way of doing it?
I looked at some MSDN articles but could not find a way of doing this. The solution should work on Windows XP and up.
Windows will load at most one version of each DLL name per process. If it loads a DLL listed in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs, it won't load a similarly-named DLL later. But in AppInit_DLLs you can list a DLL with an explicit path, overriding the normal LoadLibrary() order.
Hence, temporarily put your test DLL in AppInit_DLLs and it will override any other DLL with the same name.
According to MSDN, it will always start by the application directory (unless you modify it with the alternate search order method...) so it seems to be difficult. You can still copy the executable and its other dependencies elsewhere. It is not that elegant though.
Or you can launch the executable that you have copied elsewhere along with the new DLL, from the original directory. According to the search order it should work too, though I must admit I have never tried.
You can hook LoadLibrary() calls for your process from the beginning. When your patched version of LoadLibrary() sees your DLL's it calls original LoadLibrary() with modified DLL's path.Even if you don't use LoadLibrary() call to load your DLLs, Windows CRT does. So this technique must work.
The only way I know would use LoadLibrary API including the path, but you say you can not change the exe.

Plugin DLLs that depend on other DLLs

I am writing a DLL to plug into another (3rd party) application. The DLL will need to depend on another set of DLLs (for license reasons I cannot link statically).
I would like my DLL to be "xcopy-deployable" to any directory. I would also like not to require adding this directory to the path.
If I just build the DLL the usual way, Windows will refuse to load the DLL, since it cannot find the DLLs next to the current process.
Are there any good options for helping Windows locate the DLL?
To answer some questions:
The DLL is written in C++.
The extra DLLs are QT-dlls.
I would like to place the extra DLLs in the same folder as my plugin DLL. I can get the name of that folder from GetModuleFileName.
The application is Firefox, the DLL is a PKCS#11 security module.
The application loads the DLL using the full path to the DLL (the user supplies it when installing the plugin).
Requiring that the DLLs be placed in System32 or next to the application would work, but it is a bit messy and could cause problems with uninstallers.
LoadLibrary and GetProcAddress would of course work, but is not really feasible in my case. I am using hundreds, if not thousands, of methods in the other DLLs. I really need to use the import-libraries.
I had thought about using delay-loaded dlls combined with SetDllDirectory in DllMain. Have anyone tried anything like this?
I can think of 3 ways.
put the dlls in the same folder as your application (you cannot do this?)
Use runtime linking. LoadLibrary() and GetProcAddress()
Use a manifest http://msdn.microsoft.com/en-us/library/aa374182(VS.85).aspx
But if the dll isn't in the same folder as the .exe, how are you going to know where it is? forget Windows not knowing, how do you know?
you can specify the path of dll as the parameter of LoadLibrary().
Another option is to modify the PATH variable. Have a batch file for launching the main app, and set the PATH=%PATH%;%~dp0. This ensures a minimal footprint, with no additional traces left in the system after running.