Salut, les fonctions du module ne sont pas de moi, tout le credit va donc à son auteur, l'url de l'original est dans le code.
Par contre je trouve ça vraiment tres sympa, donc j'ai concrétisé la chose avec un exemple ARCHI SIMPLE de son utilisation et je le poste ici, j'avais déja vu des demandes, et j'avais également lu des posts disant que ce n'était pas possible.
Bref vous avez une form, un appel d'api, mais .... vous ne déclarez pas l'API !
Source / Exemple :
Option Explicit
'original source: http://nienie.com/~masapico/doc_FuncPtr.html
Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Public Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As Long
Private Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal Flags As Long, ByVal Size As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal Mem As Long) As Long
Private Declare Function MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Dest As Any, ByRef Src As Any, ByVal Size As Long) As Long
Private Const GMEM_FIXED As Long = 0&
Public Function CallFuncPtr(FuncPtr As Long, ParamArray Params() As Variant) As Variant
Const MAX_CODESIZE As Long = 65536
Dim I As Long
Dim pCodeData As Long
Dim pParamData() As Long
Dim PC As Long
Dim Operand As Long
Dim RetValue As Long
Dim StrValue As String
Dim LongValue As Long
Dim dwThreadID As Long
Dim hThread As Long
Dim dwExit As Long
ReDim pParamData(UBound(Params)) As Long
pCodeData = GlobalAlloc(GMEM_FIXED, MAX_CODESIZE)
PC = pCodeData
AddByte PC, &H55
For I = UBound(Params) To 0 Step -1
If VarType(Params(I)) = vbString Then
pParamData(I) = GlobalAlloc(GMEM_FIXED, LenB(Params(I)))
StrValue = Params(I)
MoveMemory ByVal pParamData(I), ByVal StrValue, LenB(StrValue)
Operand = pParamData(I)
Else
Operand = Params(I)
End If
AddByte PC, &H68
AddLong PC, Operand
Next
AddByte PC, &HB8
AddLong PC, FuncPtr
AddInt PC, &HD0FF
AddByte PC, &HBA
AddLong PC, VarPtr(RetValue)
AddInt PC, &H289
AddByte PC, &H5D
AddInt PC, &HC033
AddByte PC, &HC2
AddInt PC, &H8
' run the assembler code in a new thread
hThread = CreateThread(0, 0, pCodeData, 0, 0, dwThreadID)
Do
' if exit code is 256 the thread is
' still running
GetExitCodeThread hThread, dwExit
If dwExit <> 259 Then Exit Do
DoEvents
Loop
GlobalFree pCodeData
Conclusion :
Encore bravo à l'auteur original du module, j'en veux encore !
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.