windows 路径 常用函数使用 UTF8-ascii ascii-UTF8 串转换

	char buffer[MAX_PATH];
	GetModuleFileNameA( NULL, buffer, MAX_PATH );
	PathRemoveFileSpecA(buffer);

	// c: d: 和后边路径合并
	char cfg_path[MAX_PATH];
	PathCombineA(cfg_path, buffer, "config.cfg");

	char* s = PathFindExtensionA(cfg_path);
	fmt::print("{}\n", s);
	char* s2 = PathFindFileNameA(cfg_path);
	fmt::print("{}\n", s2);
	char* s3 = PathFindNextComponentA(cfg_path);
	fmt::print("{}\n", s3);

	// 普通的路径增加,注意第一个参数
	char buffer_1[MAX_PATH] = "name_1\\name_2";
	PathAppendA(buffer_1, "def\\123");

	// 文件或文件夹是否存在1就代表存在
	int ret = PathFileExistsA("d:\\log1.txt");
	int ret2 = PathFileExistsA("E:\\vs2010-c++\\fmtTest");

得到模块或是exe的运行目录的函数:

static bool GetSelfModulePath(char* path)
{
	MEMORY_BASIC_INFORMATION mbi;
	HMODULE dllHandle = ((::VirtualQuery(GetSelfModulePath, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL);
	char t_path[MAX_PATH] = { 0 };
	GetModuleFileNameA(dllHandle, t_path, MAX_PATH);

	PathRemoveFileSpecA(t_path);
	strcpy_s(path, sizeof(t_path), t_path);
	return true;
}

static bool GetSelfModulePath2(char* path, char* combinFileName)
{
	MEMORY_BASIC_INFORMATION mbi;
	HMODULE dllHandle = ((::VirtualQuery(GetSelfModulePath2, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL);
	char t_path[MAX_PATH] = { 0 };
	GetModuleFileNameA(dllHandle, t_path, MAX_PATH);

	PathRemoveFileSpecA(t_path);
	PathCombineA(path, t_path, combinFileName);
	return true;
}

调用:

	char DllPath[MAX_PATH] = {0};
	GetSelfModulePath(DllPath);

	PathRemoveFileSpecA(DllPath);

	char domainPath[MAX_PATH] = { 0 };
	PathCombineA(domainPath, DllPath, "domain.ini");

	char url[256] = { 0 };
	GetPrivateProfileStringA("url", "drdata", "", url, sizeof(url),domainPath);

	char abc[256] = { 0 };
	GetSelfModulePath2(abc, "domain.ini");

        

       这两天和go语言访问json设计到utf8与ascii串互相转换

       // 先获取这个头文件并加入是vs2015工程

       // UnicodeConversions/utf8conv.h at master · GiovanniDicanio/UnicodeConversions · GitHub

        #include "Utf8Conv.h" 

        // ascii 串转成utf8 串 

        CStringW sss = L"你好";
        string testJson = GiovanniDicanio::win32::Utf8FromUtf16(sss);

      

        // utf8 串转成ascii串

        const std::string kinU8 = "\xE9\x87\x91";
        CStringW invalidUtf16 = GiovanniDicanio::win32::Utf16FromUtf8(kinU8);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值