0/5 (8 avis)
Vue 5 319 fois - Téléchargée 636 fois
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
5 avril 2006 à 19:45
Ce n'est pas une déclaration d'api ?
5 avril 2006 à 20:26
5 avril 2006 à 21:20
1 - Fonctions bcp trop contraignante
2 - Probleme lié au thread (pile et proté des variables)
de plus pourquoi utiliser des pseudo instruction assembleur avec des api alors qu'un tout assembleur aurrait suffit
Bref c'est bien mais comme je dit souvent c'est bcp pour pas grand chose. Ce type de code ne servira que si on ne sais pas quel fonction appeler donc peux etre pour faire un plug in ?! mais dans ce cas on utilise le mecanisme COM qui est natif dans vb.
@+
5 avril 2006 à 21:21
beurk la c'est la cata ! :p
@+
5 avril 2006 à 22:12
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.