Using SetDllDirectory()

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am looking for a way to tell my application where to look for the necessary DLLs. I have already searched the forums and found many posts which described making changes to environment variables and the registry, which are not an option for me (target machines will not have rights to make these changes). I also tried the "delay loaded DLLs" option, which did not seem to work for me.<br/> <br/> Then I found some posts suggesting the use of the "SetDllDirectory" function for the same purpose, and someone who reported getting it to work using this syntax:<br/> <br/>
<pre lang="x-c# SetDllDirectory(L"../dlls/");[/code]
<br/> <br/> However, when building my application and copying it to the test machine with the exectuable in one dir (lets call it "C:app") and the DLLs in a subdirectory named "C:appdlls", I get an error from my application saying that it cannot find the necessary DLLs. Of course, if I copy the DLLs into the same directory as the executable, the application runs just fine.<br/> <br/> My question is: How do I use SetDllDirectory properly? <br/> <br/> I have already seen the MSDN knowledge base article on it ( http://msdn.microsoft.com/en-us/library/ms686203.aspx http://msdn.microsoft.com/en-us/library/ms686203.aspx ), and this doesnt really help. Some of the key points of confusion are: The syntax (how to format the path string properly -- why is there an L in the example I found?) and where this function call should be in my code for it to work properly (I currently have it as the first line in my main function). <br/> <br/> Also, if there is a better way of doing this (or, alternatively, if anyone can tell me how to embed these DLLs into my executable instead, that would be even better), please let me know.<br/> <br/> Any help is greatly appreciated!

View the full article
 
Back
Top