CPUInfo ========================================================== form 部分,添加2 Buttons: ========================================================== Private Sub cmdCallFunc_Click(Index As Integer) Select Case Index Case 0 lblFuncRet(Index) = CBool(wincpuidsupport()) Case 1 lblFuncRet(Index) = ProcessorCount() Case 2 Me.MousePointer = vbHourglass lblFuncRet(Index) = cpunormspeed() Me.MousePointer = vbDefault Case 3 Me.MousePointer = vbHourglass lblFuncRet(Index) = cpurawspeed() Me.MousePointer = vbDefault Case 4 lblFuncRet(Index) = GetCPUDescription() Case 5 lblFuncRet(Index) = GetCPUDescriptionString(Verbose:=CBool(chkVerbose.Value)) Case 6 lblFuncRet(Index) = GetCPUModel() Case 7 lblFuncRet(Index) = GetCPUType() Case 8 lblFuncRet(Index) = wincpuid() Case 9 lblFuncRet(Index) = CPUHasMMX() Case 10 lblFuncRet(Index) = CPUHasFPU() Case 11 lblFuncRet(Index) = CPUHasTimeStampCounter() Case 12 Dim vs As DLL_VER Call GetDllVerString(vs) lblFuncRet(Index) = vs.Major & "." & vs.Minor End Select End SubPrivate Sub cmdTimeStamp_Click() Dim ts As TIME_STAMP Dim Output As String Dim i As LongIf GetTimeStampCode(ts) Then Output = Hex$(ts.dwHigh) Output = Output & " : " & Hex$(ts.dwLow) Call lstTimeStamp.AddItem(Output) Else MsgBox "CPU does not have timestamp register" End If End Sub =============================================================== .bas 部分: =============================================================== Option Explicit Public Type TIME_STAMP dwLow As Long 'Lower 32-bits of Time Stamp Register value dwHigh As Long 'Upper 32-bits of Time Stamp Register value End TypePublic Type DLL_VER Minor As String 'Minor Version Major As String 'Major Version End TypePrivate Declare Function wincpuidext Lib "CpuInf32.dll" () As Integer Private Declare Function wincpufeatures Lib "CpuInf32.dll" () As Long Private Declare Function winrdtsc Lib "CpuInf32.dll" () As Currency Private Declare Function getdllversion Lib "CpuInf32.dll" () As Integer Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (lpvDest As Any, _ lpvSource As Any, _ ByVal cbCopy As Long)Public Declare Function wincpuidsupport Lib "CpuInf32.dll" () As Integer Public Declare Function wincpuid Lib "CpuInf32.dll" () As Long Public Declare Function cpurawspeed Lib "CpuInf32.dll" () As Long Public Declare Function cpunormspeed Lib "CpuInf32.dll" () As Long Public Declare Function ProcessorCount Lib "CpuInf32.dll" () As LongPrivate Function GetBit(ByVal iValue As Long, ByVal iBitPos As Integer) As Boolean Debug.Assert iBitPos >= 0 And iBitPos
To :sonicdater(发呆呆) 你是不是没看清题目?这也叫“在VB里实现直接到硬件的操作”?? 除非你的“CpuInf32.dll”是用VB写的!如果是的话,把写它的代码贴出来才有意义!!
一个例子 '主 题:在VB中使用嵌入asm和API指针,去它的DECLARE吧!绝对的好消息。高手请进。 '作 者: thriller '所属论坛: Visual Basic '问题点数:0 '回复次数:0 '发表时间:2001-2-1 22:42:00 ' '看看下面的代码。 '在VB中使用嵌入asm和API指针,去它的DECLARE吧! '在DELPHI和VC中可以做到的,VB一样可以了。虽然稍微麻烦,但的确有效。 '还有什么是VB不能做的?! '好东西不敢独享,大家LOOK:'form Private Declare Function GetDC& Lib "user32" (ByVal hwnd As Long) Private Declare Function ReleaseDC& Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long)Private Sub Command1_Click() Dim a As Long, b As Long Dim s() As Byte, x As Long, y As Long s = StrConv("Hello !", vbFromUnicode) b = 15 x = CallApiByName("user32", "SetWindowTextA", hwnd, VarPtr(s(0))) Debug.Print "x= ", x x = CallApiByName("kernel32", "RtlMoveMemory", VarPtr(a), VarPtr(b), 4&) Debug.Print "a= ", a x = CallApiByName("user32", "FlashWindow", hwnd, 1&) Debug.Print "x= ", x dc1 = GetDC(hwnd) x = CallApiByName("user32", "GetDC", hwnd) Debug.Print "x= ", x, "dc= ", dc1 x = ReleaseDC(hwnd, dc1) End Sub'basOption Explicit '*********************************************** '* This module use excelent solution from '* http://www.vbdotcom.com/FreeCode.htm '* how to implement assembly calls directly '* into VB code. '*********************************************** Private Declare Function LoadLibrary Lib "Kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long Private Declare Function GetProcAddress Lib "Kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function FreeLibrary Lib "Kernel32" (ByVal hLibModule As Long) As Long Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal cBytes As Long) Private mlngParameters() As Long 'list of parameters Private mlngAddress As Long 'address of function to call Private mbytCode() As Byte 'buffer for assembly code Private mlngCP As Long 'used to keep track of latest byte added to codePublic Function CallApiByName(libName As String, funcName As String, ParamArray FuncParams()) As Long Dim lb As Long, i As Integer ReDim mlngParameters(0) ReDim mbytCode(0) mlngAddress = 0 lb = LoadLibrary(ByVal libName) If lb = 0 Then MsgBox "DLL not found", vbCritical Exit Function End If mlngAddress = GetProcAddress(lb, ByVal funcName) If mlngAddress = 0 Then MsgBox "Function entry not found", vbCritical FreeLibrary lb Exit Function End If ReDim mlngParameters(UBound(FuncParams) + 1) For i = 1 To UBound(mlngParameters) mlngParameters(i) = CLng(FuncParams(i - 1)) Next i CallApiByName = CallWindowProc(PrepareCode, 0, 0, 0, 0) FreeLibrary lb End FunctionPrivate Function PrepareCode() As Long Dim lngX As Long, codeStart As Long ReDim mbytCode(18 + 32 + 6 * UBound(mlngParameters)) codeStart = GetAlignedCodeStart(VarPtr(mbytCode(0))) mlngCP = codeStart - VarPtr(mbytCode(0)) For lngX = 0 To mlngCP - 1 mbytCode(lngX) = &HCC Next AddByteToCode &H58 'pop eax AddByteToCode &H59 'pop ecx AddByteToCode &H59 'pop ecx AddByteToCode &H59 'pop ecx AddByteToCode &H59 'pop ecx AddByteToCode &H50 'push eax For lngX = UBound(mlngParameters) To 1 Step -1 AddByteToCode &H68 'push wwxxyyzz AddLongToCode mlngParameters(lngX) Next AddCallToCode mlngAddress AddByteToCode &HC3 AddByteToCode &HCC PrepareCode = codeStart End FunctionPrivate Sub AddCallToCode(lngAddress As Long) AddByteToCode &HE8 AddLongToCode lngAddress - VarPtr(mbytCode(mlngCP)) - 4 End SubPrivate Sub AddLongToCode(lng As Long) Dim intX As Integer Dim byt(3) As Byte CopyMemory byt(0), lng, 4 For intX = 0 To 3 AddByteToCode byt(intX) Next End SubPrivate Sub AddByteToCode(byt As Byte) mbytCode(mlngCP) = byt mlngCP = mlngCP + 1 End SubPrivate Function GetAlignedCodeStart(lngAddress As Long) As Long GetAlignedCodeStart = lngAddress + (15 - (lngAddress - 1) Mod 16) If (15 - (lngAddress - 1) Mod 16) = 0 Then GetAlignedCodeStart = GetAlignedCodeStart + 16 End Function
如何内嵌
风:,你一定是用VC吧,我想用的方法,其实,也在VC里的学的。不过,还不熟,
从概念上讲,VB也支持(一定支持)。那样的操作,如:CO(),所以我觉得MS提供了大部分的东西,但大部分人,没有使用。因为,大部分高手,都到VC或其它工具里去写这些东西了。
我不是用VC的哟:)
我是用BCB的
强烈推荐用BCB或DELPHI!!!:)
http://www.china-askpro.com/msg46/qa49.shtml
http://www.china-askpro.com/msg27/qa86.shtml
==========================================================
form 部分,添加2 Buttons:
==========================================================
Private Sub cmdCallFunc_Click(Index As Integer)
Select Case Index
Case 0
lblFuncRet(Index) = CBool(wincpuidsupport())
Case 1
lblFuncRet(Index) = ProcessorCount()
Case 2
Me.MousePointer = vbHourglass
lblFuncRet(Index) = cpunormspeed()
Me.MousePointer = vbDefault
Case 3
Me.MousePointer = vbHourglass
lblFuncRet(Index) = cpurawspeed()
Me.MousePointer = vbDefault
Case 4
lblFuncRet(Index) = GetCPUDescription()
Case 5
lblFuncRet(Index) = GetCPUDescriptionString(Verbose:=CBool(chkVerbose.Value))
Case 6
lblFuncRet(Index) = GetCPUModel()
Case 7
lblFuncRet(Index) = GetCPUType()
Case 8
lblFuncRet(Index) = wincpuid()
Case 9
lblFuncRet(Index) = CPUHasMMX()
Case 10
lblFuncRet(Index) = CPUHasFPU()
Case 11
lblFuncRet(Index) = CPUHasTimeStampCounter()
Case 12
Dim vs As DLL_VER
Call GetDllVerString(vs)
lblFuncRet(Index) = vs.Major & "." & vs.Minor
End Select
End SubPrivate Sub cmdTimeStamp_Click()
Dim ts As TIME_STAMP
Dim Output As String
Dim i As LongIf GetTimeStampCode(ts) Then
Output = Hex$(ts.dwHigh)
Output = Output & " : " & Hex$(ts.dwLow)
Call lstTimeStamp.AddItem(Output)
Else
MsgBox "CPU does not have timestamp register"
End If
End Sub
===============================================================
.bas 部分:
===============================================================
Option Explicit
Public Type TIME_STAMP
dwLow As Long 'Lower 32-bits of Time Stamp Register value
dwHigh As Long 'Upper 32-bits of Time Stamp Register value
End TypePublic Type DLL_VER
Minor As String 'Minor Version
Major As String 'Major Version
End TypePrivate Declare Function wincpuidext Lib "CpuInf32.dll" () As Integer
Private Declare Function wincpufeatures Lib "CpuInf32.dll" () As Long
Private Declare Function winrdtsc Lib "CpuInf32.dll" () As Currency
Private Declare Function getdllversion Lib "CpuInf32.dll" () As Integer
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(lpvDest As Any, _
lpvSource As Any, _
ByVal cbCopy As Long)Public Declare Function wincpuidsupport Lib "CpuInf32.dll" () As Integer
Public Declare Function wincpuid Lib "CpuInf32.dll" () As Long
Public Declare Function cpurawspeed Lib "CpuInf32.dll" () As Long
Public Declare Function cpunormspeed Lib "CpuInf32.dll" () As Long
Public Declare Function ProcessorCount Lib "CpuInf32.dll" () As LongPrivate Function GetBit(ByVal iValue As Long, ByVal iBitPos As Integer) As Boolean
Debug.Assert iBitPos >= 0 And iBitPos
除非你的“CpuInf32.dll”是用VB写的!如果是的话,把写它的代码贴出来才有意义!!
http://www.csdn.net/expert/topic/710/710370.xml?
'主 题:在VB中使用嵌入asm和API指针,去它的DECLARE吧!绝对的好消息。高手请进。
'作 者: thriller
'所属论坛: Visual Basic
'问题点数:0
'回复次数:0
'发表时间:2001-2-1 22:42:00
'
'看看下面的代码。
'在VB中使用嵌入asm和API指针,去它的DECLARE吧!
'在DELPHI和VC中可以做到的,VB一样可以了。虽然稍微麻烦,但的确有效。
'还有什么是VB不能做的?!
'好东西不敢独享,大家LOOK:'form
Private Declare Function GetDC& Lib "user32" (ByVal hwnd As Long)
Private Declare Function ReleaseDC& Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long)Private Sub Command1_Click()
Dim a As Long, b As Long
Dim s() As Byte, x As Long, y As Long
s = StrConv("Hello !", vbFromUnicode)
b = 15
x = CallApiByName("user32", "SetWindowTextA", hwnd, VarPtr(s(0)))
Debug.Print "x= ", x
x = CallApiByName("kernel32", "RtlMoveMemory", VarPtr(a), VarPtr(b), 4&)
Debug.Print "a= ", a
x = CallApiByName("user32", "FlashWindow", hwnd, 1&)
Debug.Print "x= ", x
dc1 = GetDC(hwnd)
x = CallApiByName("user32", "GetDC", hwnd)
Debug.Print "x= ", x, "dc= ", dc1
x = ReleaseDC(hwnd, dc1)
End Sub'basOption Explicit
'***********************************************
'* This module use excelent solution from
'* http://www.vbdotcom.com/FreeCode.htm
'* how to implement assembly calls directly
'* into VB code.
'***********************************************
Private Declare Function LoadLibrary Lib "Kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "Kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FreeLibrary Lib "Kernel32" (ByVal hLibModule As Long) As Long
Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (lpDest As Any, lpSource As Any, ByVal cBytes As Long)
Private mlngParameters() As Long 'list of parameters
Private mlngAddress As Long 'address of function to call
Private mbytCode() As Byte 'buffer for assembly code
Private mlngCP As Long 'used to keep track of latest byte added to codePublic Function CallApiByName(libName As String, funcName As String, ParamArray FuncParams()) As Long
Dim lb As Long, i As Integer
ReDim mlngParameters(0)
ReDim mbytCode(0)
mlngAddress = 0
lb = LoadLibrary(ByVal libName)
If lb = 0 Then
MsgBox "DLL not found", vbCritical
Exit Function
End If
mlngAddress = GetProcAddress(lb, ByVal funcName)
If mlngAddress = 0 Then
MsgBox "Function entry not found", vbCritical
FreeLibrary lb
Exit Function
End If
ReDim mlngParameters(UBound(FuncParams) + 1)
For i = 1 To UBound(mlngParameters)
mlngParameters(i) = CLng(FuncParams(i - 1))
Next i
CallApiByName = CallWindowProc(PrepareCode, 0, 0, 0, 0)
FreeLibrary lb
End FunctionPrivate Function PrepareCode() As Long
Dim lngX As Long, codeStart As Long
ReDim mbytCode(18 + 32 + 6 * UBound(mlngParameters))
codeStart = GetAlignedCodeStart(VarPtr(mbytCode(0)))
mlngCP = codeStart - VarPtr(mbytCode(0))
For lngX = 0 To mlngCP - 1
mbytCode(lngX) = &HCC
Next
AddByteToCode &H58 'pop eax
AddByteToCode &H59 'pop ecx
AddByteToCode &H59 'pop ecx
AddByteToCode &H59 'pop ecx
AddByteToCode &H59 'pop ecx
AddByteToCode &H50 'push eax
For lngX = UBound(mlngParameters) To 1 Step -1
AddByteToCode &H68 'push wwxxyyzz
AddLongToCode mlngParameters(lngX)
Next
AddCallToCode mlngAddress
AddByteToCode &HC3
AddByteToCode &HCC
PrepareCode = codeStart
End FunctionPrivate Sub AddCallToCode(lngAddress As Long)
AddByteToCode &HE8
AddLongToCode lngAddress - VarPtr(mbytCode(mlngCP)) - 4
End SubPrivate Sub AddLongToCode(lng As Long)
Dim intX As Integer
Dim byt(3) As Byte
CopyMemory byt(0), lng, 4
For intX = 0 To 3
AddByteToCode byt(intX)
Next
End SubPrivate Sub AddByteToCode(byt As Byte)
mbytCode(mlngCP) = byt
mlngCP = mlngCP + 1
End SubPrivate Function GetAlignedCodeStart(lngAddress As Long) As Long
GetAlignedCodeStart = lngAddress + (15 - (lngAddress - 1) Mod 16)
If (15 - (lngAddress - 1) Mod 16) = 0 Then GetAlignedCodeStart = GetAlignedCodeStart + 16
End Function
我认为可以使用C++等类型语言写成.DLL便于使用。
还有就是看你用VB对硬件编成的类型某些可以直接使用API
还有写可以仿真成文件方式,总之对应不同的硬件最好使用不同的方法也不能使用通用不变的习惯
事实上
在对硬件的控制程序
用c或者汇编写dll文件是非常好的想法
用VB去做
往往会发觉那是在浪费时间