Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get Application Directory. Example please

319 views
Skip to first unread message

Michelle Stone

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to Visual C++ (MFC), Visual C++ (language)
My program saves a listbox to a file. Currently I have hardcoded it to store
it to the root directory "C:\\CodList.Dat". I want it to be saved to my
program directory "C:\\MyProg\\CodList.Dat". But this "MyProg" directory may
be any directory in any drive or sub-directory.

Reading responses to a similar post I learned GetModuleFileNameEx () is a
good start. But MSDN doesn't have any examples and I am baffled. Being a
beginner I can't quite understand what HMODULE and the such are; again
reading the definitions in MSDN can't convince me I understood.

Please give me an example, or just a one line example of
GetModuleFileNameEx().

If possible also tell me how to extract just the Directory Name (full path
to directory) by crossing out the filename.

For your reference, I am copying the syntax of GetModuleNameEx() from MSDN,
which I just can't understand...


====

GetModuleFileNameEx
-------------------
The GetModuleFileNameEx function retrieves the fully qualified path for the
specified module.

DWORD GetModuleFileNameEx(
HANDLE hProcess, // handle to the process
HMODULE hModule, // handle to the module
LPTSTR lpFilename, // buffer that receives the path
DWORD nSize // size of the buffer
);

Parameters
==========
hProcess:
---------
Handle to the process that contains the module.

hModule:
--------
Handle to the module.

lpFilename:
-----------
Pointer to the buffer that receives the fully qualified path to the module.

nSize:
------
Specifies the size, in bytes, of the lpFilename buffer.
Return Value
If the function succeeds, the return value specifies the length of the
string copied to the buffer.

======

Thank you...

-Michelle Stone


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Alan Mukamal

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to Michelle Stone
Michelle,
Just struggled through the same thing. Try the following:

char szPath[MAX_PATH];
GetModuleFileName(NULL, szPath, sizeof(szPath));
// returns full path and exe name.

// now get just the path:
strMY_APP_FOLDER = _T(szPath);
CString strMY_APP_FOLDER =
strMY_APP_FOLDER.Left(strMY_APP_FOLDER.ReverseFind('\\') + 1);
// include the backslash in the path

-- Alan
--------------------
Michelle Stone wrote:

--
---------------------------------------------------
Alan Mukamal
amuk...@ix.netcom.com
---------------------------------------------------

Felix Brack

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to
Also have a look at the api function GetModuleHandle(...). I leave the rest
up
to your imagination...

Hope this helps !

--
Felix Brack
LTEC AG
Dorfgasse 10
CH-4435 Niederdorf
SWITZERLAND
Internet: http://www.ltec.ch

Tel. +41 61 963 14 14
Fax. +41 61 963 14 13
E-Mail: f...@ltec.ch
Michelle Stone <mich_...@yahoo.com> wrote in message
news:LPBBKCMNDFHABFONJFL...@yahoo.com...

Fernando de Almeida Peres

unread,
Sep 20, 1999, 3:00:00 AM9/20/99
to
If your intention is just to write the file in the directory where do you
have your application executable, try to call the Open function like this:

CFile myFile;
...
myFile.Open("CodList.Dat",CFile::modeCreate|CFile::shareDenyNone|CFile::mode
Write);

For me, it work writing the file in the exact directory where I have my
executable...

Fernando de Almeida Peres


Michelle Stone wrote in message ...

0 new messages