// TODO: 在此添加额外的初始化代码
CString SetupPath;
GetExePath(SetupPath); //获取程序当前路径
CString config_userconfig=SetupPath+_T("users\\userconfig.cfg");
//函数名称:GetPath
//说 明: 获取程序的路径
//入 参:
//出 参: strPath目录路径
//说 明:
void CTestDlg::GetExePath(CString& strPath)
{
TCHAR szFull[_MAX_PATH];
TCHAR szDrive[_MAX_DRIVE];
TCHAR szDir[_MAX_DIR];
::GetModuleFileName(NULL, szFull, sizeof(szFull)/sizeof(TCHAR));
_tsplitpath(szFull, szDrive, szDir, NULL, NULL);
_tcscpy(szFull, szDrive);
_tcscat(szFull, szDir);
strPath = CString(szFull);
}
//
DLL:Demo.dll
/
CString strFilePath;
TCHAR tzPath[MAX_PATH+sizeof(TCHAR)] = {0};
GetModuleFileName(::GetModuleHandle(_T("Demo")), tzPath, MAX_PATH);
lstrcpy( _tcsrchr(tzPath, _T('\\'))+ 1, _T("file.xml"));
strFilePath = tzPath;
- #include<stdio.h>
- #include<Windows.h>
- #include "tchar.h"
- char *THCAR2char(TCHAR* tchStr)
- {
- int iLen = 2*wcslen(tchStr);//CString,TCHAR汉字算一个字符,因此不用普通计算长度
- char* chRtn = new char[iLen+1];
- wcstombs(chRtn,tchStr,iLen+1);//转换成功返回为非负值
- return chRtn;
- }
- int main()
- {
- TCHAR szFilePath[MAX_PATH];
- DWORD szRet = ::GetModuleFileName(NULL, szFilePath, MAX_PATH);
- char *pFilePath=THCAR2char(szFilePath);
- if(szRet)
- {
- printf("FilePath=%s\n",pFilePath);
- }else{
- printf("Failed\n");
- }
- return 0;
- }
TCHAR szFilePath[MAX_PATH];
DWORD szRet = ::GetModuleFileName(NULL, szFilePath, MAX_PATH);
CString cstrFilePath = szFilePath;
int nPos = cstrFilePath.ReverseFind('\\');
cstrFilePath = cstrFilePath.Left(nPos);
cstrFilePath += "\\XXXXX";