Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Application path

Application path

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Prakash Nadar
    wrote on last edited by
    #1

    how do i get the path from where the application was executed ?? i am using MFC. Thanx. My God is more powerfull Than Your God. (the line that divides the world)

    R E 2 Replies Last reply
    0
    • P Prakash Nadar

      how do i get the path from where the application was executed ?? i am using MFC. Thanx. My God is more powerfull Than Your God. (the line that divides the world)

      R Offline
      R Offline
      RChin
      wrote on last edited by
      #2

      Use the GetModuleFileName() API.

      	CString strDirectoryPath;
      	TCHAR zName[MAX_PATH];
      	TCHAR* zLast;
      	
      	::GetModuleFileName(0,zName,sizeof(zName));
      	zLast=_tcsrchr( zName, (TCHAR)'\\');
      	if (zLast)
      		*(zLast+1) = (TCHAR)'\0';
      	
      	strDirectoryPath = zName;
      	
      	///////////////////////////
      	ASSERT( !strDirectoryPath.IsEmpty() );
      	///////////////////////////
      
      	return strDirectoryPath;
      

      I Dream of Absolute Zero

      P 1 Reply Last reply
      0
      • R RChin

        Use the GetModuleFileName() API.

        	CString strDirectoryPath;
        	TCHAR zName[MAX_PATH];
        	TCHAR* zLast;
        	
        	::GetModuleFileName(0,zName,sizeof(zName));
        	zLast=_tcsrchr( zName, (TCHAR)'\\');
        	if (zLast)
        		*(zLast+1) = (TCHAR)'\0';
        	
        	strDirectoryPath = zName;
        	
        	///////////////////////////
        	ASSERT( !strDirectoryPath.IsEmpty() );
        	///////////////////////////
        
        	return strDirectoryPath;
        

        I Dream of Absolute Zero

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        Thanx i guess this piece of code is little better. CString strAppPath; ::GetModuleFileName(NULL,strAppPath.GetBuffer(MAX_PATH),MAX_PATH); strAppPath.ReleaseBuffer(); strAppPath = strAppPath.Left(strAppPath.ReverseFind('\\')); AfxMessageBox(strAppPath); My God is more powerfull Than Your God. (the line that divides the world)

        1 Reply Last reply
        0
        • P Prakash Nadar

          how do i get the path from where the application was executed ?? i am using MFC. Thanx. My God is more powerfull Than Your God. (the line that divides the world)

          E Offline
          E Offline
          eugi
          wrote on last edited by
          #4

          you can also check the GetCurrentDirectory() in the Platform SDK out: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getcurrentdirectory.asp bye,eugi www.eugigames.tk

          P 1 Reply Last reply
          0
          • E eugi

            you can also check the GetCurrentDirectory() in the Platform SDK out: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getcurrentdirectory.asp bye,eugi www.eugigames.tk

            P Offline
            P Offline
            Prakash Nadar
            wrote on last edited by
            #5

            Current directory is not what i want, i wanted the location of the exe file. suppose the exe file is in c:\windows and if you execute the program from c:\temp then c:\temp is ur current directory and c:\windows is the source directory :-) My God is more powerfull Than Your God. (the line that divides the world)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups