Ini File

I would like to have one INI file for my application in the application root directory.

I´m doing the following in InitInstance()
//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszProfileName);//Change the name of the .INI file.
//The CWinApp destructor will free the memory.

But, MFC is putting my INI file in the windows directory.
How can i change this?
My thanks in advance.
Who is Participating?
NorbertConnect With a Mentor Commented:
To get the location of the running app you can use
CString AppPath;
AfxGetModuleShortFileName(AfxGetInstanceHandle(), AppPath);
so you get the complete path and name of your exe:
To write A function that returns the path of your exe you can use
CString CYourApp::GetIniPath()
    CString AppPath;
    AfxGetModuleShortFileName(AfxGetInstanceHandle(), AppPath);
    int StartOfFileName=AppPath.ReverseFind('\\');
    return AppPath.Mid(0, StartOfFileName);

try this
m_pszProfileName=_tcsdup(_T("<your path>\\ProgSMB050.ini"));
jmartins71Author Commented:
Obviously that will work but i don´t know in advance my path.
I must get it somehow.

My application my be installed in different places.
I forgot:
you have to include Afxpriv.h for
jmartins71Author Commented:
Thanks a lot.
It works just fine.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.