• Advertisement

Archived

This topic is now archived and is closed to further replies.

How to get name of exe?

This topic is 5154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
oops, sorry, im running a Windows Project, should have said that...

Share this post


Link to post
Share on other sites
Console app: should be argv[0].

Windows app: GetModuleFileName() with the argument as the handle received from GetModuleHandle() with a null argument.

Share this post


Link to post
Share on other sites
GetProcessName, or the 0th parameter given to your main...


T2k

Share this post


Link to post
Share on other sites
quote:
Original post by msn12b
Or GetModuleNameFile(NULL, ...).

...

edit: fixed function call after looking it up.



Fix it again. You got the Name and File part of the function call switched. (Besides which, using NULL as the argument to GetModuleFileName() may not return the exe''s name.)

Share this post


Link to post
Share on other sites
Even in a Windows application, you''ll still have access to argc & argv.

I don''t have MSDN with me right now, so not sure if they''re documented well, but lookup:

__argc
__argv

Supposidly I hear these don''t work with MFC, but I wouldn''t be sure as to why not.

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
using NULL as the argument to GetModuleFileName() may not return the exe's name.

According to MSDN,

GetModuleFileName(NULL, ...)

and

GetModuleFileName(GetModuleHandle(NULL), ...)

sound quite identical:

Under GetModuleHandle:
lpModuleName
If this parameter is NULL, GetModuleHandle
returns a handle to the file used to create
the calling process (.exe file).

Under GetModuleFileName:
hModule
Handle to the module whose path is being
requested. If this parameter is NULL,
GetModuleFileName retrieves the path of
the executable file of the current process.

So GetModuleFileName(NULL) sounds like it should work just fine.

[edited by - Agony on January 14, 2004 3:15:54 PM]

Share this post


Link to post
Share on other sites
That''s interesting. The text in the copy of MSDN on my computer is subtly different:
quote:

hModule
[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.

Share this post


Link to post
Share on other sites
I was gonna use my local copy of MSDN to check it as well, but I figured I better play it safe and check their online version. It''s not hard to imagine that the documentation that came with VC++ 6 could be different. Heck, they have DirectX 5 documentation in there.

Share this post


Link to post
Share on other sites

  • Advertisement