當(dāng)把C代碼翻譯到VB時(shí),你經(jīng)常會(huì)遇到高字和低字的操作,通常是把兩個(gè)整型值合成一個(gè)長(zhǎng)整型。當(dāng)在C代碼中使用了無(wú)符號(hào)整型,這一位是可以被設(shè)置的,考試.大提示因此簡(jiǎn)單的直接轉(zhuǎn)換高字將會(huì)遇到困難。由于VB不支持無(wú)符號(hào)算術(shù)符,我們只好剝?nèi)ミ@一位,在稍后再把它加回來(lái),以避免溢出和錯(cuò)誤的結(jié)果。(WXJ_Lake 譯)
開(kāi)始一個(gè)新工程,增添一個(gè)標(biāo)準(zhǔn)模塊。把以下代碼寫(xiě)入模塊:
Start a new project then add a module. Add the following code to the module:
Public Property Get LoWord(ByRef lThis As Long) As Long
LoWord = (lThis And &HFFFF&)
End Property
Public Property Let LoWord(ByRef lThis As Long, ByVal lLoWord As Long)
lThis = lThis And Not &HFFFF& Or lLoWord
End Property
Public Property Get HiWord(ByRef lThis As Long) As Long
If (lThis And &H80000000) = &H80000000 Then
HiWord = ((lThis And &H7FFF0000) &H10000) Or &H8000&
Else
HiWord = (lThis And &HFFFF0000) &H10000
End If
End Property
Public Property Let HiWord(ByRef lThis As Long, ByVal lHiWord As Long)
If (lHiWord And &H8000&) = &H8000& Then
lThis = lThis And Not &HFFFF0000 Or ((lHiWord And &H7FFF&) * &H10000) Or &H80000000
Else
lThis = lThis And Not &HFFFF0000 Or (lHiWord * &H10000)
End If
End Property
開(kāi)始一個(gè)新工程,增添一個(gè)標(biāo)準(zhǔn)模塊。把以下代碼寫(xiě)入模塊:
Start a new project then add a module. Add the following code to the module:
Public Property Get LoWord(ByRef lThis As Long) As Long
LoWord = (lThis And &HFFFF&)
End Property
Public Property Let LoWord(ByRef lThis As Long, ByVal lLoWord As Long)
lThis = lThis And Not &HFFFF& Or lLoWord
End Property
Public Property Get HiWord(ByRef lThis As Long) As Long
If (lThis And &H80000000) = &H80000000 Then
HiWord = ((lThis And &H7FFF0000) &H10000) Or &H8000&
Else
HiWord = (lThis And &HFFFF0000) &H10000
End If
End Property
Public Property Let HiWord(ByRef lThis As Long, ByVal lHiWord As Long)
If (lHiWord And &H8000&) = &H8000& Then
lThis = lThis And Not &HFFFF0000 Or ((lHiWord And &H7FFF&) * &H10000) Or &H80000000
Else
lThis = lThis And Not &HFFFF0000 Or (lHiWord * &H10000)
End If
End Property