{
UINT wDriverIndex
LPSTR lpszName
int cbName
LPSTR lpszVer
int cbVer
}
HMODULE hdll = LoadLibrary("AVICAP32.dll")//加载动态连接配启库
if (hdll)//判断是否加载成功
{
capGetDriverDescriptionT pcapGetDriverDescription =
(capGetDriverDescriptionT)GetProcAddress(hdll,"capGetDriverDescriptionA")//取得函数地址
}
pcapGetDriverDescription()//调用动态连接库
LZ你好用如果命袭轮令来判断的话太繁杂。
或者还友谨有一种取巧的方法——用DLL库来弄。
有一个API是动态调用子程序,那个命令有几个参数,是 库文件名(文本型)、库命令(文本型)。就可以这样动态调用。当然前提是这个窗口界面是那个dll的,这样自己调用自己的命令,以达到LZ你的目的。
比如,按钮1的事件是“_按钮1_被单好禅基击”,调用就是“_动态调用子程序("自身的路径","_" + 编辑框.内容 + "_被单击")”
_________________________________
我的QQ:540726671 -yice 希望可以一起学习交流
'--------模块中---------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 m_opIndex As Long
Private m_OpCode() As BytePublic Function CallApiByName(ByVal libName As String, ProcName As String, ParamArray Params()) As Long
Dim hProc As Long
Dim hModule As Long
ReDim m_OpCode(400 + 6 * UBound(Params))hModule = LoadLibrary(ByVal libName)
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
CallApiByName = CallWindowProc(GetCodeStart(hProc, Params), 0, 1, 2, 3)
FreeLibrary hModule
End FunctionPrivate Function GetCodeStart(ByVal lngProc As Long, ByVal arrParams As Variant) As Long
Dim lngIndex As Long, lngCodeStart As Long
lngCodeStart = (VarPtr(m_OpCode(0)) Or &HF) + 1
m_opIndex = lngCodeStart - VarPtr(m_OpCode(0))
For lngIndex = 0 To m_opIndex - 1
m_OpCode(lngIndex) = &HCC 'int 3
Next lngIndexFor lngIndex = UBound(arrParams) To 0 Step -1
AddByteToCode &H68
AddLongToCode CLng(arrParams(lngIndex))
Next lngIndex
AddByteToCode &HE8
AddLongToCode lngProc - VarPtr(m_OpCode(m_opIndex)) - 4AddByteToCode &HC2
AddByteToCode &H10
AddByteToCode &H0
GetCodeStart = lngCodeStart
End FunctionPrivate Sub AddLongToCode(lData As Long)
CopyMemory m_OpCode(m_opIndex), lData, 4
m_opIndex = m_opIndex + 4
End SubPrivate Sub AddIntToCode(iData As Byte)
CopyMemory m_OpCode(m_opIndex), iData, 2
m_opIndex = m_opIndex + 2
End SubPrivate Sub AddByteToCode(bData As Byte)
m_OpCode(m_opIndex) = bData
m_opIndex = m_opIndex + 1
End Sub
'-----------调用-------------Dim b1() As Byte
Dim b2() As Byte
b1 = StrConv("Open", vbFromUnicode)
b2 = StrConv(" http://www.baidu.com", vbFromUnicode)
CallApiByName "Shell32.dll", "ShellExecuteA", 0, VarPtr(b1(0)), VarPtr(b2(0)), 0, 0, 0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)