Solved

Ini File

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

937 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

5 Experts available now in Live!

Get 1:1 Help Now