Solved

Finding a path

Posted on 2000-02-29
2
202 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
[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 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

724 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