We help IT Professionals succeed at work.

m_pszProfileName and moving exe files

caulfield
caulfield asked
on
I made an NT executable that needs data from a .ini file.
I want to place the .ini file in the same folder of the executable and i want to move this folder. How can i set the m_pszProfileName variable to do this?
Is there a variable that gives me the path of the executable?
Comment
Watch Question

Commented:
To set the m_pszProfileName use somenthing like this.

AfxGetApp()->m_pszProfileName = "here comes the name of your .ini file".
 CWinApp::m_pszExeName contains the name of the exe file without extension. If u want the path just remove everithing after the last \ in this string.

Author

Commented:
m_pszExeName does not give the full path but only the name of the exe file.
Commented:
Here is the code to set the INI file path:
// First free the string allocated by MFC at CWinApp
// startup.
// The string is allocated before InitInstance is
// called and released in CWinApp destructor
   free((void*)m_pszProfileName);

// build the file name according to the application
// file name
   TCHAR szINIFile[_MAX_PATH];
   ::GetModuleFileName(NULL, szINIFile, _MAX_PATH);
   _tcsrchr(szINIFile, _T('.'))[0] = _T('\0');
   _tcscat(szINIFile, _T(".ini"));
   m_pszProfileName = _tcsdup(szINIFile);

CERTIFIED EXPERT

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by vbk_bgm
Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

khkremer
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.