473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1924
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: hokiegal99 | last post by:
I've written a small script (with much help from this list) that searches through a directory for files without a PC filename extension like .doc .xls and then adds them. The reason for writing the...
1
by: Matt | last post by:
In test() method: var path="C:\test\hello.txt"; //returns -1 for path.lastIndexOf("\\"). why?? var pos=path.lastIndexOf("\\"); //return -1 But in showFile() method: We are able to get the...
2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
2
by: Xam | last post by:
Hello everybody Do you know of a javascript routine that can warn if there are any pre-defined invalid chars in the filename of an INPUT file box before it is submitted with the submit button. ...
11
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a...
4
by: Jon Rea | last post by:
Hi, Just a quickie ... I thought that Directory.GetCurrentGirectory(), unless the current directory had been changed by the program, would always point to the directory where the .exe for the...
2
by: Csharper95 | last post by:
I want to get the file name and path from a SaveFileDialog (for a 'save as' operation) after the user has saved the information under a new file name (and presumably under a new path) ? I want...
10
by: Brian Gruber | last post by:
Hi, I'm looking for a way to rename a whole directory of files in short order. The files in the directory have different lengths, however all of them end with _xxxx the x's represent a randomly...
1
by: The Mad Ape | last post by:
Hello I have a FileSave Dialog and am trying to pass the current folder name to a string. Is there any way to do that? It was easy to get the file path and name using .FileName but I see nothing...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.