MFC中取出编辑框字符串转换成16进制

DWORD CTOD(CString m_Send)
{
	char *stops, s[3] = {0};
	unsigned char  d[10] = {0};
	DWORD realLen = m_Send.GetLength();
	DWORD len = m_Send.GetLength() / 2 + m_Send.GetLength() %2;
	bool bFlag = FALSE;
	if (m_Send.GetLength() % 2 == 1)
	{
		bFlag = TRUE;
	}
	DWORD i=0;

	while (len)
	{
		if (len == 1&& bFlag)
		{
			s[0]= m_Send.GetAt(realLen - i * 2 -1 );
			s[1] = 0;
			s[2] = 0x0;
			d[i] = (unsigned char)strtoul(s, &stops, 16);
			return *(DWORD*)d;
		}
		
		s[0] = m_Send.GetAt(realLen - i * 2 -2);
		s[1] = m_Send.GetAt(realLen - i * 2-1);
		s[2] = 0x0;
		d[i] = (unsigned char)strtoul(s, &stops, 16);
		i++;
		len--;
	}
	return *(DWORD*)d;
}


//	以下为使用例子  例如编辑框输入1cab   CTOD返回的DWORD值就是0x1cab  无需加前缀0x
	CString Pid;
	GetDlgItemText(IDC_EDIT_PROCESSID,Pid );
	DWORD nPid = CTOD(Pid);

你可能感兴趣的:(C++语法,编程中的技巧,恶意代码行为分析)