End Sub
------------------------------end---------------------------------
下面是modu1e.bas的源代码
----------------------module1.bas的源文件--------------------------
Option Explicit
注释:
注释:This shows how to incorporate machine code into VB
注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:注释:
注释:The example fills the array with a few machine instructions and then copies
注释:them to a procedure address. The modified procedure is then called thru
注释:CallWindowProc. The result of this specific machine code is your CPU Vendor Name.
注释:
注释:##########################################################################
注释:Apparently it gets a Stack Pointer Error, but I don注释:t know why; if anybody
注释:can fix that please let me know... UMGEDV@AOL.COM
注释:The Error is not present in the native compiled version; so I think it got
注释:something to do with the P-Code Calling Convention (strange though)...
注释:##########################################################################
注释:
注释:Sub Dummy serves to reserve some space to copy the machine instructions into.
注释:
注释:
注释:Tested on Intel and AMD CPU注释:s (uncompiled and compiled)
注释:
注释:
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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private x As Long
Public Function GetCpuName() As String
Dim MachineCode(0 To 35) As Byte
Dim VarAddr As Long
Dim FunctAddr As Long
Dim EAX As Long
Dim CPUName(1 To 12) As Byte
MachineCode(32) = &HC2 注释:ret 16 I tried everything from 0 to 24
MachineCode(33) = &H10 注释: but all produce the stack error
MachineCode(34) = &H0
注释:tell cpuid what we want
EAX = 0
注释:get address of Machine Code
VarAddr = VarPtr(MachineCode(0))
注释:get address of Sub Dummy
FunctAddr = GetAddress(AddressOf Dummy)
注释:copy the Machine Code to where it can be called
CopyMemory ByVal FunctAddr, ByVal VarAddr, 35 注释:35 bytes machine code
注释:call it
On Error Resume Next 注释:apparently it gets a stack pointer error when in P-Code but i dont know why
CallWindowProc FunctAddr, EAX, VarPtr(CPUName(1)), VarPtr(CPUName(9)), VarPtr(CPUName(5))
注释:Debug.Print Err; Err.Description
注释:MsgBox Err & Err.Description
On Error GoTo 0
用shell命令去执行com,exe,不知道怎么调用汇编与C,Delphi可以执行汇编,不知道VB行不行.
下面的代码可以让程序在shell时停下来,待shell命令执行后才继续.
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Function ShellForWait(sAppName As String, Optional ByVal lShowWindow As VbAppWinStyle = vbMinimizedFocus, Optional ByVal lWaitTime As Long = 0) As Boolean
Dim lID As Long, lHnd As Long, lRet As Long
On Error Resume Next
lID = Shell(sAppName, lShowWindow)
If lID > 0 Then
lHnd = OpenProcess(SYNCHRONIZE, 0, lID)
If lHnd <> 0 Then
Do
lRet = WaitForSingleObject(lHnd, lWaitTime)
DoEvents
Loop While lRet = WAIT_TIMEOUT
CloseHandle lHnd
ShellForWait = True
Else
ShellForWait = False
End If
Else
ShellForWait = False
End If
End Function
Private Sub Command1_Click()
ShellForWait "cmd.exe ", , &HFFFF
MsgBox ""
End Sub