title: LoadLibrary with Absolute Path returns Incorrect HMODULE with No Error
body: <p>I have some code which is trying to load a Dll. </p>
  
  <p>I have encountered an odd 'error' with this. When trying to load the dll from an absolute path, I get a Non-Null HMODULE that gives no windows error codes on a GetLastError call (i.e. GetLastError returns '0' or success according to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx" rel="nofollow">msdn</a>). When calling into a function in this dll, I get incorrect values.</p>
  
  <p>This behavior is peculiar, because if, instead, I switch the current directory to be that of my current dll using SetCurrentDirectory and use a relative path call to LoadLibrary, I get correct values.</p>
  
  <p>Here is a snippet describing the situation:</p>
  
  <p>Using absolute path:</p>
  
  <pre><code>std::string libLoc = get_dll_location(); // Get the directory of this dll
  HMODULE myDLL = LoadLibraryA(libLoc.c_str()); // Non-null value
  DWORD lastError = GetLastError(); // returns 0
  
  MyObj * value = UseDLL(myDLL); // bad value
  </code></pre>
  
  <p>Using relative path:</p>
  
  <pre><code>SetCurrentDirectory("c:\\path\\containing\\dll\\"); // hard coded path to dll's folder
  HMODULE myDLL = LoadLibrary("myDll.dll");  // Non-null value
  MyObj * value = UseDLL(myDLL);  // Good value
  </code></pre>
  
  <p>I'd really like to avoid having to use SetCurrentDirectory, because the application using this Dll may be multi-threaded and require that the directory stays the same. </p>
  
  <p>Any insight on this issue would be much appreciated. Hopefully, this is just a minor bug on my part.</p>
  
  <p><strong>Update</strong>: Using <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179%28v=vs.85%29.aspx" rel="nofollow">LoadLibraryEx</a> seems to be out of the question, as the LOAD_LIBRARY_SEARCH_* flags don't appear to be available to me (I've already tried installing the <a href="http://support.microsoft.com/kb/2533623" rel="nofollow">KB2533623 update</a>).</p>