您的位置:程序门 -> vb ->



asp调用dll文件的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


asp调用dll文件的问题
发表于:2007-10-26 16:31:19 楼主
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  

        m_diskinfo   =   udisk  
          '  
          '  
        hsmartioctl   =   opensmart(ndrive)  
        if   hsmartioctl     <   >   invalid_handle_value   then  

        call   deviceiocontrol(hsmartioctl,   dfp_get_version,   byval   0,   0,   versionparams,   len(versionparams),   cbbytesreturned,   0)  

        if   not   (versionparams.bidedevicemap   \   2   ^   ndrive   and   &h10)   then  
        if   doenablesmart(hsmartioctl,   scip,   outcmd,   ndrive,   cbbytesreturned)   then  
        bdfpdrivemap   =   bdfpdrivemap   or   2   ^   ndrive  
        end   if  
        end   if  
        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)  
        closehandle   hsmartioctl  
        getdiskinfo   =   1  
        exit   function             '   > ---     >       bottom  
        end   if  
        closehandle   hsmartioctl  
        getdiskinfo   =   0  
        else         'not       hsmartioctl...  
        getdiskinfo   =   -2  
        end   if  

end   function  
  这是vb取硬盘序列号的dll文件中一段   在asp中调用了   为什么只显示-2   应该怎么调用才能正确取出硬盘序列号
发表于:2007-10-26 16:50:091楼 得分:0
private   const   max_ide_drives   as   long   =   4   'max   number   of   drives   assuming   primary/secondary,master/slave   topology
private   const   read_attribute_buffer_size               as   long   =   512
private   const   identify_buffer_size               as   long   =   512
private   const   read_threshold_buffer_size               as   long   =   512
private   const   dfp_get_version               as   long   =   &h74080
private   const   dfp_send_drive_command               as   long   =   &h7c084
private   const   dfp_receive_drive_data               as   long   =   &h7c088

private   type   getversionoutparams
        bversion       as   byte               '       binary       driver       version.
        brevision       as   byte               '       binary       driver       revision.
        breserved       as   byte               '       not       used.
        bidedevicemap       as   byte               '       bit       map       of       ide       devices.
        fcapabilities       as   long               '     bit       mask       of       driver       capabilities.
        dwreserved(3)       as   long               '       for       future       use.
end   type

private   const   cap_ide_id_function               as   long   =   1                       '       ata       id       command       supported
private   const   cap_ide_atapi_id               as   long   =   2                       '       atapi       id       command       supported
private   const   cap_ide_EXECute_smart_function               as   long   =   4                       '       smart       commannds       supported

private   type   ideregs
        bfeaturesreg       as   byte               '       used       for       specifying       smart       "commands".
        bsectorcountreg       as   byte             '       ide       sector       count       register
        bsectornumberreg       as   byte             '       ide       sector       number       register
        bcyllowreg       as   byte               '       ide       low       order       cylinder       value
        bcylhighreg       as   byte               '"       ide       high       order       cylinder       value
        bdriveheadreg       as   byte             '       ide       drive/head       register
        bcommandreg       as   byte               '       actual       ide       command.
        breserved       as   byte               '     reserved       for       future       use.           must       be       zero.
end   type

private   type   sendcmdinparams
        cbuffersize       as   long             '       buffer       size       in       bytes
        irdriveregs       as   ideregs             '       structure       with       drive       register       values.
        bdrivenumber       as   byte               '       physical       drive       number       to       send
        'command       to       (0,1,2,3)
        breserved(2)       as   byte               '     reserved       for       future       expansion.
        dwreserved(3)       as   long             '       for       future       use.
        bbuffer(0)       as   byte               '       input       buffer.
end   type

private   const   ide_atapi_id               as   long   =   &ha1                     '     returns       id       sector       for       atapi.
private   const   ide_id_function               as   long   =   &hec                       '       returns       id       sector       for       ata.
private   const   ide_EXECute_smart_function               as   long   =   &hb0                       '     performs       smart       cmd.
private   const   smart_cyl_low               as   long   =   &h4f
private   const   smart_cyl_hi               as   long   =   &hc2

private   type   driverstatus
        bdrivererror       as   byte               '     error       code       from       driver,
        bidestatus       as   byte             '       contents       of       ide       error       register.
        breserved(1)       as   byte               '       reserved       for       future       expansion.
        dwreserved(1)       as   long             '       reserved       for       future       expansion.
end   type

private   const   smart_no_error               as   long   =   0                       '       no       error
private   const   smart_ide_error               as   long   =   1                       '       error       from       ide       controller
private   const   smart_invalid_flag               as   long   =   2                       '"       invalid       command       flag
private   const   smart_invalid_command               as   long   =   3                       '"       invalid       command       byte
private   const   smart_invalid_buffer               as   long   =   4                       '"       bad       buffer       (null,       invalid       addr..)
private   const   smart_invalid_drive               as   long   =   5                       '"       drive       number       not       valid
private   const   smart_invalid_ioctl               as   long   =   6                       '"       invalid       ioctl
private   const   smart_error_no_mem               as   long   =   7                       '"       could       not       lock       user   "s       buffer
private   const   smart_invalid_register               as   long   =   8                       '"       some       ide       register       not       valid
private   const   smart_not_supported               as   long   =   9                       '"       invalid       cmd       flag       set
private   const   smart_no_ide_device               as   long   =   10                   '"       cmd       issued       to       device       not       present

private   type   sendcmdoutparams
        cbuffersize       as   long               '       size       of       bbuffer       in       bytes
        drvstatus       as   driverstatus               '       driver       status       structure.
        bbuffer(0)       as   byte               '     buffer       of       arbitrary       length       in       which       to       store       the       data       read       from       the           "       drive.
end   type

private   const   smart_read_attribute_values               as   long   =   &hd0                       '"       ata4:       renamed
private   const   smart_read_attribute_thresholds               as   long   =   &hd1                     '   "       obsoleted       in       ata4!
private   const   smart_enable_disable_attribute_autosave               as   long   =   &hd2
private   const   smart_save_attribute_values               as   long   =   &hd3
private   const   smart_EXECute_offline_immediate               as   long   =   &hd4                     '   "       ata4
private   const   smart_enable_smart_operations               as   long   =   &hd8
private   const   smart_disable_smart_operations               as   long   =   &hd9
private   const   smart_return_smart_status               as   long   =   &hda


发表于:2007-10-26 16:50:292楼 得分:0
private   type   driveattribute
        battrid       as   byte             '   "       identifies       which       attribute
        wstatusflags       as   integer               '"       see       bit       definitions       below
        battrvalue       as   byte             '   "       current       normalized       value
        bworstvalue       as   byte               '"       how       bad       has       it       ever       been?
        brawvalue(5)       as   byte               '"       un-normalized       value
        breserved       as   byte               '"       ...
end   type

private   type   attrthreshold
        battrid       as   byte               '"       identifies       which       attribute
        bwarrantythreshold       as   byte           '"       triggering       value
        breserved(9)       as   byte               '"       ...
end   type

private   type   idsector
        wgenconfig       as   integer
        wnumcyls       as   integer
        wreserved       as   integer
        wnumheads       as   integer
        wbytespertrack       as   integer
        wbytespersector       as   integer
        wsectorspertrack       as   integer
        wvendorunique(2)       as   integer
        sserialnumber(19)       as   byte
        wbuffertype       as   integer
        wbuffersize       as   integer
        weccsize       as   integer
        sfirmwarerev(7)       as   byte
        smodelnumber(39)       as   byte
        wmorevendorunique       as   integer
        wdoublewordio       as   integer
        wcapabilities       as   integer
        wreserved1       as   integer
        wpiotiming       as   integer
        wdmatiming       as   integer
        wbs       as   integer
        wnumcurrentcyls       as   integer
        wnumcurrentheads       as   integer
        wnumcurrentsectorspertrack       as   integer
        ulcurrentsectorcapacity(3)       as   byte               '"这里只能用byte,因为vb没有无符号的long型变量
        wmultsectorstuff       as   integer
        ultotaladdressablesectors(3)       as   byte               '"这里只能用byte,因为vb没有无符号的long型变量
        wsingleworddma       as   integer
        wmultiworddma       as   integer
        breserved(127)       as   byte
end   type

private   const   attr_invalid               as   long   =   0
private   const   attr_read_error_rate               as   long   =   1
private   const   attr_throughput_perf               as   long   =   2
private   const   attr_spin_up_time               as   long   =   3
private   const   attr_start_stop_count               as   long   =   4
private   const   attr_realloc_sector_count               as   long   =   5
private   const   attr_read_channel_margin               as   long   =   6
private   const   attr_seek_error_rate               as   long   =   7
private   const   attr_seek_time_perf               as   long   =   8
private   const   attr_power_on_hrs_count               as   long   =   9
private   const   attr_spin_retry_count               as   long   =   10
private   const   attr_calibration_retry_count               as   long   =   11
private   const   attr_power_cycle_count               as   long   =   12

private   const   pre_failure_warranty               as   long   =   &h1
private   const   on_line_collection               as   long   =   &h2
private   const   performance_attribute               as   long   =   &h4
private   const   error_rate_attribute               as   long   =   &h8
private   const   event_count_attribute               as   long   =   &h10
private   const   self_preserving_attribute               as   long   =   &h20

private   const   num_attribute_structs               as   long   =   30
private   const   invalid_handle_value               as   long   =   -1

private   const   ver_platform_win32s               as   long   =   0
private   const   ver_platform_win32_windows               as   long   =   1
private   const   ver_platform_win32_nt               as   long   =   2

private   type   osversioninfo
        dwosversioninfosize       as   long
        dwmajorversion       as   long
        dwminorversion       as   long
        dwbuildnumber       as   long
        dwplatformid       as   long
        szcsdversion       as   string   *   128                       '"           maintenance       string       for       pss       usage
end   type

private   const   create_new               as   long   =   1
private   const   generic_read               as   long   =   &h80000000
private   const   generic_write               as   long   =   &h40000000
private   const   file_share_read               as   long   =   &h1
private   const   file_share_write               as   long   =   &h2
private   const   open_existing                   as   long   =   3

private   m_diskinfo           as   idsector

private   declare   function   getversionex   lib   "kernel32"   alias   "getversionexa"   (lpversioninformation   as   osversioninfo)   as   long
private   declare   function   createfile   lib   "kernel32"   alias   "createfilea"   (byval   lpfilename   as   string,   byval   dwdesiredaccess   as   long,   byval   dwsharemode   as   long,   byval   lpsecurityattributes   as   long,   byval   dwcreationdisposition   as   long,   byval   dwflagsandattributes   as   long,   byval   htemplatefile   as   long)   as   long
private   declare   function   deviceiocontrol   lib   "kernel32"   (byval   hdevice   as   long,   byval   dwiocontrolcode   as   long,   lpinbuffer   as   any,   byval   ninbuffersize   as   long,   lpoutbuffer   as   any,   byval   noutbuffersize   as   long,   lpbytesreturned   as   long,   byval   lpoverlapped   as   long)   as   long
private   declare   function   closehandle   lib   "kernel32"   (byval   hobject   as   long)   as   long
private   declare   sub   copymemory   lib   "kernel32"   alias   "rtlmovememory"   (destination   as   any,   source   as   any,   byval   length   as   long)

private   declare   function   getvolumeinformation   lib   "kernel32"   alias   "getvolumeinformationa"   (byval   lprootpathname   as   string,   byval   lpvolumenamebuffer   as   string,   byval   nvolumenamesize   as   long,   lpvolumeserialnumber   as   long,   lpmaximumcomponentlength   as   long,   lpfilesystemflags   as   long,   byval   lpfilesystemnamebuffer   as   string,   byval   nfilesystemnamesize   as   long)   as   long

'"信息类型枚举
enum   euminfotype
        hdmodelsn   =   0
        hdonlymodel   =   1
        hdonlysn   =   2
end   enum

'"磁盘通道枚举
enum   eumdiskno
        hdprimarymaster   =   0
        hdprimaryslave   =   1
        hdsecondarymaster   =   2
        hdsecondaryslave   =   3
end   enum

'"取得逻辑盘序列号(非唯一)
function   getdiskvolume(optional   byval   strdiskname   =   "c")   as   string
        dim   tempstr1           as   string   *   256,   tempstr2                       as   string   *   256
        dim   templon1           as   long,   templon2               as   long,   getval               as   long
       
        dim   tmpvol           as   string
       
        call   getvolumeinformation(strdiskname   &   ":\",   tempstr1,   256,   getval,   templon1,   templon2,   tempstr2,   256)
        if   getval   =   0   then
        tmpvol   =   ""
        else
        tmpvol   =   hex(getval)
        tmpvol   =   string(8   -   len(tmpvol),   "0")   &   tmpvol
        tmpvol   =   left(tmpvol,   4)   &   "-"   &   right(tmpvol,   4)
        end   if
        getdiskvolume   =   tmpvol
end   function
发表于:2007-10-26 16:50:523楼 得分:0
'取得硬盘信息:型号/物理系列号(唯一)
function   getharddiskinfo(optional   byval   numdisk   as   eumdiskno   =   hdprimarymaster,   optional   byval   numtype   as   euminfotype   =   hdonlysn)   as   string

        if   getdiskinfo(numdisk)   =   1   then
        dim   pserialnumber           as   string,   pmodelnumber               as   string
        pserialnumber   =   strconv(m_diskinfo.sserialnumber,   vbunicode)
        pmodelnumber   =   strconv(m_diskinfo.smodelnumber,   vbunicode)
       
        select   case   numtype
        case   hdonlymodel               '仅型号
        getharddiskinfo   =   trim(pmodelnumber)
        case   hdonlysn               '"仅系列号
        getharddiskinfo   =   trim(pserialnumber)
        case   else               '"型号,系列号
        getharddiskinfo   =   trim(pmodelnumber)   &   ","   &   trim(pserialnumber)
        end   select
        end   if

end   function

private   function   opensmart(byval   ndrive   as   byte)   as   long
        dim   hsmartioctl           as   long
        dim   hd           as   string
        dim   versioninfo           as   osversioninfo

        hsmartioctl   =   invalid_handle_value
        versioninfo.dwosversioninfosize   =   len(versioninfo)
        getversionex   versioninfo
        select   case   versioninfo.dwplatformid
        case   ver_platform_win32s
        opensmart   =   hsmartioctl
        case   ver_platform_win32_windows
        hsmartioctl   =   createfile("\\.\smartvsd",   0,   0,   0,   create_new,   0,   0)
        case   ver_platform_win32_nt
        if   ndrive   <   max_ide_drives   then
        'hd       =       "file://./physicaldrive"       &       ndrive
        hd   =   "\\.\physicaldrive"   &   ndrive
        hsmartioctl   =   createfile(hd,   generic_read   or   generic_write,   file_share_read   or   file_share_write,   0,   open_existing,   0,   0)
        end   if
        end   select
        opensmart   =   hsmartioctl

end   function

private   function   doidentify(byval   hsmartioctl   as   long,   pscip   as   sendcmdinparams,   pscop()   as   byte,   byval   bidcmd   as   byte,   byval   bdrivenum   as   byte,   lpcbbytesreturned   as   long)   as   boolean
        pscip.cbuffersize   =   identify_buffer_size

        pscip.irdriveregs.bfeaturesreg   =   0
        pscip.irdriveregs.bsectorcountreg   =   1
        pscip.irdriveregs.bsectornumberreg   =   1
        pscip.irdriveregs.bcyllowreg   =   0
        pscip.irdriveregs.bcylhighreg   =   0

        pscip.irdriveregs.bdriveheadreg   =   &ha0   or   ((bdrivenum   and   1)   *   2   ^   4)
        pscip.irdriveregs.bcommandreg   =   bidcmd
        pscip.bdrivenumber   =   bdrivenum
        pscip.cbuffersize   =   identify_buffer_size
        doidentify   =   cbool(deviceiocontrol(hsmartioctl,   dfp_receive_drive_data,   _
        pscip,   32,   _
        pscop(0),   528,   _
        lpcbbytesreturned,   0))

end   function

private   function   doenablesmart(byval   hsmartioctl   as   long,   pscip   as   sendcmdinparams,   pscop   as   sendcmdoutparams,   byval   bdrivenum   as   byte,   lpcbbytesreturned   as   long)   as   boolean
        pscip.cbuffersize   =   0

        pscip.irdriveregs.bfeaturesreg   =   smart_enable_smart_operations
        pscip.irdriveregs.bsectorcountreg   =   1
        pscip.irdriveregs.bsectornumberreg   =   1
        pscip.irdriveregs.bcyllowreg   =   smart_cyl_low
        pscip.irdriveregs.bcylhighreg   =   smart_cyl_hi
        pscip.irdriveregs.bdriveheadreg   =   &ha0   or   ((bdrivenum   and   1)   *   2   ^   4)
        pscip.irdriveregs.bcommandreg   =   ide_EXECute_smart_function
        pscip.bdrivenumber   =   bdrivenum

        doenablesmart   =   cbool(deviceiocontrol(hsmartioctl,   dfp_send_drive_command,   _
        pscip,   lenb(pscip)   -   1,   _
        pscop,   lenb(pscop)   -   1,   _
        lpcbbytesreturned,   0))

end   function

'---------------------------------------------------------------------
'"---------------------------------------------------------------------
private   sub   changebyteorder(szstring()   as   byte,   byval   uscstrsize   as   integer)

        dim   i           as   integer
        dim   btemp           as   byte

        for   i   =   0   to   uscstrsize   -   1   step   2
        btemp   =   szstring(i)
        szstring(i)   =   szstring(i   +   1)
        szstring(i   +   1)   =   btemp
        next   i

end   sub

private   sub   displayidinfo(pids   as   idsector,   pscip   as   sendcmdinparams,   byval   bidcmd   as   byte,   byval   bdfpdrivemap   as   byte,   byval   bdrivenum   as   byte)

        changebyteorder   pids.smodelnumber,   ubound(pids.smodelnumber)   +   1

        changebyteorder   pids.sfirmwarerev,   ubound(pids.sfirmwarerev)   +   1

        changebyteorder   pids.sserialnumber,   ubound(pids.sserialnumber)   +   1

end   sub

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

        m_diskinfo   =   udisk
        '
        '
        hsmartioctl   =   opensmart(ndrive)
        if   hsmartioctl   <>   invalid_handle_value   then

        call   deviceiocontrol(hsmartioctl,   dfp_get_version,   byval   0,   0,   versionparams,   len(versionparams),   cbbytesreturned,   0)

        if   not   (versionparams.bidedevicemap   \   2   ^   ndrive   and   &h10)   then
        if   doenablesmart(hsmartioctl,   scip,   outcmd,   ndrive,   cbbytesreturned)   then
        bdfpdrivemap   =   bdfpdrivemap   or   2   ^   ndrive
        end   if
        end   if
        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)
        closehandle   hsmartioctl
        getdiskinfo   =   1
        exit   function           '> ---   >       bottom
        end   if
        closehandle   hsmartioctl
        getdiskinfo   =   0
        else       'not       hsmartioctl...
        getdiskinfo   =   -2
        end   if

end   function
这是全部dll代码


快速检索

最新资讯
热门点击