470,810 Members | 864 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Current Filename and File path

Hi all,

Probably a really simple answer to this, but so far I'm having trouble
locating the answer. I'm writing an unmanaged VC++ app and I need to grab
the currently executing filename and file path from inside the application.
So if I am in the directory C:\Program Files\Test_Dir and I run TestApp
(.exe file), I need to grab the current directory ("C:\Program
Files\Test_Dir") and the application's full filename ("TestApp.exe"). Any
ideas are appreciated.

Thanks
Jun 7 '06 #1
11 1825
"Mike C#" <xy*@xyz.com> wrote in message
news:ur**************@TK2MSFTNGP04.phx.gbl...
I'm writing an unmanaged VC++ app and I need to grab the currently
executing filename and file path from inside the application.


Check the docs for GetModuleFileName(0, ...);

Regards,
Will

Jun 7 '06 #2
Thanks, I'll look into it. I was afraid I would have to do something funky
with the process id for a minute :) Thanks

"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message
news:ui**************@TK2MSFTNGP03.phx.gbl...
"Mike C#" <xy*@xyz.com> wrote in message
news:ur**************@TK2MSFTNGP04.phx.gbl...
I'm writing an unmanaged VC++ app and I need to grab the currently
executing filename and file path from inside the application.


Check the docs for GetModuleFileName(0, ...);

Regards,
Will

Jun 8 '06 #3
"Mike C#" <xx*@yyy.com> wrote in message news:0z**************@fe12.lga...
Check the docs for GetModuleFileName(0, ...);

Regards,
Will


Thanks Will, it works great!

By the way, is there a method for grabbing resources (i.e., version number,
copyright, etc.) from within the current process? Currently I'm having to
open the file again (hence the GetModuleFileName call) to read the
resources. It seems like there should be a way to grab the resources from
memory, since the file is already loaded and executing. Thanks again!
Jun 8 '06 #4
"Mike C#" <xy*@xyz.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Thanks Will,
You are welcome.
it works great!
I try hard not to give bogus information. :-)
By the way, is there a method for grabbing resources (i.e., version
number, copyright, etc.) from within the current process? Currently I'm
having to open the file again (hence the GetModuleFileName call) to read
the resources.


How are you opening it? If it is with GetFileVersionInfo() then I think that
that is the canonical way.

Regards,
Will
Jun 8 '06 #5

"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message
news:u$*************@TK2MSFTNGP05.phx.gbl...
Thanks Will,


You are welcome.
it works great!


I try hard not to give bogus information. :-)
By the way, is there a method for grabbing resources (i.e., version
number, copyright, etc.) from within the current process? Currently I'm
having to open the file again (hence the GetModuleFileName call) to read
the resources.


How are you opening it? If it is with GetFileVersionInfo() then I think
that that is the canonical way.


Yeah I'm using GetFileVersionInfo(), but it just seems odd that I have to
grab the file by pathname to get the resource information of itself! :) I
thought there might be a method out there to grab the resources from memory
without all the hocus-pocus, but hey this method works!

Thanks again!
Jun 8 '06 #6
"Mike C#" <xy*@xyz.com> wrote in message
news:ur**************@TK2MSFTNGP03.phx.gbl...
Yeah I'm using GetFileVersionInfo(), but it just seems odd that I have to
grab the file by pathname to get the resource information of itself! :)


Well, it is a resource so there just may be, but being the lazy &^%$# that I
am, I have never researched an alternative. :-)

Seriously, with the application running, at least sone of its image file
must be loaded in memory. I am happy to let the cache manager sort it out.

Are you building a resource editor or something?

Regards,
Will
Jun 8 '06 #7
"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message
news:ul**************@TK2MSFTNGP04.phx.gbl...
Well, it is a resource so there just may be, but being the lazy &^%$# that
I am, I have never researched an alternative. :-)

Seriously, with the application running, at least sone of its image file
must be loaded in memory. I am happy to let the cache manager sort it out.

Are you building a resource editor or something?


Nah, nothing that fancy :) I'm re-writing some applications here at work,
and I don't like the fact that all the "metadata" is hard-coded into the
apps. The previous designer hard-coded app name, version, etc. using
#define style constants. Some of the app names and versions changed, but
the hard-coded info wasn't updated along the way in many cases -- so I
figured I'd use resources to add some flexibility and as a better method of
keeping all this metadata in sync, since I'm rewriting these things from
scratch anyway. :)
Jun 8 '06 #8
"Mike C#" <xy*@xyz.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
so I figured I'd use resources to add some flexibility and as a better
method of keeping all this metadata in sync, since I'm rewriting these
things from scratch anyway. :)


I see. As I said, I've always used GetFileVersionInfo...() functions.

But I just tried this quick and awful hack

HRSRC hrsrc = FindResource(hInst, VS_VERSION_INFO, VERSIONINFO);
HGLOBAL hglbl = LoadResource(hInst, hrsrc);
LPVOID pv = LockResource(hglbl);

UINT u;
LPCSTR p;
VerQueryValue(pv, "\\StringFileInfo\\040904B0\\FileDescription", (LPVOID
*)&p, &u);

and it seems to do the right thing.

Regards,
Will
Jun 8 '06 #9
"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message
news:uw**************@TK2MSFTNGP04.phx.gbl...
"Mike C#" <xy*@xyz.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
so I figured I'd use resources to add some flexibility and as a better
method of keeping all this metadata in sync, since I'm rewriting these
things from scratch anyway. :)


I see. As I said, I've always used GetFileVersionInfo...() functions.

But I just tried this quick and awful hack

HRSRC hrsrc = FindResource(hInst, VS_VERSION_INFO, VERSIONINFO);
HGLOBAL hglbl = LoadResource(hInst, hrsrc);
LPVOID pv = LockResource(hglbl);

UINT u;
LPCSTR p;
VerQueryValue(pv, "\\StringFileInfo\\040904B0\\FileDescription",
(LPVOID *)&p, &u);


Thanks William! I ran your sample, and ran into a problem or two. Finally
got it to work but I think you're right - reading the resources from the
file is probably my best bet right now :) Now I'm running into another
problem with a possible memory leak... will the fun never end?
Jun 13 '06 #10
"Mike C#" <xy*@xyz.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Thanks William!
You are welcome.
I ran your sample, and ran into a problem or two.
It was an awful hack. I did work here. Just by the way, the IDE assigns an
ID of 1 (VS_VERSION_INFO) to the resource. I'm not sure if that is a
convention or a requirement.
Now I'm running into another problem with a possible memory leak... will
the fun never end?


:-)

Regards,
Will
Jun 13 '06 #11
"William DePalo [MVP VC++]" <wi***********@mvps.org> wrote in message
news:et****************@TK2MSFTNGP05.phx.gbl...
I ran your sample, and ran into a problem or two.


It was an awful hack. I did work here. Just by the way, the IDE assigns an
ID of 1 (VS_VERSION_INFO) to the resource. I'm not sure if that is a
convention or a requirement.


Yeah to get it to work here I had to use a string identifier "#1". It did
work, but I have more confidence in your original suggestion :) Thanks!
Jun 14 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by hokiegal99 | last post: by
2 posts views Thread by Rob Cowie | last post: by
4 posts views Thread by Jon Rea | last post: by
10 posts views Thread by Brian Gruber | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.