From: James Y. <cy...@gm...> - 2007-11-13 12:47:02
|
Say this is my code: #include <stdio.h> > #include <windows.h> > > typedef int (__cdecl *MYPROC)(LPWSTR); > > int main( > int argc, > char *argv[] > ) { > HMODULE hModule; > MYPROC SendInput; > > if (!(hModule = LoadLibrary("user32.dll"))) { > puts("user32.dll not loaded."); > } > if (SendInput = (MYPROC)GetProcAddress(hModule, "SendInput")) { > puts("SendInput is not found."); > } > > return (0); > } > "SendInput is not found" is always shown in my console... I know SendInput is in user32.dll, but I just cannot get it with GetProcAddress()! What I got from "objdump -T user32.dll" is: > .... > [Ordinal/Name Pointer] Table > .... > [ 570] SendInput > .... > Any help is appreciated. -- This is a UTF-8 formatted mail ----------------------------------------------- James C.-C.Yu |
From: Brian D. <br...@de...> - 2007-11-13 17:47:03
|
James Yu wrote: > typedef int (__cdecl *MYPROC)(LPWSTR); This is very wrong. Win32 API functions are type WINAPI (i.e. stdcall) not cdecl. It is quite likely that you will crash or otherwise suffer very strange behavior due to a broken stack if you try to call a function through a pointer declared with the wrong calling convention. > if (SendInput = (MYPROC)GetProcAddress(hModule, > "SendInput")) { > puts("SendInput is not found."); > } This does not make sense, as the body of the 'if' is executed when the return value is nonzero, as would be the case when it succeeds. Brian |