---
title: "有用的vc获取当前目录的代码"
author: "feihen"
date: "2011-03-11T16:02:48Z"
tags: []
categories: ["编程语言"]
slug: "vc"
draft: false
lastmod: "2011-03-11T16:02:48Z"
id: 954088
url: "https://feihen.iteye.com/blog/954088"
---

//获取当前目录  
CString GetModuleDir()  
{  
    CString sPath;  
    GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX\_PATH+1),MAX\_PATH);  
    sPath.ReleaseBuffer();  
    int nPos=0;  
    nPos=sPath.ReverseFind('\\\\');  
    sPath=sPath.Left (nPos);  
    CString file;  
    file.Format("当前路径：%s",sPath);  
    AfxMessageBox(file);  
    return file;    
}