zoukankan      html  css  js  c++  java
  • [手游项目5]windows获得当前进程名

    #include <windows.h>
    #include <stdio.h>
    #include <string>
    
    using namespace std;
    
    void SplitString2Int(const string& src, string delimit, vector<string>& vecRet)
    {
    	string null_subst = "0";
    	if (src.empty() || src == "" || delimit.empty() || delimit == "")
    		return;
    
    	int deli_len = delimit.size();
    	int nIndex = 0;
    	int last_search_position = 0;
    	while ((nIndex = src.find(delimit, last_search_position)) != -1)
    	{
    		if (nIndex == last_search_position)
    		{
    			string nValue = null_subst.c_str();
    			vecRet.push_back(nValue);
    		}
    		else
    		{
    			string nValue = src.substr(last_search_position, nIndex - last_search_position).c_str();
    			vecRet.push_back(nValue);
    		}
    		last_search_position = nIndex + deli_len;
    	}
    
    	string last_one = src.substr(last_search_position);
    	if (last_one.empty())
    	{
    		string nValue = (null_subst.c_str());
    		vecRet.push_back(nValue);
    	}
    	else
    	{
    		string nValue = (last_one.c_str());
    		vecRet.push_back(nValue);
    	}
    }
    
    std::string TCHAR2STRING(TCHAR *STR)
    {
    	int iLen = WideCharToMultiByte(CP_ACP, 0, STR, -1, NULL, 0, NULL, NULL);
    	char* chRtn = new char[iLen * sizeof(char)];
    	WideCharToMultiByte(CP_ACP, 0, STR, -1, chRtn, iLen, NULL, NULL);
    	std::string str(chRtn);
    	delete chRtn;
    	return str;
    }
    
    void main()
    {
    	TCHAR szPath[MAX_PATH];
    	GetModuleFileName(NULL, szPath, MAX_PATH);
    	vector<string> FileName;
    	string strPath = TCHAR2STRING(szPath);
    	SplitString2Int(strPath,"\", FileName);
    	string strFileName = FileName[FileName.size() - 1];
    }
  • 相关阅读:
    python
    springboot-mybatis-pagehelper(分页插件)
    图片验证码工具类
    http工具类
    page工具类
    生成count位随机数工具类
    日期工具类
    dozer工具类
    list自定义排序工具类
    fastJson工具类
  • 原文地址:https://www.cnblogs.com/byfei/p/14104093.html
Copyright © 2011-2022 走看看