Link to home
Start Free TrialLog in
Avatar of zeurx
zeurxFlag for United States of America

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
ASKER CERTIFIED SOLUTION
Avatar of mnashadka
mnashadka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrbiggles
mrbiggles

Hi,

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
Avatar of zeurx

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@CProgramDeath2Dlg@@MAEHXZ)

then a ending error

please can you help... i included the files i needed.
thanks ;)

Program fatal error LNK1120: 2 unresolved externals
Avatar of zeurx

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@CProgramDeath2Dlg@@MAEHXZ)

then a ending error

please can you help... i included the files i needed.
thanks ;)

Program fatal error LNK1120: 2 unresolved externals
Avatar of jkr
The easiest way:

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.
Avatar of zeurx

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
>>#inculde "psapi.lib"

This should read

#pragma comment ( lib, "psapi.lib")
Avatar of zeurx

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
Avatar of zeurx

ASKER

just add #pragma comment ( lib, "psapi.lib")