Solved

Ini File

Posted on 1998-09-30
5
369 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 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now