1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <windows.h>
void main()
{
HMODULE hMod=LoadLibrary("user32.dll");
/////////////fisr method to invoke Api//////////////////////////
int (__stdcall *MsgBox1)(HWND ,LPSTR,LPSTR,int);
(FARPROC&)MsgBox1=GetProcAddress(hMod,"MessageBoxA");
/////////////second method to invoke Api//////////////////////////
typedef int (__stdcall *MSGBOX)(HWND ,LPSTR ,LPSTR ,INT);
MSGBOX MsgBox2=(MSGBOX)GetProcAddress(hMod,"MessageBoxA");
MsgBox1(NULL,"first method succeed!\n\n"
"1、int (__stdcall *MsgBox)(HWND ,LPSTR,LPSTR,int);\n"
"2、(FARPROC&)MsgBox=GetProcAddress(hMod,\"MessageBoxA\");\n"
"3、MsgBox(Null,\"hello,I love you\",\"Caption\",0);",
"Invoke by function, Method 1:",0);
MsgBox2(NULL,"second method succeed!\n\n"
"1、typedef int (__stdcall *MSGBOX)(HWND ,LPSTR ,LPSTR ,INT);\n"
"2、MSGBOX MsgBox2=(MSGBOX)GetProcAddress(hMod,\"MessageBoxA\");\n"
"3、MsgBox2(Null,\"hello,I love you\",\"Caption\",0);",
"Invoke by function pointer, Method 2:",0);
return;
}
| |