'嘿,够简单吧!下面是动态调用MessageBoxA的源代码,上面的步骤被封装到RunDll32函数中,可放到模块(CallAPIbyName.bas)中:
Dim s1() As Byte
Dim
s2() As Byte
Dim
ret As Long
Dim
hProc As Long
Dim
hModule As Long
Sub
t2()
Const hWnd = 0
s1 = StrConv("Hello~World", vbFromUnicode)
s2 = StrConv(
"VBNote", vbFromUnicode)
ret = RunDll32(
"user32", "MessageBoxA", hWnd, VarPtr(s1(0)), VarPtr(s2(0)), 0 &)
End Sub
Public Function
RunDll32(LibFileName As String, ProcName As String, ParamArray Params()) As Long
ReDim
m_OpCode(400 + 6 * UBound(Params)) '保留用来写m_OpCode
'读取API库
hModule = LoadLibrary(ByVal LibFileName)
If hModule = 0 Then
MsgBox "Library读取失败!"
Exit Function
End If
'取得函数地址
hProc = GetProcAddress(hModule, ByVal ProcName)
If hProc = 0 Then
MsgBox "函数读取失败!", vbCritical
FreeLibrary hModule
Exit Function
End If
'执行Assembly Code部分
RunDll32 = CallWindowProc(GetCodeStart(hProc, Params), 0, 1, 2, 3)
FreeLibrary hModule
'释放空间
End Function


 
目前有0条回应
Comment
Trackback
你目前的身份是游客,请输入昵称和电邮!