Solved

Ini File

Posted on 1998-09-30
5
383 Views
Last Modified: 2013-11-20
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.
m_pszProfileName=_tcsdup(_T("ProgSMB050.ini"));


But, MFC is putting my INI file in the windows directory.
How can i change this?
My thanks in advance.
0
Comment
Question by:jmartins71
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:cyrilbdt
ID: 1322727
try this
m_pszProfileName=_tcsdup(_T("<your path>\\ProgSMB050.ini"));
0
 

Author Comment

by:jmartins71
ID: 1322728
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.
0
 
LVL 3

Accepted Solution

by:
Norbert earned 50 total points
ID: 1322729
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:
<YourDrive:\><YourPath\><YourApp>.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);
}

0
 
LVL 3

Expert Comment

by:Norbert
ID: 1322730
I forgot:
you have to include Afxpriv.h for
AfxGetModuleShortFileName
0
 

Author Comment

by:jmartins71
ID: 1322731
Thanks a lot.
It works just fine.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question