zeurx
asked on
Find Filename
Ok im new to some of the advanced parts of mfc and was wondering how to/if posible to find the file name of my program
etc. the program was named test.exe by default and i changed it to "my program.exe" and i copy the file to a backup so nothing can go wrong
is there any way to get the filename so i can copy the right file and not a fixed file name ;)
thanks to anyone that helps
etc. the program was named test.exe by default and i changed it to "my program.exe" and i copy the file to a backup so nothing can go wrong
is there any way to get the filename so i can copy the right file and not a fixed file name ;)
thanks to anyone that helps
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mnashadka this helps alot but i get to linking errors:
Program error LNK2019: unresolved external symbol _GetModuleBaseNameA@16 referenced in function "protected: virtual int __thiscall CProgramDlg::OnInitDialog( void)" (?OnInitDialog@CProgramDlg @@MAEHXZ)
and
Program error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "protected: virtual int __thiscall CProgramDlg::OnInitDialog( void)" (?OnInitDialog@CProgramDea th2Dlg@@MA EHXZ)
then a ending error
please can you help... i included the files i needed.
thanks ;)
Program fatal error LNK1120: 2 unresolved externals
Program error LNK2019: unresolved external symbol _GetModuleBaseNameA@16 referenced in function "protected: virtual int __thiscall CProgramDlg::OnInitDialog(
and
Program error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "protected: virtual int __thiscall CProgramDlg::OnInitDialog(
then a ending error
please can you help... i included the files i needed.
thanks ;)
Program fatal error LNK1120: 2 unresolved externals
ASKER
mnashadka this helps alot but i get to linking errors:
Program error LNK2019: unresolved external symbol _GetModuleBaseNameA@16 referenced in function "protected: virtual int __thiscall CProgramDlg::OnInitDialog( void)" (?OnInitDialog@CProgramDlg @@MAEHXZ)
and
Program error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "protected: virtual int __thiscall CProgramDlg::OnInitDialog( void)" (?OnInitDialog@CProgramDea th2Dlg@@MA EHXZ)
then a ending error
please can you help... i included the files i needed.
thanks ;)
Program fatal error LNK1120: 2 unresolved externals
Program error LNK2019: unresolved external symbol _GetModuleBaseNameA@16 referenced in function "protected: virtual int __thiscall CProgramDlg::OnInitDialog(
and
Program error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "protected: virtual int __thiscall CProgramDlg::OnInitDialog(
then a ending error
please can you help... i included the files i needed.
thanks ;)
Program fatal error LNK1120: 2 unresolved externals
The easiest way:
char acModuleName [ MAX_PATH];
GetModuleFileName ( NULL, acModuleName, sizeof ( acModuleName));
char acModuleName [ MAX_PATH];
GetModuleFileName ( NULL, acModuleName, sizeof ( acModuleName));
To use my way, you also need to link with psapi.lib. jkr's is a little easier, but it returns the whole path and you have to parse past the '\'. Good luck.
ASKER
how do i add psapi.lib to my source...
i tried #inculde <psapi.lib>
and #inculde "psapi.lib"
now working... says it cant find the file
i tried #inculde <psapi.lib>
and #inculde "psapi.lib"
now working... says it cant find the file
>>#inculde "psapi.lib"
This should read
#pragma comment ( lib, "psapi.lib")
This should read
#pragma comment ( lib, "psapi.lib")
ASKER
how do i add psapi.lib to my source...
i tried #inculde <psapi.lib>
and #inculde "psapi.lib"
now working... says it cant find the file
i tried #inculde <psapi.lib>
and #inculde "psapi.lib"
now working... says it cant find the file
ASKER
just add #pragma comment ( lib, "psapi.lib")
An easy way to get your app's name is to use the MFC global function:
AfxGetAppName( );
This will give you the internal name of your app, and will not change even if the executable is manually renamed. In your case you would always get "test" without the .exe extension.
If you wanted to get "my program" (again without .exe) you can do this:
AfxGetApp( )->m_pszExeName;
Hope this helps.
-TS