I have a native VC++ project that uses a dll (which is not in a project). Now, I must to put the dll in one the "Search Path Used by Windows to Locate a DLL" link
but I don't want the dll to sit in the exectuable or current or windows or system directory.
So my only option according to that is adding the path to the %PATH% environment variable.
Is there any other way?
Is there an elegant way to do so (adding to PATH)? should I do this on installation? should I be concerned if i'm doing this?
Summing up all the techniques I have found:
string temp = "myFullDirectoryPathToDll"; string temp2 =Environment.GetEnvironmentVariable("PATH") + ";" + temp; Environment.SetEnvironmentVariable("PATH", temp2);
this, and I think MSDN should have stressed that, changes the environment variable PATH only in this process.
when debugging in VS the appPath doesn't 'work' use properties->debug->environment and merge environment variables link
Here are a few suggestions:
You could embed the dll as a resource in your main executable and then extract it to a temporary directory and load it from their using LoadLibrary and then get the relevant function addresses using GetProcAddress.
You could modify you main processes search path using SetDllDirectory() to include the location of the DLL. This avoids having to make any global changes to the system. And again use LoadLibrary/GetProcAddress to resolve the function addresses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With