How might one cope with the ambiguous value produced by GetDllDirectory?
Posted
by Integer Poet
on Stack Overflow
See other posts from Stack Overflow
or by Integer Poet
Published on 2010-05-26T16:44:07Z
Indexed on
2010/05/26
18:01 UTC
Read the original article
Hit count: 240
win32
|setdlldirectory
GetDllDirectory
produces an ambiguous value. When the string this call produces is empty, it means one of the following:
- nobody has called
SetDllDirectory
- somebody passed
NULL
toSetDllDirectory
- somebody passed an empty string to
SetDllDirectory
The first two cases are equivalent for my purposes, but the third case is a problem. If I want to write save/restore code (call GetDllDirectory
to save the "old" value, SetDllDirectory
to set a "new" value temporarily, and later SetDllDirectory
again to restore the "old" value), I run the risk of reversing some other programmer's intent.
If the other programmer intended for the current working directory to be in the DLL search order (in other words, one of the first two bullets is true), and I pass an empty string to SetDllDirectory
, I will be taking the current working directory out of the DLL search order, reversing the other programmer's intent.
Can anyone suggest an approach to eliminate or work around this ambiguity?
P.S. I know having the current working directory in the DLL search order could be interpreted as a security hole. Nevertheless, it is the default behavior, and my code is not in a position to undo that; my code needs to be compatible with the expectations of all potential callers, many of which are large and old and beyond my control.
© Stack Overflow or respective owner