我不管,那我发贴吧里面了
UINT CBasicOperation::TransformToHex(CString csInput, BYTE* Result, UINT& nLen)
{
WCHAR* wcIpt;
UINT nLength;
BYTE Get[2];
CString csKeyWords;
UINT nLenKey;
UINT Found;
csKeyWords = L" 0123456789ABCDEFabcdef";
nLenKey = csKeyWords.GetLength();
WCHAR wcKey[30];
wcscpy(wcKey, csKeyWords);
nLength = csInput.GetLength();
if(!nLength)return 0;
wcIpt = new WCHAR[nLength + 1];
wcscpy(wcIpt, csInput);
wcIpt[nLength] = 0;
nLen = 0;
for(int i = 0 ;i < nLength; i ++)
{
Found = 0;
for(int j = 0; j < nLenKey; j ++)
{
if(wcKey[j] == wcIpt[i])
Found = j + 1;
}
if (!Found){delete wcIpt;return 0;}
if(Found == 1)continue;
{
if(TransformSingleToHex(wcIpt[i], Get + 0) &&
TransformSingleToHex(wcIpt[i + 1], Get + 1))
{
Result[nLen] = Get[0] << 4 | Get[1];
i ++;
}
}
nLen ++;
}
delete wcIpt;
return 1;
}
int CBasicOperation::TransformSingleToHex(WCHAR wc, BYTE* btResult)
{
switch(wc)
{
case '0': btResult[0] = 0; return 1;
case '1': btResult[0] = 1; return 1;
case '2': btResult[0] = 2; return 1;
case '3': btResult[0] = 3; return 1;
case '4': btResult[0] = 4; return 1;
case '5': btResult[0] = 5; return 1;
case '6': btResult[0] = 6; return 1;
case '7': btResult[0] = 7; return 1;
case '8': btResult[0] = 8; return 1;
case '9': btResult[0] = 9; return 1;
case 'a': btResult[0] = 10; return 1;
case 'b': btResult[0] = 11; return 1;
case 'c': btResult[0] = 12; return 1;
case 'd': btResult[0] = 13; return 1;
case 'e': btResult[0] = 14; return 1;
case 'f': btResult[0] = 15; return 1;
case 'A': btResult[0] = 10; return 1;
case 'B': btResult[0] = 11; return 1;
case 'C': btResult[0] = 12; return 1;
case 'D': btResult[0] = 13; return 1;
case 'E': btResult[0] = 14; return 1;
case 'F': btResult[0] = 15; return 1;
}
return 0;
}