VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 472|回复: 6

把此DLL动态链接库能不能VB6调用

[复制链接]
发表于 2017-11-28 23:28:00 | 显示全部楼层 |阅读模式
此动态链接win7/8/10/以下无需Admin权限。

Delphi 调用

function gethddsn32:string;stdcall;external'Get_HDDSN.dll';
能不能调用VB6?高手帮忙。

发表于 2017-11-29 10:29:57 | 显示全部楼层
没看到DLL在哪,
回复 支持 反对

使用道具 举报

发表于 2017-11-29 10:30:24 | 显示全部楼层
没看到DLL在哪,
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-11-29 17:29:25 | 显示全部楼层








本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

发表于 2017-11-30 08:46:05 | 显示全部楼层
直接使用以下模块就可以读取硬盘的物理序列号了。
  1. Option Explicit

  2. Private Const MAX_IDE_DRIVES As Long = 4 ' Max number of drives assuming primary/secondary, master/slave topology
  3. Private Const READ_ATTRIBUTE_BUFFER_SIZE As Long = 512
  4. Private Const IDENTIFY_BUFFER_SIZE As Long = 512
  5. Private Const READ_THRESHOLD_BUFFER_SIZE As Long = 512
  6. Private Const DFP_GET_VERSION As Long = &H74080
  7. Private Const DFP_SEND_DRIVE_COMMAND As Long = &H7C084
  8. Private Const DFP_RECEIVE_DRIVE_DATA As Long = &H7C088

  9. Private Type GETVERSIONOUTPARAMS
  10. bVersion As Byte ' Binary driver version.
  11. bRevision As Byte ' Binary driver revision.
  12. bReserved As Byte ' Not used.
  13. bIDEDeviceMap As Byte ' Bit map of IDE devices.
  14. fCapabilities As Long ' Bit mask of driver capabilities.
  15. dwReserved(3) As Long ' For future use.
  16. End Type

  17. Private Const CAP_IDE_ID_FUNCTION = 1 ' ' ATA ID command supported
  18. Private Const CAP_IDE_ATAPI_ID As Long = 2 ' ' ATAPI ID command supported
  19. Private Const CAP_IDE_EXECUTE_SMART_FUNCTION As Long = 4 ' SMART commannds supported

  20. Private Type IDEREGS
  21. bFeaturesReg As Byte ' Used for specifying SMART "commands".
  22. bSectorCountReg As Byte ' IDE sector count register
  23. bSectorNumberReg As Byte ' IDE sector number register
  24. bCylLowReg As Byte ' IDE low order cylinder value
  25. bCylHighReg As Byte ' IDE high order cylinder value
  26. bDriveHeadReg As Byte ' IDE drive/head register
  27. bCommandReg As Byte ' Actual IDE command.
  28. bReserved As Byte ' reserved for future use. Must be zero.
  29. End Type

  30. Private Type SENDCMDINPARAMS
  31. cBufferSize As Long ' Buffer size in bytes
  32. irDriveRegs As IDEREGS ' Structure with drive register values.
  33. bDriveNumber As Byte ' Physical drive number to send
  34. ' command to (0,1,2,3).
  35. bReserved(2) As Byte ' Reserved for future expansion.
  36. dwReserved(3) As Long ' For future use.
  37. bBuffer(0) As Byte ' Input buffer.
  38. End Type

  39. Private Const IDE_ATAPI_ID As Long = &HA1 ' Returns ID sector for ATAPI.
  40. Private Const IDE_ID_FUNCTION As Long = &HEC ' Returns ID sector for ATA.
  41. Private Const IDE_EXECUTE_SMART_FUNCTION As Long = &HB0 ' Performs SMART cmd.
  42. Private Const SMART_CYL_LOW As Long = &H4F
  43. Private Const SMART_CYL_HI As Long = &HC2

  44. Private Type DRIVERSTATUS
  45. bDriverError As Byte ' Error code from driver,
  46. bIDEStatus As Byte ' Contents of IDE Error register.
  47. bReserved(1) As Byte ' Reserved for future expansion.
  48. dwReserved(1) As Long ' Reserved for future expansion.
  49. End Type

  50. Private Const SMART_NO_ERROR As Long = 0 ' No error
  51. Private Const SMART_IDE_ERROR As Long = 1 ' Error from IDE controller
  52. Private Const SMART_INVALID_FLAG As Long = 2 ' Invalid command flag
  53. Private Const SMART_INVALID_COMMAND As Long = 3 ' Invalid command byte
  54. Private Const SMART_INVALID_BUFFER As Long = 4 ' Bad buffer (null, invalid addr..)
  55. Private Const SMART_INVALID_DRIVE As Long = 5 ' Drive number not valid
  56. Private Const SMART_INVALID_IOCTL As Long = 6 ' Invalid IOCTL
  57. Private Const SMART_ERROR_NO_MEM As Long = 7 ' Could not lock user's buffer
  58. Private Const SMART_INVALID_REGISTER As Long = 8 ' Some IDE Register not valid
  59. Private Const SMART_NOT_SUPPORTED As Long = 9 ' Invalid cmd flag set
  60. Private Const SMART_NO_IDE_DEVICE As Long = 10 ' Cmd issued to device not present

  61. Private Type SENDCMDOUTPARAMS
  62. cBufferSize As Long ' Size of bBuffer in bytes
  63. drvStatus As DRIVERSTATUS ' Driver status structure.
  64. bBuffer(0) As Byte ' Buffer of arbitrary length in which to store the data read from the drive.
  65. End Type

  66. Private Const SMART_READ_ATTRIBUTE_VALUES As Long = &HD0 ' ATA4: Renamed
  67. Private Const SMART_READ_ATTRIBUTE_THRESHOLDS As Long = &HD1 ' Obsoleted in ATA4!
  68. Private Const SMART_ENABLE_DISABLE_ATTRIBUTE_AUTOSAVE As Long = &HD2
  69. Private Const SMART_SAVE_ATTRIBUTE_VALUES As Long = &HD3
  70. Private Const SMART_EXECUTE_OFFLINE_IMMEDIATE As Long = &HD4 ' ATA4
  71. Private Const SMART_ENABLE_SMART_OPERATIONS As Long = &HD8
  72. Private Const SMART_DISABLE_SMART_OPERATIONS As Long = &HD9
  73. Private Const SMART_RETURN_SMART_STATUS As Long = &HDA

  74. Private Type DRIVEATTRIBUTE
  75. bAttrID As Byte ' Identifies which attribute
  76. wStatusFlags As Integer ' see bit definitions below
  77. bAttrValue As Byte ' Current normalized value
  78. bWorstValue As Byte ' How bad has it ever been?
  79. bRawValue(5) As Byte ' Un-normalized value
  80. bReserved As Byte ' ...
  81. End Type

  82. Private Type ATTRTHRESHOLD
  83. bAttrID As Byte 'Identifies which attribute
  84. bWarrantyThreshold As Byte ' Triggering value
  85. bReserved(9) As Byte ' ...
  86. End Type

  87. Private Type IDSECTOR
  88. wGenConfig As Integer
  89. wNumCyls As Integer
  90. wReserved As Integer
  91. wNumHeads As Integer
  92. wBytesPerTrack As Integer
  93. wBytesPerSector As Integer
  94. wSectorsPerTrack As Integer
  95. wVendorUnique(2) As Integer
  96. sSerialNumber(19) As Byte
  97. wBufferType As Integer
  98. wBufferSize As Integer
  99. wECCSize As Integer
  100. sFirmwareRev(7) As Byte
  101. sModelNumber(39) As Byte
  102. wMoreVendorUnique As Integer
  103. wDoubleWordIO As Integer
  104. wCapabilities As Integer
  105. wReserved1 As Integer
  106. wPIOTiming As Integer
  107. wDMATiming As Integer
  108. wBS As Integer
  109. wNumCurrentCyls As Integer
  110. wNumCurrentHeads As Integer
  111. wNumCurrentSectorsPerTrack As Integer
  112. ulCurrentSectorCapacity(3) As Byte '这里只能用byte,因为VB没有无符号的LONG型变量
  113. wMultSectorStuff As Integer
  114. ulTotalAddressableSectors(3) As Byte '这里只能用byte,因为VB没有无符号的LONG型变量
  115. wSingleWordDMA As Integer
  116. wMultiWordDMA As Integer
  117. bReserved(127) As Byte
  118. End Type

  119. Private Const ATTR_INVALID As Long = 0
  120. Private Const ATTR_READ_ERROR_RATE As Long = 1
  121. Private Const ATTR_THROUGHPUT_PERF As Long = 2
  122. Private Const ATTR_SPIN_UP_TIME As Long = 3
  123. Private Const ATTR_START_STOP_COUNT As Long = 4
  124. Private Const ATTR_REALLOC_SECTOR_COUNT As Long = 5
  125. Private Const ATTR_READ_CHANNEL_MARGIN As Long = 6
  126. Private Const ATTR_SEEK_ERROR_RATE As Long = 7
  127. Private Const ATTR_SEEK_TIME_PERF As Long = 8
  128. Private Const ATTR_POWER_ON_HRS_COUNT As Long = 9
  129. Private Const ATTR_SPIN_RETRY_COUNT As Long = 10
  130. Private Const ATTR_CALIBRATION_RETRY_COUNT As Long = 11
  131. Private Const ATTR_POWER_CYCLE_COUNT As Long = 12
  132. Private Const PRE_FAILURE_WARRANTY As Long = &H1
  133. Private Const ON_LINE_COLLECTION As Long = &H2
  134. Private Const PERFORMANCE_ATTRIBUTE As Long = &H4
  135. Private Const ERROR_RATE_ATTRIBUTE As Long = &H8
  136. Private Const EVENT_COUNT_ATTRIBUTE As Long = &H10
  137. Private Const SELF_PRESERVING_ATTRIBUTE As Long = &H20
  138. Private Const NUM_ATTRIBUTE_STRUCTS As Long = 30
  139. Private Const INVALID_HANDLE_VALUE As Long = -1
  140. Private Const VER_PLATFORM_WIN32s As Long = 0
  141. Private Const VER_PLATFORM_WIN32_WINDOWS As Long = 1
  142. Private Const VER_PLATFORM_WIN32_NT As Long = 2

  143. Private Type OSVERSIONINFO
  144. dwOSVersionInfoSize As Long
  145. dwMajorVersion As Long
  146. dwMinorVersion As Long
  147. dwBuildNumber As Long
  148. dwPlatformId As Long
  149. szCSDVersion As String * 128 ' Maintenance string for PSS usage
  150. End Type

  151. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
  152. Private Const CREATE_NEW As Long = 1
  153. Private Const GENERIC_READ As Long = &H80000000
  154. Private Const GENERIC_WRITE As Long = &H40000000
  155. Private Const FILE_SHARE_READ As Long = &H1
  156. Private Const FILE_SHARE_WRITE As Long = &H2
  157. Private Const OPEN_EXISTING As Long = 3
  158. 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
  159. 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
  160. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  161. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  162. Private m_DiskInfo As IDSECTOR
  163. 'Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

  164. Private Function OpenSMART(ByVal nDrive As Byte) As Long
  165. Dim hSMARTIOCTL As Long
  166. Dim hd As String
  167. Dim VersionInfo As OSVERSIONINFO
  168.     hSMARTIOCTL = INVALID_HANDLE_VALUE
  169.     VersionInfo.dwOSVersionInfoSize = Len(VersionInfo)
  170.     GetVersionEx VersionInfo
  171.     Select Case VersionInfo.dwPlatformId
  172.     Case VER_PLATFORM_WIN32s
  173.         OpenSMART = hSMARTIOCTL
  174.     Case VER_PLATFORM_WIN32_WINDOWS
  175.         hSMARTIOCTL = CreateFile("\\.\SMARTVSD", 0, 0, 0, CREATE_NEW, 0, 0)
  176.     Case VER_PLATFORM_WIN32_NT
  177.         If nDrive < MAX_IDE_DRIVES Then
  178.             hd = "\\.\PhysicalDrive" & nDrive
  179.             hSMARTIOCTL = CreateFile(hd, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
  180.         End If
  181.     End Select
  182.     OpenSMART = hSMARTIOCTL
  183. End Function

  184. 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
  185. pSCIP.cBufferSize = IDENTIFY_BUFFER_SIZE
  186. pSCIP.irDriveRegs.bFeaturesReg = 0
  187. pSCIP.irDriveRegs.bSectorCountReg = 1
  188. pSCIP.irDriveRegs.bSectorNumberReg = 1
  189. pSCIP.irDriveRegs.bCylLowReg = 0
  190. pSCIP.irDriveRegs.bCylHighReg = 0
  191. pSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4) '
  192. pSCIP.irDriveRegs.bCommandReg = bIDCmd
  193. pSCIP.bDriveNumber = bDriveNum
  194. pSCIP.cBufferSize = IDENTIFY_BUFFER_SIZE
  195. DoIDENTIFY = CBool(DeviceIoControl(hSMARTIOCTL, DFP_RECEIVE_DRIVE_DATA, _
  196. pSCIP, 32, _
  197. pSCOP(0), 528, _
  198. lpcbBytesReturned, 0))
  199. End Function

  200. Private Function DoEnableSMART(ByVal hSMARTIOCTL As Long, pSCIP As SENDCMDINPARAMS, pSCOP As SENDCMDOUTPARAMS, ByVal bDriveNum As Byte, lpcbBytesReturned As Long) As Boolean
  201. pSCIP.cBufferSize = 0
  202. pSCIP.irDriveRegs.bFeaturesReg = SMART_ENABLE_SMART_OPERATIONS
  203. pSCIP.irDriveRegs.bSectorCountReg = 1
  204. pSCIP.irDriveRegs.bSectorNumberReg = 1
  205. pSCIP.irDriveRegs.bCylLowReg = SMART_CYL_LOW
  206. pSCIP.irDriveRegs.bCylHighReg = SMART_CYL_HI
  207. pSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4)
  208. pSCIP.irDriveRegs.bCommandReg = IDE_EXECUTE_SMART_FUNCTION
  209. pSCIP.bDriveNumber = bDriveNum
  210. DoEnableSMART = CBool(DeviceIoControl(hSMARTIOCTL, DFP_SEND_DRIVE_COMMAND, _
  211. pSCIP, LenB(pSCIP) - 1, _
  212. pSCOP, LenB(pSCOP) - 1, _
  213. lpcbBytesReturned, 0))
  214. End Function

  215. Private Sub ChangeByteOrder(szString() As Byte, ByVal uscStrSize As Integer)
  216. Dim i As Integer
  217. Dim bTemp As Byte
  218.     For i = 0 To uscStrSize - 1 Step 2
  219.         bTemp = szString(i)
  220.         szString(i) = szString(i + 1)
  221.         szString(i + 1) = bTemp
  222.     Next i
  223. End Sub

  224. Private Sub DisplayIdInfo(pids As IDSECTOR, pSCIP As SENDCMDINPARAMS, ByVal bIDCmd As Byte, ByVal bDfpDriveMap As Byte, ByVal bDriveNum As Byte)
  225. ChangeByteOrder pids.sModelNumber, UBound(pids.sModelNumber) + 1
  226. ChangeByteOrder pids.sFirmwareRev, UBound(pids.sFirmwareRev) + 1
  227. ChangeByteOrder pids.sSerialNumber, UBound(pids.sSerialNumber) + 1
  228. End Sub

  229. Private Function GetDiskInfo(ByVal nDrive As Byte) As Long
  230. Dim hSMARTIOCTL As Long
  231. Dim cbBytesReturned As Long
  232. Dim VersionParams As GETVERSIONOUTPARAMS
  233. Dim scip As SENDCMDINPARAMS
  234. Dim scop() As Byte
  235. Dim OutCmd As SENDCMDOUTPARAMS
  236. Dim bDfpDriveMap As Byte
  237. Dim bIDCmd As Byte ' IDE or ATAPI IDENTIFY cmd
  238. Dim uDisk As IDSECTOR
  239. m_DiskInfo = uDisk

  240. hSMARTIOCTL = OpenSMART(nDrive)
  241. If hSMARTIOCTL <> INVALID_HANDLE_VALUE Then
  242.     Call DeviceIoControl(hSMARTIOCTL, DFP_GET_VERSION, ByVal 0, 0, VersionParams, Len(VersionParams), cbBytesReturned, 0)

  243.     If Not (VersionParams.bIDEDeviceMap \ 2 ^ nDrive And &H10) Then
  244.         If DoEnableSMART(hSMARTIOCTL, scip, OutCmd, nDrive, cbBytesReturned) Then
  245.             bDfpDriveMap = bDfpDriveMap Or 2 ^ nDrive
  246.         End If
  247.     End If
  248.     bIDCmd = IIf((VersionParams.bIDEDeviceMap \ 2 ^ nDrive And &H10), IDE_ATAPI_ID, IDE_ID_FUNCTION)
  249.     ReDim scop(LenB(OutCmd) + IDENTIFY_BUFFER_SIZE - 1) As Byte
  250.     If DoIDENTIFY(hSMARTIOCTL, scip, scop, bIDCmd, nDrive, cbBytesReturned) Then
  251.         CopyMemory m_DiskInfo, scop(LenB(OutCmd) - 4), LenB(m_DiskInfo)
  252.         Call DisplayIdInfo(m_DiskInfo, scip, bIDCmd, bDfpDriveMap, nDrive)
  253.         CloseHandle hSMARTIOCTL
  254.         GetDiskInfo = 1
  255.         Exit Function '>---> Bottom
  256.     End If
  257.     CloseHandle hSMARTIOCTL
  258.     GetDiskInfo = 0
  259. Else 'NOT HSMARTIOCTL...
  260.     GetDiskInfo = -1
  261. End If
  262. End Function
  263. '=====================================================
  264. Public Function GetDiskSN() As String
  265. On Error Resume Next
  266. If GetDiskInfo(0) <> -1 Then                    '如果有双硬盘,使用 GetDiskInfo(1),如此类推!
  267.     Dim a As String, b As String
  268.     a = StrConv(m_DiskInfo.sSerialNumber, vbUnicode)
  269.     a = Trim(a)
  270.     GetDiskSN = Replace(a, vbNullChar, "")      '取硬盘序列号
  271. End If
  272. End Function

  273. Public Function GetDiskID() As String
  274. On Error Resume Next
  275. If GetDiskInfo(0) <> -1 Then                    '如果有双硬盘,使用 GetDiskInfo(1),如此类推!
  276.     Dim b As String
  277.     b = StrConv(m_DiskInfo.sModelNumber, vbUnicode)
  278.     b = Trim(b)
  279.     GetDiskID = Replace(b, vbNullChar, "")      '取硬件厂商代码
  280. End If
  281. End Function

  282. 'Public Function GetSystemDir() As String '取系统盘的路径
  283. 'Dim aaa As String
  284. ' aaa = Space(255)
  285. ' GetWindowsDirectory aaa, 255
  286. ' aaa = Trim(aaa)
  287. ' aaa = Replace(aaa, vbNullChar, "")
  288. ' If Right(aaa, 1) <> "" Then aaa = aaa & ""
  289. ' getdir = aaa
  290. 'End Function

  291. Private Sub main()
  292.     MsgBox GetDiskSN
  293. End Sub
复制代码
回复 支持 反对

使用道具 举报

发表于 2017-12-5 15:27:51 | 显示全部楼层
可以调用,但是上面的函数原型是错误的。应该为: function gethddsn32(PWCHAR pwstr):Integer;stdcall;external'Get_HDDSN.dll';
回复 支持 反对

使用道具 举报

发表于 2017-12-6 15:16:38 | 显示全部楼层
stdcall 的可以被VB用
fastcall 的VB不支持
cdecl 的要有tlb才能被VB支持,但是你忽略栈平衡的话也是能用的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2017-12-19 00:37

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表