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
Solved

Finding a path

Posted on 2000-02-29
2
188 Views
Last Modified: 2010-04-02
Hi, when I run my app, I would like a CString variable to contain the path of the apps executable that is running. That is, c:\program files\test.exe where test.exe is the app that is running. The complication is that the app will be running in different paths depending on the PC that is running it. So the this CString variable must dynamically find its own path.
0
Comment
Question by:rose337
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 75 total points
ID: 2568571
Use GetModuleFileName()

continues.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2568593
To use this with CString I believe the following will work

CString Pth;
int Len = 64;

while (true)
{
   char *BufPtr = Pth.GetBuffer(Len);
   int RetVal = GetModuleFileName(NULL,BufPtr,Len)

   Pth.ReleaseBuffer(RetVal);
   if (RetVal != 0 && RetVal < Len) // If buffer was long enough, then
      break;
   Len += 64;
}
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

839 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