11

The documentation for LoadLibraryEx() doesn't actually explain what the altered search path is. In the table entry for the LOAD_WITH_ALTERED_SEARCH_PATH flag it says "see the Remarks section", but in the Remarks section it only says that this flag causes LoadLibraryEx() to use the altered search path.

But it doesn't explain anywhere what the altered search path actually is.

sashoalm
  • 75,001
  • 122
  • 434
  • 781

2 Answers2

13

I finally found the explanation, but it was in a page linked to by the LoadLibraryEx() docs - Dynamic-Link Library Search Order.

Note that the standard search strategy and the alternate search strategy specified by LoadLibraryEx with LOAD_WITH_ALTERED_SEARCH_PATH differ in just one way: The standard search begins in the calling application's directory, and the alternate search begins in the directory of the executable module that LoadLibraryEx is loading.

So standard begins in the *.exe's directory, while the altered begins in the *.dll's directory.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
-3

But it doesn't explain anywhere what the altered search path actually is.

That is not the case. The documentation you linked to explains this in the remarks section:

Searching for DLLs and Dependencies

The search path is the set of directories that are searched for a DLL. The LoadLibraryEx function can search for a DLL using a standard search path or an altered search path, or it can use a process-specific search path established with the SetDefaultDllDirectories and AddDllDirectory functions. For a list of directories and the order in which they are searched, see Dynamic-Link Library Search Order.

Follow the link at the end of that paragraph for the details. You really do need to read all of the documentation, right the way to the bottom of the page.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Sorry, I didn't mean imply that. Just to explain - my way of scanning through documentation is to use "Ctrl+F" to search for a keyword, or use Google. Usually this works fine, but in this case it didn't, and I initially thought it was just missing. I'm sure there are many other people that read docs my way. I hope that my question (and answer) will help them. Ironically, your answer will help only people who are not like me, and who read with comprehension, instead of frantically searching for their keyword. – sashoalm Mar 04 '15 at 09:22
  • My advice is to change the way you read the documentation. ;-) Which was really the main message of my answer. I honestly don't think that we need a question on Stack Overflow for every single bit of documentation that people might not find. When a subject is well documented, as this one is, that's all that is needed. I think the bigger picture is how to read the documentation in general, rather than the specifics of this little part of the system. That's my opinion anyway. – David Heffernan Mar 04 '15 at 09:26
  • And, FWIW, if you had CTRL+F'ed your way through the original topic, searching for altered, you would have hit upon the relevant parts of the remarks section. – David Heffernan Mar 04 '15 at 09:34
  • I did actually, but initially the sentence "For a list of directories and the order in which they are searched, see Dynamic-Link Library Search Order." somehow made me think it's only about the standard search path, so I didn't click it. My mistake I guess. – sashoalm Mar 04 '15 at 09:37
  • Anyway I agree with you that it's not the best question, but since I've already already wasted my time (and yours, sorry for which) I'd rather not delete it. Who knows, maybe it'll help someone avoid my mistake. – sashoalm Mar 04 '15 at 09:55
  • 1
    Definitely helped me - I think this was a very relevant question, and I appreciate your asking it. The information was buried very, very deep in the docs, and it really should have been surfaced next to the LOAD_WITH_ALTERED_SEARCH_PATH definition. – Kevin Day Jul 20 '17 at 14:29
  • 3
    @DavidHeffernan it didn't answer his question and berated him for not reading a 5 page MSDN article that linked to another 5 page MSDN article - neither of which was well written or easy to navigate. He wound up posting the answer to his own question, and I'm darned glad he did b/c I had the exact same experience. – Kevin Day Jul 21 '17 at 18:00
  • @Kevin It did answer the question. The fact that neither you nor the asker appear to be good at reading is the real issue. You appear to view Stack Overflow as a service to get other people to read documentation for you. A curious sense of entitlement. Anyway, thanks for your opinions. – David Heffernan Jul 21 '17 at 18:03