Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Path to Application's Directory

Status
Not open for further replies.

GameDude

Programmer
Jun 22, 2004
23
US
Is there an API call that will return the path to the directory the application is located at?

MSDN says GetCurrentDirectory should work, but when I tried using the example code for it, my compiler spit back errors at me saying the "#using <mscorlib.dll>" was an undefined preprocessor directive.

Here's the site where I found that function


let me know how to fix this, or if there's another way...
 
What language are you using?
That helpfile was for .net code (C#, managed C++, Visual Basic .net, etc)

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Apparently there were two sites for the same function. One for .net code, and one for normal C++ WinAPI code. I saw "C++" and thought it was the one I wanted. Then I found the other site with the code I REALLY wanted. Temporarily confusing...but I worked it all out.
 
This may be a little late, but nevertheless...

char work[MAX_PATH+1];

GetModuleFileNameEx(GetCurrentProcess(),
NULL,
work,
sizeof(work));



Another option in C/C++:


#include <stdlib.h>

char caProg[MAX_PATH+1];
strcpy(caProg, _pgmptr);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top