Get path to current module/EXE? Topic is solved
Get path to current module/EXE?
I can easily get the current working dir, but how can I get the path to the EXE that is running? I can remember Win32 functions for it, but can't see the wx equivalent... does it exist? (v2.8.10)
Hi JohnD,
http://docs.wxwidgets.org/2.8/wx_wxstandardpaths.html
try this:
Frank
http://docs.wxwidgets.org/2.8/wx_wxstandardpaths.html
try this:
Code: Select all
wxStandardPaths std;
wxString exePath = std.GetExecutablePath();
WinXp SP3, OS X10.5.5; CodeLite, Dialog::Blocks, wxWidgets 2.8.10
Re: Get path to current module/EXE?
On Windows you may have name.exe as a single binary file, but on the Mac the executable is in the app bundle, in "name.app/Contents/MacOS/name" - if you're doing something with the executable you need to make sure it will work on any platform. If you're trying to do something like move the .exe to a new location, make sure you get the .app bundle on the Mac for the analogous operation, and whatever is appropriate for Linux. If you need to actually access the executable, you need to use the file in *.app/Contents/MacOS/ and the appropriate file on Linux.JohnD wrote:I can easily get the current working dir, but how can I get the path to the EXE that is running? I can remember Win32 functions for it, but can't see the wx equivalent... does it exist? (v2.8.10)
Hope this helps a bit. Maybe if you explained what you need to do with the executable?
"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind."
- Alan Kay, inventor of Object Oriented Programming
- Alan Kay, inventor of Object Oriented Programming
I think Frank gave me the answer, but sure I can give more detail.
When the app is run, the working dir might not be the location where the EXE (or *nix equivalent) is located - for example in Windows if you double-click a file associated with an app, the working dir is set as the dir of the file. I want to be able to get the path of the running EXE to make sure I can load the data files.
And because I might have multiple versions of the app installed, I can't just look in the registry, I want to know exactly which EXE is running so I can obtain a path information from that.
When the app is run, the working dir might not be the location where the EXE (or *nix equivalent) is located - for example in Windows if you double-click a file associated with an app, the working dir is set as the dir of the file. I want to be able to get the path of the running EXE to make sure I can load the data files.
And because I might have multiple versions of the app installed, I can't just look in the registry, I want to know exactly which EXE is running so I can obtain a path information from that.
Good, then wxStandardPaths is really the way to go. It has methods to get data path, which you likely want to use over simply getting the executable pathJohnD wrote:I think Frank gave me the answer, but sure I can give more detail.
When the app is run, the working dir might not be the location where the EXE (or *nix equivalent) is located - for example in Windows if you double-click a file associated with an app, the working dir is set as the dir of the file. I want to be able to get the path of the running EXE to make sure I can load the data files.
And because I might have multiple versions of the app installed, I can't just look in the registry, I want to know exactly which EXE is running so I can obtain a path information from that.
"Keyboard not detected. Press F1 to continue"
-- Windows
-- Windows
You shouldn't allocate and instance of wxStandardPaths, usefrank_frl wrote:Hi JohnD,
http://docs.wxwidgets.org/2.8/wx_wxstandardpaths.html
try this:FrankCode: Select all
wxStandardPaths std; wxString exePath = std.GetExecutablePath();
Code: Select all
::wxStandardPaths::Get().GetExecutablePath();
Note that you don't allocate an instance of class wxStandardPaths, but retrieve the global standard paths object using wxStandardPaths::Get on which you call the desired methods.
Thanks
Allonii
Allonii