1 Star 2 Fork 0

kunger/PeView

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Utilities.cpp 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
kunger 提交于 2020-04-07 11:26 . init
#include "StdAfx.h"
#include "Utilities.h"
CUtilities::CUtilities()
{
}
CUtilities::~CUtilities()
{
}
BOOL CUtilities::ReleaseRes(UINT ResID,LPCTSTR lpType,LPCTSTR destFile)
{
//查找资源文件
HRSRC res = FindResource(NULL, MAKEINTRESOURCE(ResID), lpType); //实际使用时修改这里即可MAKEINTRESOURCE(IDR_SYS),TEXT("BINARY")
if (!res)
return FALSE;
//加载资源
HGLOBAL resGlobal = LoadResource(NULL, res);
if (!resGlobal)
return FALSE;
//资源文件大小
DWORD size = SizeofResource(NULL, res);
//锁定资源
BYTE* ptr = (BYTE*)LockResource(resGlobal);
if (!ptr)
return FALSE;
//创建文件 实际使用时修改XXX.sys
HANDLE hFile = CreateFile(destFile, GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
DWORD dw;
//将资数据写入文件
if (!WriteFile(hFile, ptr, size, &dw, NULL)){
CloseHandle(hFile);
return FALSE;
}
CloseHandle(hFile);
return TRUE;
}
char * wchar2char(const wchar_t* wchar)
{
char * m_char;
int len = WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), NULL, 0, NULL, NULL);
m_char = new char[len + 1];
WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), m_char, len, NULL, NULL);
m_char[len] = '\0';
return m_char;
}
wchar_t * char2wchar(const char* cchar)
{
wchar_t *m_wchar;
int len = MultiByteToWideChar(CP_ACP, 0, cchar, strlen(cchar), NULL, 0);
m_wchar = new wchar_t[len + 1];
MultiByteToWideChar(CP_ACP, 0, cchar, strlen(cchar), m_wchar, len);
m_wchar[len] = '\0';
return m_wchar;
}
BOOL hexstr2int(CDuiString sHex,int &iRet)
{
iRet = 0;
BOOL bRet = FALSE;
char* chex = wchar2char(sHex.GetData());
char*hex = chex;
int res = 0;
for (; *hex; hex++)
{
int d = toupper(*hex);
if (d >= '0' && d <= '9')d -= '0';
else
if (d >= 'A' && d <= 'F')d -= 'A' - 10;
else break;
res = res * 16 + d;
}
iRet = res;
delete[] chex;
bRet = TRUE;
return bRet;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/kunger/PeView.git
git@gitee.com:kunger/PeView.git
kunger
PeView
PeView
master

搜索帮助