首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 常用代码共享 [已结帖,结帖人:zyx040404]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zyx040404
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    • 结帖率:
    发表于:2008-11-17 21:08:12 楼主
    以下代码是我多年工作中总结的常用代码,其中部分代码是其他人写的代码
    我将常用代码写成一个DLL,使用DOT.NET 2003,如果要使用该DLL,就必须要修改项目的C++的默认属性为/MDd或/MD,否则会有内存异常
    请参考http://msdn.microsoft.com/en-us/library/ms235460(VS.80).aspx, 里面有讲具体原因
    当然如果你喜欢可以直接使用原代码, 有些代码写的不一定很好,仅仅当做参考一下

    这些常用代码包括:日志,注册表管理,正则表达式,XML操作,文件扫描,资源文件使用,MD5加密,字符串操作,时间操作,文件操作,OS操作,串口操作等
    存储的文件目录结构是:
    CommFunctions
    ----COMM
    ----MD5
    ----UtilLog
    ----UtilRegistry
    ----UtilRegularString
    ----UtilResource
    ----UtilScanFile
    ----UtilXML
    ----CommonDataDefine.h
    ----Util.cpp
    ----Util.h

    另外也可以参考我发的另外几个关于经验分享的帖子

    经验分享,如何写DLL
    http://topic.csdn.net/u/20080822/00/17bbae38-9936-42b6-ac76-806911e7830a.html

    经验分享,如何写线程
    http://topic.csdn.net/u/20080906/01/1e9aa0c3-6167-4abb-a2b3-91083716edfd.html

    经验分享,如何使用try,catch, throw之一
    http://topic.csdn.net/u/20080823/19/75373f80-7709-44b3-856f-31651910b6e6.html

    经验分享,如何使用try,catch, throw之二
    http://topic.csdn.net/u/20080824/12/abeadfe6-cc1b-4f6d-ab04-93b82a5eab54.html

    经验分享,如何设计代码架构
    http://topic.csdn.net/u/20080830/00/2be80d62-5340-4f6f-a067-368a6215972e.html
    0  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zyx040404
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-17 21:13:481楼 得分:0
    先是CommonDataDefine.h文件,在很多地方都要用到
    C/C++ code
    ////////////////////////////////////////////////////////////////////////////////////////////////// // // Title: common data define // Compiler: Microsoft Visual Studio .NET 2003 // Creation Date: 2007/08/12 // Description: define the common data // // Authors: Jacky Zhou, zyx040404@163.com // ////////////////////////////////////////////////////////////////////////////////////////////////// #pragma once #include <TCHAR.H> #include <shlwapi.h> #include <assert.h> #include <string> #include <vector> #include <list> #include <map> #include <sstream> #include <algorithm> using namespace std; //****************************************************************************************************** // common data define //****************************************************************************************************** #ifdef _UNICODE typedef wstring TSTRING; typedef wstringstream STRINGSTREAM; typedef wifstream IFSTREAM; typedef wofstream OFSTREAM; #else typedef string TSTRING; typedef stringstream STRINGSTREAM; typedef ifstream IFSTREAM; typedef ofstream OFSTREAM; #endif typedef vector<TSTRING> VECSTRING; typedef VECSTRING::iterator VECSTRING_IT; typedef VECSTRING::const_iterator VECSTRING_CONST_IT; #define NPOS -1
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zyx040404
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-17 21:34:262楼 得分:0
    这是Util.h头文件
    C/C++ code
    ////////////////////////////////////////////////////////////////////////////////////////////////// // // Title: Util // Compiler: Microsoft Visual Studio .NET 2003 // Creation Date: 2007/08/12 // Description: XML parser // // Authors: Jacky Zhou, zyx040404@163.com // ////////////////////////////////////////////////////////////////////////////////////////////////// #pragma once #ifdef UTIL_EXPORTS #define UTIL_API __declspec(dllexport) #else #define UTIL_API __declspec(dllimport) #endif #include <WINDOWS.H> #include <NTSECAPI.H> #include "CommonDataDefine.h" //----------------------------------------------------------------------------------------------------- // classes //----------------------------------------------------------------------------------------------------- UTIL_API void * CreateILogger(); UTIL_API void * CreateIRegistryKnob(); UTIL_API void * CreateIStringMatchService(); UTIL_API void * CreateIXMLParser(); UTIL_API void * CreateIScanFile(); UTIL_API void * CreateIResource(); UTIL_API void * CreateIDBGW(); UTIL_API void * CreateIMD5(); //----------------------------------------------------------------------------------------------------- // string functions //----------------------------------------------------------------------------------------------------- UTIL_API int CompareStringWithoutCase(const TSTRING & s1, const TSTRING & s2); UTIL_API size_t FindStringWithoutCase(const TSTRING & s1, const TSTRING & s2); UTIL_API TSTRING stoupper(const TSTRING & s); UTIL_API TSTRING stolower(const TSTRING & s); UTIL_API TSTRING srtrim(TSTRING & s); UTIL_API TSTRING sltrim(TSTRING & s); UTIL_API TSTRING strim(TSTRING & s); UTIL_API void GetRidOfDoubleQuotationMarks(TSTRING & s); UTIL_API char * Wstring2Char(const wstring wstr, char* tch); UTIL_API TSTRING Bstr2String(const BSTR bstr, TSTRING & sString); UTIL_API BSTR String2Bstr(const TSTRING & sString, BSTR bstr); UTIL_API TSTRING Int2String(const int iValue); UTIL_API TSTRING Int2String(const int iValue, TSTRING & sString); UTIL_API void Replace(TSTRING & sSource, const TSTRING & sOld, const TSTRING & sNew); UTIL_API TSTRING GetPathFromEnviroment(const TSTRING & sEnvNameWithPercent); UTIL_API TSTRING ReplaceEnvToRealValue(const TSTRING &sTempLine); UTIL_API int GetStringBytesCount(const unsigned char *str); UTIL_API int GetStringCharCount(const unsigned char *str); UTIL_API void InitLsaString(PLSA_UNICODE_STRING LsaString, LPWSTR String); UTIL_API void CommaSeperatedStrToStrVector(TSTRING& cms, VECSTRING& strvector); //----------------------------------------------------------------------------------------------------- // time functions //----------------------------------------------------------------------------------------------------- UTIL_API TSTRING GetTime(); UTIL_API TSTRING GetIntervalTime(const TSTRING& sBeginTime, const TSTRING& sEndTime); //----------------------------------------------------------------------------------------------------- // file functions //----------------------------------------------------------------------------------------------------- UTIL_API BOOL CreateDir(const TSTRING & sPath); UTIL_API BOOL CreateFileByPath(const TSTRING & sFile); UTIL_API BOOL IsFileExist(const TSTRING & sFile); UTIL_API BOOL IsFileValid(const TSTRING & sFile); UTIL_API BOOL IsPathValid(const TSTRING & sPath); UTIL_API BOOL CreatePathByFullFileName(const TSTRING & sFile); UTIL_API void EmptyDir(const TSTRING & sPath); UTIL_API void DeleteFiles(const TSTRING & sPath); UTIL_API void AddBackslashToPathIfNotPresent(TSTRING & sPath); UTIL_API __int64 GetDiskKSizeUsed(const TSTRING & sDrive); UTIL_API __int64 GetFileSize(const TSTRING & sFullFileName); UTIL_API __int64 GetFolderSize(const TSTRING & sFolder); UTIL_API BOOL MoveFile(LPCTSTR src, LPCTSTR dst, BOOL dwflags); UTIL_API BOOL CopyDir(const TCHAR* srcDir, const TCHAR* dstDir); UTIL_API int RunExeFile(const TSTRING & sCommandLine, BOOL bWait = FALSE, DWORD dwFlags = 0); UTIL_API TSTRING GetRunPath(); UTIL_API TSTRING GetLongPathNameFromShortName(const TSTRING & sShortFileName); UTIL_API BOOL IsEmptyFolder(const TCHAR* dir); UTIL_API DWORD GetOrignalPathName(LPTSTR pszCurrentPathName, LPTSTR pszOrignalPathName, DWORD cbBuffer); UTIL_API size_t GetNewFileIndex(const TSTRING & sFileName, const TCHAR tchFlag = _T('(')); //----------------------------------------------------------------------------------------------------- // OS functions //----------------------------------------------------------------------------------------------------- enum OS_RESTART_TYPE { UNKNOW_RESTART_TYPE = 0, SHUTDOWN_AND_REBOOT = 1, RESTART_DIALOG = 2 }; UTIL_API void RestartWindows(const OS_RESTART_TYPE & restartType); UTIL_API void SystemShutDownAndReboot(); UTIL_API void PreventSystemHibernation(); UTIL_API void CriticalDelay(LONG delayTime); UTIL_API void SimpleBeginThread(unsigned ( __stdcall *start_address )( void * ), void * arglist = NULL); UTIL_API string GetCPUVenderID(); UTIL_API string GetCPUSerial(); //----------------------------------------------------------------------------------------------------- // Resource functions //----------------------------------------------------------------------------------------------------- UTIL_API int GetResString(int uStrID, TSTRING& tsText, LPRECT lpRc = NULL); UTIL_API int GetResControl(int eView, int uCtrlID, TSTRING& tsText, LPRECT lpRc = NULL); UTIL_API int GetResControl(int eView, int uCtrlID, LPRECT lpRc); UTIL_API int LoadNLS(const TSTRING& tsResFile); UTIL_API int GetMsgString(int uStrID, TSTRING& tsText); UTIL_API int GetResFont(int uFontID, LPLOGFONT lpFt, int eView = -1);

    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • wuming0404
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-17 21:48:013楼 得分:0
    up
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zyx040404
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-17 21:48:594楼 得分:0
    Util.cpp比较长,慢慢写
    C/C++ code
    ////////////////////////////////////////////////////////////////////////////////////////////////// // // Title: Util // Compiler: Microsoft Visual Studio .NET 2003 // Creation Date: 2007/08/12 // Description: XML parser // // Authors: Jacky Zhou, zyx040404@163.com // ////////////////////////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include <algorithm> #include <Shlobj.h> #include <ShObjIdl.h> #include <PROCESS.H> #include "Util.h" #include "UtilLog/ILogger.h" #include "UtilLog/LoggerImpl.h" #include "UtilRegularString/IStringMatchService.h" #include "UtilRegularString/StringMatchServiceImpl.h" #include "UtilRegistry/IRegistryKnob.h" #include "UtilRegistry/RegistryKnobImpl.h" #include "UtilXML/IXMLParser.h" #include "UtilXML/XMLParserImpl.h" #include "UtilScanFile/IScanFile.h" #include "UtilScanFile/ScanFileImpl.h" #include "UtilResource/ResourceImpl.h" #include "dbgw/IDBGW.h" #include "dbgw/DBGWImpl.h" #include "MD5/md5.h" using namespace std; static CResourceImpl l_Resource; #define MAX_PATH_IN_BYTES (MAX_PATH * 2) //------------------------------------------------------------------------------------------------------ // FileSizeK //------------------------------------------------------------------------------------------------------ __int64 FileSizeK(DWORD high, DWORD low) { __int64 k = 0; if (high != 0) { k = high; k <<= 22; // shift left 32 since high order, then right 10 to divide by 1024 } k += (low / 1024); return k; } //------------------------------------------------------------------------------------------------------ // GetFileSize //------------------------------------------------------------------------------------------------------ __int64 GetFileSize(const TSTRING & sFullFileName, WIN32_FIND_DATA & win32FindData) { __int64 i64FileSize = 0; if (win32FindData.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) { __int64 i64ActualSize = 0; DWORD dwActualSizeLow = 0; DWORD dwActualSizeHigh = 0; dwActualSizeLow = GetCompressedFileSize(sFullFileName.c_str(), &dwActualSizeHigh); if (dwActualSizeHigh > 0) { i64ActualSize = dwActualSizeHigh; i64ActualSize <<= 32; } i64ActualSize += dwActualSizeLow; i64FileSize = (i64ActualSize / 1024); } else i64FileSize = max(FileSizeK(win32FindData.nFileSizeHigh, win32FindData.nFileSizeLow), 1); return i64FileSize; } BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • wuyu637
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-17 21:49:355楼 得分:0
    mark
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zyx040404
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-17 21:50:276楼 得分:0
    C/C++ code
    //****************************************************************************************************** // structs definition //****************************************************************************************************** enum SCAN_FILE_ERROR { HF_error, HF_continue, HF_done }; //****************************************************************************************************** // classes //****************************************************************************************************** //------------------------------------------------------------------------------------------------------ // CreateILogger //------------------------------------------------------------------------------------------------------ UTIL_API void * CreateILogger() { CLoggerImpl * pRK = new CLoggerImpl(); return static_cast<void *> (pRK); } //------------------------------------------------------------------------------------------------------ // CreateIRegistryKnob //------------------------------------------------------------------------------------------------------ UTIL_API void * CreateIRegistryKnob() { CRegistryKnobImpl* pRK = new CRegistryKnobImpl(); return static_cast<void *> (pRK); } //------------------------------------------------------------------------------------------------------ // CreateIStringMatchService //------------------------------------------------------------------------------------------------------ UTIL_API void * CreateIStringMatchService() { CStringMatchServiceImpl* pSMS = new CStringMatchServiceImpl(); return static_cast<void *> (pSMS); } //------------------------------------------------------------------------------------------------------ // CreateIXMLParser //------------------------------------------------------------------------------------------------------ UTIL_API void * CreateIXMLParser() { CXMLParser* pXMLParser = new CXMLParser(); return static_cast<void *> (pXMLParser); } //------------------------------------------------------------------------------------------------------ // CreateIScanFile //------------------------------------------------------------------------------------------------------ UTIL_API void * CreateIScanFile() { CScanFileImpl* pScanFile = new CScanFileImpl(); return static_cast<void *> (pScanFile); } //------------------------------------------------------------------------------------------------------ // CreateIResource //------------------------------------------------------------------------------------------------------ UTIL_API void * CreateIResource() { CResourceImpl* pResource = new CResourceImpl(); return static_cast<void *> (pResource); } //------------------------------------------------------------------------------------------------------ // CreateIDBGW //------------------------------------------------------------------------------------------------------ UTIL_API void * CreateIDBGW() { CDBGWImpl* pDBGW = new CDBGWImpl(); return static_cast<void *> (pDBGW); } //------------------------------------------------------------------------------------------------------ // CreateIMD5 //------------------------------------------------------------------------------------------------------ UTIL_API void * CreateIMD5() { CMD5* pMD5 = new CMD5(); return static_cast<void *> (pMD5); }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zyx040404
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-17 21:51:597楼 得分:0
    这是字符串的函数
    C/C++ code
    //****************************************************************************************************** // string functions //****************************************************************************************************** //------------------------------------------------------------------------------------------------------ // CompareStringWithoutCase //------------------------------------------------------------------------------------------------------ UTIL_API int CompareStringWithoutCase(const TSTRING & s1, const TSTRING & s2) { return _tcsicmp (s1.c_str(), s2.c_str()); } //------------------------------------------------------------------------------------------------------ // FindStringWithoutCase //------------------------------------------------------------------------------------------------------ UTIL_API size_t FindStringWithoutCase(const TSTRING & s1, const TSTRING & s2) { TSTRING sLower1 = stolower(s1); TSTRING sLower2 = stolower(s2); return sLower1.find(sLower2); } //------------------------------------------------------------------------------------------------------ // stoupper //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING stoupper(const TSTRING & s) { TSTRING upper(s); for(size_t i=0; i<s.length(); i++) upper[i] = _totupper(upper[i]); return upper; } //------------------------------------------------------------------------------------------------------ // stolower //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING stolower(const TSTRING & s) { TSTRING lower(s); for(size_t i=0; i<s.length(); i++) lower[i] = _totlower(lower[i]); return lower; } //------------------------------------------------------------------------------------------------------ // srtrim //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING srtrim(TSTRING & s) { s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(::isspace))).base(), s.end()); return s; } //------------------------------------------------------------------------------------------------------ // sltrim //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING sltrim(TSTRING & s) { s.erase(s.begin(),std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(::isspace)))); return s; } //------------------------------------------------------------------------------------------------------ // strim //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING strim(TSTRING & s) { return sltrim(srtrim(s)); } //------------------------------------------------------------------------------------------------------ // GetRidOfDoubleQuotationMarks //------------------------------------------------------------------------------------------------------ UTIL_API void GetRidOfDoubleQuotationMarks(TSTRING & s) { if (s.find(_T("\"")) == 0) s = s.substr(1); if (s.find(_T("\"")) == s.length() - 1) s = s.substr(0, s.length() - 1); } //------------------------------------------------------------------------------------------------------ // Wstring2Char //------------------------------------------------------------------------------------------------------ UTIL_API char * Wstring2Char(const wstring wstr, char* tch) { UINT codepage = GetACP(); int n = 0; n = WideCharToMultiByte(codepage, 0, wstr.c_str(), -1, tch, MAX_PATH_IN_BYTES, NULL,NULL); tch[n] = '\0'; return tch; } //------------------------------------------------------------------------------------------------------ // Bstr2String //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING Bstr2String(const BSTR bstr, TSTRING & sString) { TCHAR *tch = NULL; try { size_t iLen = _tcslen(bstr) + 1; tch = new TCHAR[iLen]; if (NULL != tch) { memset(tch, 0,iLen); #ifdef UNICODE _tcscpy(tch, bstr); #else UINT codepage = GetACP(); int n = WideCharToMultiByte(codepage, 0, bstr, -1, tch, MAX_PATH_IN_BYTES, NULL,NULL); tch[n] = '\0'; #endif sString = tch; delete tch; } } catch(...) { if (tch) delete tch; } return sString; } //------------------------------------------------------------------------------------------------------ // String2Bstr //------------------------------------------------------------------------------------------------------ UTIL_API BSTR String2Bstr(const TSTRING & sString, BSTR bstr) { #ifdef UNICODE _tcscpy(bstr, sString.c_str()); #else UINT codepage = GetACP(); int n = 0; n = MultiByteToWideChar(codepage, 0, sString.c_str(), -1, bstr, MAX_PATH_IN_BYTES); bstr[n] = '\0'; #endif return bstr; } //------------------------------------------------------------------------------------------------------ // Int2String //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING Int2String(const int iValue) { TSTRING sString; return Int2String(iValue, sString);; } //------------------------------------------------------------------------------------------------------ // Int2String //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING Int2String(const int iValue, TSTRING & sString) { TCHAR tchValue[20000] = {0}; _itot(iValue, tchValue, 10); sString = tchValue; return sString; } //------------------------------------------------------------------------------------------------------ // Replace //------------------------------------------------------------------------------------------------------ UTIL_API void Replace(TSTRING & sSource, const TSTRING & sOld, const TSTRING & sNew) { //basic_string.find will return 0 if the string is "" if (sOld.empty()) return; TSTRING sLine = sSource; TSTRING sResult; size_t iPos = NPOS; while (TRUE) { iPos = FindStringWithoutCase(sLine, sOld); if (iPos == NPOS) { //get suffix file description sResult += sLine; break; } //get pre file description sResult = sResult + sLine.substr(0, iPos) + sNew; sLine = sLine.substr(iPos + sOld.length()); } sSource = sResult; }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zyx040404
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-17 21:53:118楼 得分:0
    这还是字符串函数
    C/C++ code
    //------------------------------------------------------------------------------------------------------ // GetPathFromEnviroment //------------------------------------------------------------------------------------------------------ #define ID_WINENV_SYSTEMROOT_DIRECTORIES _T("%systemroot directory%") #define ID_WINENV_WINDOWS_DIRECTORIES _T("%windows directory%") UTIL_API TSTRING GetPathFromEnviroment(const TSTRING & sEnvNameWithPercent) { //check whether sEnvNameWithPercent includes "%" at begin and end position if (sEnvNameWithPercent[0] != _T('%') && sEnvNameWithPercent[sEnvNameWithPercent.size() - 1] != '%') return _T(""); TSTRING sPath; if (CompareStringWithoutCase(sEnvNameWithPercent, ID_WINENV_SYSTEMROOT_DIRECTORIES) == 0) { TCHAR tchSystemDirectory[MAX_PATH + 1] = {0}; GetSystemDirectory(tchSystemDirectory, MAX_PATH); sPath = tchSystemDirectory; } else if (CompareStringWithoutCase(sEnvNameWithPercent, ID_WINENV_WINDOWS_DIRECTORIES) == 0) { TCHAR tchWindowsDirectory[MAX_PATH + 1] = {0}; GetWindowsDirectory(tchWindowsDirectory, MAX_PATH); sPath = tchWindowsDirectory; } else { TCHAR tchPath[MAX_PATH + 1] = {0}; //ExpandEnvironmentStrings gets the windows env, GetEnvironmentVariable gets the user define env ExpandEnvironmentStrings(sEnvNameWithPercent.c_str(), tchPath, MAX_PATH); if (0 == CompareStringWithoutCase(sEnvNameWithPercent, tchPath)) { memset(tchPath, 0, sizeof(tchPath)); TSTRING sEnvName = sEnvNameWithPercent; sEnvName = sEnvName.substr(1, sEnvName.size() - 2); GetEnvironmentVariable(sEnvName.c_str(), tchPath, MAX_PATH); } sPath = tchPath; } //remove the last "\" of tchPath if (sPath[sPath.length() - 1] == _T('\\')) sPath = sPath.substr(0, sPath.length() - 1); return sPath; } //------------------------------------------------------------------------------------------------------ // ReplaceEnvToRealValue //------------------------------------------------------------------------------------------------------ UTIL_API TSTRING ReplaceEnvToRealValue(const TSTRING &sTempLine) { TSTRING sLine = sTempLine; TSTRING sNewLine; size_t iPos = NPOS; while (TRUE) { iPos = sLine.find(_T("%")); if (iPos == NPOS) { //get suffix file description sNewLine += sLine; break; } //get pre file description sNewLine += sLine.substr(0, iPos); sLine = sLine.substr(iPos + 1); iPos = sLine.find(_T("%")); if (iPos == NPOS) return _T(""); //get tchPath from env TSTRING sEnv = sLine.substr(0, iPos); sEnv = _T("%") + sEnv + _T("%"