VB可以用Declare聲明來調用標准DLL的外部函數
對我這樣的菜鳥還有點深奧
以上兩步得到了預加載函數的指針
實現以上功能的主要程序
LibAddr = LoadLibrary(ByVal
ProcAddr = GetProcAddress(LibAddr
push uType
push lpCaption
push lpText
push hWnd
call ProcAddr
FreeLibrary LibAddr
嘿源碼天空
Dim s
Dim ret As Long
s
s
ret = RunDll
CallAPIbyName
Option Explicit
Private Declare Function LoadLibrary Lib
Private Declare Function GetProcAddress Lib
Private Declare Function CallWindowProc Lib
Private Declare Function FreeLibrary Lib
Private Declare Sub CopyMemory Lib
Public m_opIndex As Long
Private m_OpCode() As Byte
Public Function RunDll
Dim hProc As Long
Dim hModule As Long
ReDim m_OpCode(
hModule = LoadLibrary(ByVal LibFileName)
If hModule =
MsgBox
Exit Function
End If
hProc = GetProcAddress(hModule
If hProc =
MsgBox
FreeLibrary hModule
Exit Function
End If
RunDll
FreeLibrary hModule
End Function
Private Function GetCodeStart(ByVal lngProc As Long
Dim lngIndex As Long
lngCodeStart = (VarPtr(m_OpCode(
m_opIndex = lngCodeStart
For lngIndex =
m_OpCode(lngIndex) = &HCC
Next lngIndex
For lngIndex = UBound(arrParams) To
AddByteToCode &H
AddLongToCode CLng(arrParams(lngIndex))
Next lngIndex
AddByteToCode &HE
AddLongToCode lngProc
AddByteToCode &HC
AddByteToCode &H
AddByteToCode &H
GetCodeStart = lngCodeStart
End Function
Private Sub AddLongToCode(lData As Long)
CopyMemory m_OpCode(m_opIndex)
m_opIndex = m_opIndex +
End Sub
Private Sub AddIntToCode(iData As Byte)
CopyMemory m_OpCode(m_opIndex)
m_opIndex = m_opIndex +
End Sub
Private Sub AddByteToCode(bData As Byte)
m_OpCode(m_opIndex) = bData
m_opIndex = m_opIndex +
End Sub
From:http://tw.wingwit.com/Article/program/net/201311/13062.html