1.使用APi函数GetModuleFileName

char path[MAX_PATH];

GetModuleFileName(NULL, path, MAX_PATH);        //获取到完整路径如:E:\Tools\qq.exe

*strrchr(path,'\\') = '\0';                                                      //截取路径E:\Tools

2.MFC

char path[MAX_PATH];

memcpy(path, AfxGetApp()->m_pszHelpFilePath, MAX_PATH)       //获取到完整路径如:E:\Tools\qq.hlp

*strrchr(path,'\\') = '\0';                                                                              //截取路径E:\Tools

3 用这个函数也可以做到截取路径

PathRemoveFileSpec(LPTSTR pszPath)

例:

LPTSTR GetProgramDir(int nBufferLength, LPTSTR lpBuffer)

{

    DWORD dwReturn = 0;

LPTSTR tszSlash;

if (nBufferLength <= 0 || lpBuffer == NULL)

        return NULL;

dwReturn = ::GetModuleFileName(NULL, lpBuffer, nBufferLength);

if (dwReturn <= nBufferLength)

    {

    PathRemoveFileSpec(lpBuffer); 

    tszSlash = lpBuffer;

    }

return tszSlash;

}

2..

string GetPPath()                 //取程序运行的当前路径

{

TCHAR exeFullPath[MAX_PATH]; // MAX_PATH

GetModuleFileName(NULL,exeFullPath,MAX_PATH);//得到程序模块名称,全路径

char drive[_MAX_DRIVE];

char dir[_MAX_DIR];

_splitpath(exeFullPath, drive, dir, NULL,NULL);

string PragramPath(drive);

string TempPath(dir);

PragramPath += TempPath ;

cout<< PragramPath<<endl;

return PragramPath;

}

3.unicode 工程

TCHAR AppPath[256] = {0};

char g_strAppPath[256] = {0};



 ::GetModuleFileName(NULL,AppPath, MAX_PATH);

WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)AppPath, -1, g_strAppPath, 256, 0, 0);

*strrchr(g_strAppPath,'\\') = '\0';

VC 获 取 当前程序运行路径的几种方法的更多相关文章

  1. VC获取当前程序运行路径

    /***************************************************/ /* 函数: 获取当前程序运行的路径 /* 返回: 当前程序运行路径 C:\AAA\BBB\ ...

  2. golang获取程序运行路径

    golang获取程序运行路径: /* 获取程序运行路径 */ func getCurrentDirectory() string { dir, err := filepath.Abs(filepath ...

  3. [C#]中获取当前程序运行路径的方法

    获取当前程序运行路径: ①//获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集.string str = System.AppDomain.CurrentDoma ...

  4. 【转】 C#获取当前程序运行路径的方法集合

    [转] C#获取当前程序运行路径的方法集合 //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Assembly.Location; resul ...

  5. .NET 实现启动时重定向程序运行路径及 Windows 服务运行模式部署

    日常工作中有时候会遇到需要将程序直接在服务器上运行,而不依赖于 IIS 托管的情况,直接运行有两种方式,一种是部署为 服务模式,另一种则是 直接启动 .NET 发布之后的 exe 文件以 控制台模式运 ...

  6. iOS 获取文件的目录路径的几种方法 [转]

    iOS 获取文件的目录路径的几种方法 2 years ago davidzhang iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. d ...

  7. mac学习Python第一天:安装、软件说明、运行python的三种方法

    一.Python安装 从Python官网下载Python 3.x的安装程序,下载后双击运行并安装即可: Python有两个版本,一个是2.x版,一个是3.x版,这两个版本是不兼容的. MAC 系统一般 ...

  8. 【转】c# Image获得图片路径的三种方法 winform

    代码如下:c# pictureBox1.Image的获得图片路径的三种方法 winform 1.绝对路径:this.pictureBox2.Image=Image.FromFile("D:\ ...

  9. c# pictureBox1.Image的获得图片路径的三种方法 winform

    代码如下:c# pictureBox1.Image的获得图片路径的三种方法 winform 1.绝对路径:this.pictureBox2.Image=Image.FromFile("D:\ ...

随机推荐

  1. 【linux】压缩和解压缩

    .gz格式 压缩gzip: gzip只能压缩文件,且压缩后文件消失,不能压缩目录. [root@andon tmp]# ls ml orbit-gdm pulse-2sLvu7UbjUYf pulse ...

  2. SPOJ #453. Sums in a Triangle (tutorial)

    It is a small fun problem to solve. Since only a max sum is required (no need to print path), we can ...

  3. Redis在Windows环境下搭建

    1.  下载Redis-Windows版本 Redis官网下载页面: http://redis.io/download Windows下Redis项目: https://github.com/MSOp ...

  4. zend studio 12汉化和破解

    首先提供一个 zend studio 12汉化的百度连接地址(我的网盘里有) http://pan.baidu.com/s/1dD5x1cd 下载后解压 安装方法 Help–> Install  ...

  5. (C/C++ interview) Static 详解

    C Static http://stackoverflow.com/questions/572547/what-does-static-mean-in-a-c-program Static could ...

  6. windows server 2012将计算机、回收站、文档等图标添加到桌面

    rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0

  7. 图片--Android加载图片导致内存溢出(Out of Memory异常)

    Android在加载大背景图或者大量图片时,经常导致内存溢出(Out of Memory  Error),本文根据我处理这些问题的经历及其它开发者的经验,整理解决方案如下(部分代码及文字出处无法考证) ...

  8. dos查看端口

    C:\Documents and Settings\Administrator>netstat -an | findstr "22"  TCP    192.168.16.2 ...

  9. js跳转页面方法整理

    1.window.location.href方式 window.location.href="http://www.zgw8.com"; 2.window.navigate方式跳转 ...

  10. header('Content-type:text/html;charset = utf-8');出现中文乱码

    header('Content-type:text/html;charset = utf-8'); "="两旁不能留空格,必须紧密连写,否则出现乱码;