高手进来,这段取硬盘ID的代码,怎么才能编译通过了。200分
不要叫我用dll.
Public Function GetDiskInfo(ByVal nDrive As Byte) As Long
    Dim hSMARTIOCTL As Long
    Dim cbBytesReturned As Long
    Dim VersionParams As GETVERSIONOUTPARAMS
    Dim scip As SENDCMDINPARAMS
    Dim scop() As Byte
    Dim OutCmd As SENDCMDOUTPARAMS
    Dim bDfpDriveMap As Byte
    Dim bIDCmd As Byte                    ' IDE or ATAPI IDENTIFY cmd
    Dim uDisk As IDSECTOR
    ' Clear buffer
    m_DiskInfo = uDisk
    '
    ' Try to get a handle to SMART IOCTL, report failure and exit if
    ' can't.
    '
    hSMARTIOCTL = OpenSMART(nDrive)
    If hSMARTIOCTL <> INVALID_HANDLE_VALUE Then
        '
        ' Get the version, etc of SMART IOCTL
        '        Call DeviceIoControl(hSMARTIOCTL, DFP_GET_VERSION, ByVal 0, 0, VersionParams, Len(VersionParams), cbBytesReturned, 0)        '
        ' If there is a IDE device at number "nDrive" issue commands
        ' to the device.
        '
        'if (VersionParams.bIDEDeviceMap >> nDrive & 1)
        '{        '
        ' Try to enable SMART so we can tell if a drive supports it.
        ' Ignore ATAPI devices.
        '        If Not (VersionParams.bIDEDeviceMap \ 2 ^ nDrive And &H10) Then
            If DoEnableSMART(hSMARTIOCTL, scip, OutCmd, nDrive, cbBytesReturned) Then
                '
                ' Mark the drive as SMART enabled
                '
                bDfpDriveMap = bDfpDriveMap Or 2 ^ nDrive
            End If
        End If
        '
        ' Now, get the ID sector for all IDE devices in the system.
        ' If the device is ATAPI use the IDE_ATAPI_ID command,
        ' otherwise use the IDE_ID_FUNCTION command.
        '
        bIDCmd = IIf((VersionParams.bIDEDeviceMap \ 2 ^ nDrive And &H10), IDE_ATAPI_ID, IDE_ID_FUNCTION)
        
        ReDim scop(LenB(OutCmd) + IDENTIFY_BUFFER_SIZE - 1) As Byte
        If DoIDENTIFY(hSMARTIOCTL, scip, scop, bIDCmd, nDrive, cbBytesReturned) Then
            CopyMemory m_DiskInfo, scop(LenB(OutCmd) - 4), LenB(m_DiskInfo)
            Call DisplayIdInfo(m_DiskInfo, scip, bIDCmd, bDfpDriveMap, nDrive)
            '
            ' Close SMART.
            '
            CloseHandle hSMARTIOCTL
            GetDiskInfo = 1
            Exit Function
        End If
        '}
        '
        ' Close SMART.
        '
        CloseHandle hSMARTIOCTL
        GetDiskInfo = 0
    Else
        GetDiskInfo = -1
    End If
End FunctionPublic Property Get pGenConfig() As Long
    pGenConfig = VBIntegerToUShort(m_DiskInfo.wGenConfig)
End PropertyPublic Property Get pNumCyls() As Long
    pNumCyls = VBIntegerToUShort(m_DiskInfo.wNumCyls)
End PropertyPublic Property Get pNumHeads() As Long
    pNumHeads = VBIntegerToUShort(m_DiskInfo.wNumHeads)
End PropertyPublic Property Get pBytesPerTrack() As Long
    pBytesPerTrack = VBIntegerToUShort(m_DiskInfo.wBytesPerTrack)
End PropertyPublic Property Get pBytesPerSector() As Long
    pBytesPerSector = VBIntegerToUShort(m_DiskInfo.wBytesPerSector)
End PropertyPublic Property Get pSectorsPerTrack() As Long
    pSectorsPerTrack = VBIntegerToUShort(m_DiskInfo.wSectorsPerTrack)
End PropertyPublic Property Get pSerialNumber() As Byte()
    pSerialNumber = m_DiskInfo.sSerialNumber
End PropertyPublic Property Get pBufferType() As Long
    pBufferType = VBIntegerToUShort(m_DiskInfo.wBufferType)
End PropertyPublic Property Get pBufferSize() As Long
    pBufferSize = VBIntegerToUShort(m_DiskInfo.wBufferSize)
End PropertyPublic Property Get pECCSize() As Long
    pECCSize = VBIntegerToUShort(m_DiskInfo.wECCSize)
End PropertyPublic Property Get pFirmwareRev() As Byte()
    pFirmwareRev = m_DiskInfo.sFirmwareRev
End PropertyPublic Property Get pModelNumber() As Byte()
    pModelNumber = m_DiskInfo.sModelNumber
End PropertyPublic Property Get pDoubleWordIO() As Long
    pDoubleWordIO = VBIntegerToUShort(m_DiskInfo.wDoubleWordIO)
End PropertyPublic Property Get pCapabilities() As Long
    pCapabilities = VBIntegerToUShort(m_DiskInfo.wCapabilities)
End PropertyPublic Property Get pPIOTiming() As Long
    pPIOTiming = VBIntegerToUShort(m_DiskInfo.wPIOTiming)
End PropertyPublic Property Get pDMATiming() As Long
    pDMATiming = VBIntegerToUShort(m_DiskInfo.wDMATiming)
End PropertyPublic Property Get pBS() As Long
    pBS = VBIntegerToUShort(m_DiskInfo.wBS)
End PropertyPublic Property Get pNumCurrentCyls() As Long
    pNumCurrentCyls = VBIntegerToUShort(m_DiskInfo.wNumCurrentCyls)
End PropertyPublic Property Get pNumCurrentHeads() As Long
    pNumCurrentHeads = VBIntegerToUShort(m_DiskInfo.wNumCurrentHeads)
End PropertyPublic Property Get pNumCurrentSectorsPerTrack() As Long
    pNumCurrentSectorsPerTrack = VBIntegerToUShort(m_DiskInfo.wNumCurrentSectorsPerTrack)
End PropertyPublic Property Get pCurrentSectorCapacity() As Long
    pCurrentSectorCapacity = m_DiskInfo.ulCurrentSectorCapacity
End PropertyPublic Property Get pMultSectorStuff() As Long
    pMultSectorStuff = VBIntegerToUShort(m_DiskInfo.wMultSectorStuff)
End PropertyPublic Property Get pTotalAddressableSectors() As Long
    pTotalAddressableSectors = m_DiskInfo.ulTotalAddressableSectors
End PropertyPublic Property Get pSingleWordDMA() As Long
    pSingleWordDMA = VBIntegerToUShort(m_DiskInfo.wSingleWordDMA)
End PropertyPublic Property Get pMultiWordDMA() As Long
    pMultiWordDMA = VBIntegerToUShort(m_DiskInfo.wMultiWordDMA)
End PropertyPrivate Function VBIntegerToUShort(ByVal i As Integer) As Long
    Call CopyMemory(VBIntegerToUShort, i, 2)
End Function

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1526/1526713.xml?temp=.2067835
      

  2.   

    新鲜出炉,获取真正磁盘序列号(VB版-1)
    http://expert.csdn.net/Expert/TopicView1.asp?id=1526696
    新鲜出炉,获取真正磁盘序列号(VB版-2)
    http://expert.csdn.net/Expert/TopicView1.asp?id=1526703
    新鲜出炉,获取真正磁盘序列号(VB版-3)
    http://expert.csdn.net/Expert/TopicView1.asp?id=1526710
    新鲜出炉,获取真正磁盘序列号(VB版-4)
    http://expert.csdn.net/Expert/topic/1526/1526713.xml?temp=.5162012
    把4个帖子按顺序连接在一起就是一个类模块了,另外经过测试在XP下可以取出硬盘硬件信息类模块名:CDiskInfo调用方法:
    Dim cDI As CDiskInfo, lRet As Long
    Set cDI = New CDiskInfo
    lRet = cDI.GetDiskInfo(0) '获取第一个硬盘
    If lRet = 1 Then
        Debug.Print StrConv(cDI.pSerialNumber, vbUnicode) '序列号
        Debug.Print StrConv(cDI.pModelNumber, vbUnicode) '型号
        Debug.Print StrConv(cDI.pFirmwareRev, vbUnicode) '修订号
    Else
        MsgBox "错误"
    End If
      

  3.   

    这个我用了的,下面是整理以后的,直接可以用了
    www.jiaxinda.com/dont_delete/98及2K取硬盘id号_类.exe
    http://vip.6to23.com/NowCan1/tech/vb_hd_info.htm
    http://vip.6to23.com/NowCan1/code/hd_info.zip