?
Solved

Ini File

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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

762 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