如何把CString转换为DWORD

2025-02-23 21:36:52
推荐回答(2个)
回答1:

int htoi(const char* psz)
{
ASSERT(psz);
size_t nlen = ::strlen(psz);

int result = 0;
for(size_t i = 0; i < nlen; i++)
{
int digit = ctoi(*psz++);
result += int(digit*::pow(16, nlen - 1 - i));
}

return result;
}
这个函数可以直接完成你的要求。

回答2:

CString sp("51d3fc34");
CString showbox;
DWORD show;
sscanf(sp,"%x",&show);
showbox.Format("%08x",show);
AfxMessageBox(showbox);