Link to home
Start Free TrialLog in
Avatar of rose337
rose337

asked on

Finding a path

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.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

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;
}