1

I have created a subst drive like the following:

G:\ => F:\projects\projectname\

When I call GetModuleFileNameW

GetModuleFileNameW(GetModuleHandleW(nullptr), buffer2, MAX_PATH);

It returns the Module path using the original path, Ex:

F:\projects\projectname\projectname.exe

Despite me running the solution and project from the subst drive location.

However, if I make a call to GetCurrentDirectoryW

GetCurrentDirectoryW(MAX_PATH, buffer3);

It ends up returning the correct path, Ex:

G:\projectname.exe

How can I get GetModuleFileNameW to return the subst path rather than the original path?

CodingMadeEasy
  • 2,257
  • 4
  • 19
  • 31
  • this depended from which name for used in `CreateProcess` call - in your case `F:\projects\projectname\projectname.exe` form used. "How can I get .. " - impossible. – RbMm Dec 16 '16 at 18:01
  • 1
    Reflects the very different layers in which these features are implemented. SUBST and GetCurrentDirectory() are sub-system features, added to get MS-Dos compatibility. A process goes all the way down the native OS. Which doesn't know beans about SUBST so cannot know a remapping was in effect. Nothing you can do about it. – Hans Passant Dec 16 '16 at 18:09
  • SUBST simply create symbolic link. so all depended from how we run exe. if by name `G:\projectname.exe` - we and got this name in `GetModuleFileNameW`, if by name `F:\projects\projectname\projectname.exe` - got this form. current directory independed from this. guess was call `CreateProcess("F:\projects\projectname\projectname.exe", ..., "G:\");` – RbMm Dec 16 '16 at 18:14
  • @HansPassant Thanks for the answers but if what you say is true then I should never get a subst path from GetModuleFileNameW correct? But when I start my application from a different project, it returns the correct subst path. – CodingMadeEasy Dec 16 '16 at 18:18
  • @CodingMadeEasy - how you start projectname.exe ? GetModuleFileNameW return exactly path which used in createprocess – RbMm Dec 16 '16 at 18:23
  • 1
    @RbMm Oh I see. I misunderstood you. I thought you were saying that GetModuleFileNameW can never return a subst drive but it can as long as CreateProcess called the process from that drive. Makes sense now. Thanks! – CodingMadeEasy Dec 16 '16 at 18:32
  • 1
    @CodingMadeEasy - yes, GetModuleFileName return exactly path form which used in module load (exe start) – RbMm Dec 16 '16 at 18:36

0 Answers0