zoukankan      html  css  js  c++  java
  • 几个非常有用的函数-获取可执行文件所在的目录及读取配置文件

    // 取得Exe所在的目录(不包含最后的"\")
    CString GetExePath()
    {
    	char sFileName[256] = {0};
    	CString sPath = _T("");
    	
    	GetModuleFileName(AfxGetInstanceHandle(), sFileName, 255);
    	sPath.Format("%s", sFileName);
    	int pos = sPath.ReverseFind('\\');
    	if(pos != -1)
    		sPath = sPath.Left(pos);
    	else
    		sPath = _T("");
    	
    	return sPath;
    }
    
    void ReadKeyValue(LPCSTR lpSection, LPCSTR lpKey, LPCTSTR lpDefault, CString &sDest, LPCTSTR sConfigFile)	// 读取字符串
    {
    	char sValue[500] = {0};
    	GetPrivateProfileString(lpSection, lpKey, lpDefault, sValue, 499, sConfigFile);
    	sDest = sValue;
    }
    
    void ReadKeyValue(LPCSTR lpSection, LPCSTR lpKey, int nDefault, UINT &nDest, LPCTSTR sConfigFile)			// 读取整数
    {
    	nDest = GetPrivateProfileInt(lpSection, lpKey, nDefault, sConfigFile);
    }
    
    void ReadKeyValue(LPCSTR lpSection, LPCSTR lpKey, int nDefault, BOOL &nDest, LPCTSTR sConfigFile)			// 读取BOOL数据
    {
    	UINT nTemp;
    	nTemp = GetPrivateProfileInt(lpSection, lpKey, nDefault, sConfigFile);
    	nDest = nTemp != 0;
    }
    

    若有需要,再添加对这几个函数的声明:

    CString GetExePath();
    void ReadKeyValue(LPCSTR lpSection, LPCSTR lpKey, LPCTSTR lpDefault, CString &sDest, LPCTSTR sConfigFile);
    void ReadKeyValue(LPCSTR lpSection, LPCSTR lpKey, int nDefault, UINT &nDest, LPCTSTR sConfigFile);
    void ReadKeyValue(LPCSTR lpSection, LPCSTR lpKey, int nDefault, BOOL &nDest, LPCTSTR sConfigFile);
    
  • 相关阅读:
    Flutter -- iOS导航栏TabBar
    微信小程序布局
    Tomcat for Mac 搭建本地后台服务器 -- 探索Apache Tomcat
    masnory 动态高度
    iPhone 尺度 x xs sr xsmax
    Deepin 安装 tomcat
    Deepin 设置静态 ip
    md 文件 转 pdf
    mac 上关于截图的偏好设置
    MySQL笔记---DDL
  • 原文地址:https://www.cnblogs.com/joeblackzqq/p/1947301.html
Copyright © 2011-2022 走看看