Calling a dll function from __asm blocks?
-
Hi I am trying to call a DLL (for testing I use the SetWindowTextA function from User32.dll) Everything seems correct to me...and the program compiles and links fine, except that on executing it, it given an illegal operation. I have checked that SetWindowTextA is in User32.dll, so I guess it should work? Here is the code: #include #define TAILLE_MAX 40 void main() { char *szFuncName = "SetWindowTextA"; char *szDllName = "User32.dll"; HINSTANCE hLibrary; HWND hwnd; char szOldWndTitle[TAILLE_MAX]; char *szNewWndTitle = "Changed Title"; BOOL RetVal; GetConsoleTitle(szOldWndTitle, TAILLE_MAX); hwnd = FindWindow(NULL, szOldWndTitle); __asm { push szDllName call LoadLibrary mov hLibrary, eax push szFuncName push hLibrary call GetProcAddress ;eax recieves function pointer push szNewWndTitle push hwnd call eax mov RetVal, eax push hLibrary call FreeLibrary } } Any ideas what is wrong? Thanks in advance :)