Unicode字符集下代码
在Unicode字符集下,以下代码可用,代码来自网络,修改后增加了个测试函数。在此对代码贡献者表示感谢!?
HMODULE GetSelfModuleHandle()
{
MEMORY_BASIC_INFORMATION mbi;
return ((::VirtualQuery(GetSelfModuleHandle, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL);
}
void TCHAR2Char(const TCHAR* tchar, char* _char)
{
int iLength;
//获取字节长度
iLength = WideCharToMultiByte(CP_ACP, 0, LPCWSTR(tchar), -1, NULL, 0, NULL, NULL);
//将tchar值赋给_char
WideCharToMultiByte(CP_ACP, 0, LPCWSTR(tchar), -1, _char, iLength, NULL, NULL);
}
string GetInstanceFolderPath()
{
string exePath = "";
TCHAR tcFullPath[MAX_PATH];
char* pChPath = new char[MAX_PATH];
memset(pChPath, '\0', MAX_PATH);
/** 获取当前程序的执行路径