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 11 1909
"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
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
"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!
"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
"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!
"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
"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. :)
"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
"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?
"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
"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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |