冰天雪地,裸体跪求,各位大侠把下面这段VC++的翻译成VB代码,小弟不甚感激(小弟我到死也不会忘记你,做鬼也不会放过你)/*
================================================================================
函数: int MxHexToAscii(unsigned char *hex,char * ascii,int nLength)
功能: 把nLength个字节逐个分解成2*nLength个可见字符。
高4位和低4位分别转换,直接加0x30。
参数:
返回值: 始终为0,表示成功。
================================================================================
*/
int MxHexToAscii(unsigned char *hex,char * ascii,int nLength)
{
int hiByte,loByte;
int i;
for ( i=0;i<nLength;i++)
{
hiByte=(hex[i]>>4)&0x0f;
loByte=hex[i]&0x0f;
ascii[i*2]=(char )(hiByte+48);
ascii[i*2+1]=(char)(loByte+48);
}
return 0;
}
/*
================================================================================
函数: int MxAsciiToHex(char * ascii,unsigned char * hex,int nLength)
功能: 把2*nLength个可见字符逐对合并成nLength个字节。
输入的可见字符要求在0x30和0x3F之间。
参数:
返回值: 0:成功;
-1:数据非法
================================================================================
*/
int MxAsciiToHex(char * ascii,unsigned char * hex,int nLength)
{
int hiByte,loByte;
int i;
for ( i=0;i<nLength;i++)
{
hiByte=ascii[i*2]-48;
if (hiByte<0 || hiByte>15)
return -1;
loByte=ascii[i*2+1]-48;
if (loByte<0 || loByte>15)
return -1;
hex[i]=(unsigned char)(hiByte*16+loByte);
}
return 0;
}
MxHexToAscii(iMyMb,mbchar,256);//把模板数据转从二进制转换到字符串,方便存储
mbchar[512]=0;//加结束符号
mbstr=mbchar;
================================================================================
函数: int MxHexToAscii(unsigned char *hex,char * ascii,int nLength)
功能: 把nLength个字节逐个分解成2*nLength个可见字符。
高4位和低4位分别转换,直接加0x30。
参数:
返回值: 始终为0,表示成功。
================================================================================
*/
int MxHexToAscii(unsigned char *hex,char * ascii,int nLength)
{
int hiByte,loByte;
int i;
for ( i=0;i<nLength;i++)
{
hiByte=(hex[i]>>4)&0x0f;
loByte=hex[i]&0x0f;
ascii[i*2]=(char )(hiByte+48);
ascii[i*2+1]=(char)(loByte+48);
}
return 0;
}
/*
================================================================================
函数: int MxAsciiToHex(char * ascii,unsigned char * hex,int nLength)
功能: 把2*nLength个可见字符逐对合并成nLength个字节。
输入的可见字符要求在0x30和0x3F之间。
参数:
返回值: 0:成功;
-1:数据非法
================================================================================
*/
int MxAsciiToHex(char * ascii,unsigned char * hex,int nLength)
{
int hiByte,loByte;
int i;
for ( i=0;i<nLength;i++)
{
hiByte=ascii[i*2]-48;
if (hiByte<0 || hiByte>15)
return -1;
loByte=ascii[i*2+1]-48;
if (loByte<0 || loByte>15)
return -1;
hex[i]=(unsigned char)(hiByte*16+loByte);
}
return 0;
}
MxHexToAscii(iMyMb,mbchar,256);//把模板数据转从二进制转换到字符串,方便存储
mbchar[512]=0;//加结束符号
mbstr=mbchar;
Public Function MxAsciiToHex(ByRef astrAscii As String, ByRef HexBytes() As Byte) As Integer
On Error GoTo myerr:
Dim lngLen As Long
Dim intI As Integer, hiByte As Integer, loByte As Integer
MxAsciiToHex = 0
intI = 1
lngLen = Len(astrAscii)
ReDim HexBytes(Int(lngLen / 2) - 1)
Do While intI <= lngLen
hiByte = Asc(Mid$(astrAscii, intI, 1)) - 48
If hiByte < 0 Or hiByte > 15 Then
MxAsciiToHex = -1
Exit Do
End If
intI = intI + 1
loByte = Asc(Mid$(astrAscii, intI, 1)) - 48
If loByte < 0 Or loByte > 15 Then
MxAsciiToHex = -1
Exit Do
End If
HexBytes(Int(intI / 2) - 1) = (hiByte * 16 + loByte)
intI = intI + 1
Loop
myerr:
If Err.Number <> 0 Then Err.Clear
End FunctionPublic Function MxHexToAscii(ByRef HexBytes() As Byte, ByRef astrAscii As String) As Integer
On Error GoTo myerr:
Dim lngUBound As Long
Dim intI As Integer, hiByte As Integer, loByte As Integer
lngUBound = UBound(HexBytes)
astrAscii = String(3 * lngUBound, Chr(0))
For intI = LBound(HexBytes) To lngUBound
loByte = (HexBytes(intI) And &HF)
hiByte = (HexBytes(intI) And &HF0) / 16
Mid(astrAscii, InStr(astrAscii, Chr(0)), 1) = Chr$(hiByte + 48)
Mid(astrAscii, InStr(astrAscii, Chr(0)), 1) = Chr$(loByte + 48)
Next
astrAscii = Left(astrAscii, InStr(astrAscii, Chr(0)) - 1)
MxHexToAscii = 0
myerr:
If Err.Number <> 0 Then Err.Clear
End Function
1 导出为第一代DLL(无类层次结构的API),用STDCALL声明.(不推荐)
2 用VC的ATL做成VB可以调用的包含类层次模型的ActiveX组件.(推荐)这样VC和VB就可以发挥各自的优势了(VC效率高可加密,VB编写简单高效).