博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
相对路径使用方法
阅读量:4687 次
发布时间:2019-06-09

本文共 2121 字,大约阅读时间需要 7 分钟。

c++

// 没有盘符,为相对路径
strDllPath.Trim(_T("\\"));
strDllPath = CEnvironment::ConfigAppDir()+strDllPath;

c#

String strDir = Environment.CommandLine.Substring(0, Environment.CommandLine.LastIndexOf(@"\XQ-4."));
或者
Environment.CurrentDirectory // 当操作中途有使用文件打开对话框的情况时,该函数可能会发生变化

 

《Environment.h》

#pragma once

class CEnvironment
{
public:
CEnvironment(void);
~CEnvironment(void);
static CString ConfigAppDir(void);
static int Init(void);
static CString m_AppPath;
static CString m_AppDriver;
static CString m_AppDir;
static CString m_AppFileName;
static CString m_AppFileExt;

static void OutputMsg01(CString tag , CString str , BOOL clean);

};

《Environment.cpp》

#include "StdAfx.h"

#include "Environment.h"

CString CEnvironment::m_AppPath = _T("");

CString CEnvironment::m_AppDriver = _T("");
CString CEnvironment::m_AppDir = _T("");
CString CEnvironment::m_AppFileName = _T("");
CString CEnvironment::m_AppFileExt = _T("");

CEnvironment::CEnvironment(void)

{
}

CEnvironment::~CEnvironment(void)
{
}

int CEnvironment::Init(void)
{
if (_T("")!=m_AppDriver)
return 0;

TCHAR path[MAX_PATH];

memset(path,0,sizeof(TCHAR)*MAX_PATH);
GetModuleFileName( NULL,path, MAX_PATH );
TCHAR drive[MAX_PATH],dir[MAX_PATH],fname[MAX_PATH],ext[MAX_PATH];
_tsplitpath(path,drive,dir,fname,ext );

m_AppDriver = drive;

m_AppDir = dir;
m_AppFileName = fname;
m_AppFileExt = ext;
//m_AppPath = drive;

return 1;

}

CString CEnvironment::ConfigAppDir(void)

{
Init();
return m_AppDriver+m_AppDir;
//m_AppPath = drive;
//m_AppPath += dir;
}

void CEnvironment::OutputMsg01(CString tag , CString str , BOOL clean)
{
CString strFilePath = _T("c:\\output111.txt");
CStdioFile file;
BOOL res = FALSE;
if (clean)
{
res = file.Open(strFilePath, CFile::modeCreate|CFile::modeReadWrite);
}
else
{
res = file.Open(strFilePath, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
}

if (res)

{
if (!clean)
{
file.SeekToEnd();
}

if (_T("")!=tag)

{
file.WriteString(tag);
file.WriteString(_T("\r\n"));
}

if (_T("")!=str)

{
file.WriteString(str);
file.WriteString(_T("\r\n"));
}

file.Close();

}
}

转载于:https://www.cnblogs.com/carl2380/archive/2012/01/09/2316916.html

你可能感兴趣的文章
[学习笔记]HTTP协议
查看>>
警告:Assigning to 'id<Delegate>' from incompatible type 'ViewController *const_st
查看>>
项目中字体比较粗,比较虚。
查看>>
杨延锟--ORACLE博客
查看>>
Web开发环境搭建 Eclipse-Java EE 篇
查看>>
python源码学习
查看>>
jdaaaaaavid --github
查看>>
xargs
查看>>
铁路微机监测分析与研究
查看>>
SpringBoot Tomcat启动报错
查看>>
css outline实践研究
查看>>
fackbook的Fresco的Image Pipeline以及自身的缓存机制
查看>>
Casablanca发布:一个用C++访问云的本地类库
查看>>
[转载]Python调用Shell 之间变量传递
查看>>
IOS开发网络篇—监测网络状态
查看>>
SQL数据库还原时备份集中的数据库备份与现有的数据库不同的解决办法
查看>>
Myeclipse、eclipse安装lombok
查看>>
springboot-全局异常处理类
查看>>
document.ready和window.onload 加载区别及可能会出现问题
查看>>
C# .Net 中字典Dictionary<TKey,TValue>泛型类 学习浅谈
查看>>