VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Call Api by Name

by Scythe (20 Submissions)
Category: Libraries
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Call an api by its name without Declare. Usefull for Sripts or if u dont know if the Machine is XP or 95...

Rate Call Api by Name

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 Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Sub Form_Load()
 Dim Libary As Long
 Dim PrcAdress As Long
 On Error GoTo NoApi
 'Load the Libary
 Libary = LoadLibrary("user32")
 'Find the procedure we want
 Procadress = GetProcAddress(Libary, "MessageBoxA")
 'Call the Api
 CallWindowProc Procadress, Me.hWnd, "My Message", "Api without Declare", &H0&
 'Unload the libary
 FreeLibrary Libary
NoApi:
End Sub

Download this snippet    Add to My Saved Code

Call Api by Name Comments

No comments have been posted about Call Api by Name. Why not be the first to post a comment about Call Api by Name.

Post your comment

Subject:
Message:
0/1000 characters