获得可执行程序EXE的绝对路径

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012911202/article/details/83416720

环境:win7_64bit + VS2012

获得当前可执行程序的绝对路径 

	char cExecPath[MAX_PATH];
	char* pszPathofFile;
    //GetModuleFileName获得当前可执行程序绝对路径\\xx\\xx\\xx.exe
	if(GetModuleFileName( 0,  cExecPath, sizeof(cExecPath)))
	{
        //strrchr查找字符在指定字符串中从左面开始的最后一次出现的位置,如果成功,返回该字符最后出现的位置,如果失败,则返回 NULL	
		pszPathofFile = strrchr(cExecPath, '\\'); /* remove the current EXE name from the path */
        //删除xx.exe,保留路径\\xx\\xx\\
		if(pszPathofFile)
		{		
			*(pszPathofFile + 1) = '\0';		
		} 
	} 

猜你喜欢

转载自blog.csdn.net/u012911202/article/details/83416720