[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Ini File

Posted on 1998-09-30
5
Medium Priority
?
397 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
  • 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

831 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