unixman83
unixman83

Reputation: 9933

Does LoadLibrary parse environment variables such as %windir%

If I do LoadLibrary("%windir%\\system32\\ole32.dll") does that mean Windows will ONLY load from "c:\windows\system32\ole32.dll" ? Also does LoadLibrary() in C understand the environment variable?

Upvotes: 5

Views: 2202

Answers (2)

Adrien Plisson
Adrien Plisson

Reputation: 23303

as Serge said and carefully tested, LoadLibrary does not do environment variable substitution in path.

however, there is a function in the windows API to replace environment variables in strings: ExpandEnvironmentStrings(). you can perform the required substitution on your path before calling LoadLibrary().

Upvotes: 6

Serge Wautier
Serge Wautier

Reputation: 21878

The docs for LoadLibrary clearly state that:

If the string specifies a full path, the function searches only that path for the module.

That said, they don't mention support for environment variables substitution. I seriously doubt they do support environment variables substitution: That's a shell feature, not a kernel API one.

BTW, that means LoadLibrary() would consider %windir%\blah.dll as a relative path since it doesn't start with a drive letter or a UNC path. Hence it would look through the whole series of directories, looking for a subdir named %windir%, which it's not likely to find!

I gave it a quick test: It confirms my opinion. Error = 126 : The specified module could not be found.

Upvotes: 4

Related Questions