//'*********************************************************************** //' DISPLAYED WITH PERMISSION OF ROY SCOTT ENTERPRISES //' AND THE AUTHOR AS AN ARCHIVING FUNCTION //' http://www.scottserver.net/forum/index.php //' ALL RIGHTS RESERVED //'************************************************************************ // MINOR EDITING PERFORMED BY UPLA STAFF //'************************************************************************ //Gerome //Microdeveloper //Dynamic API :: the ultimate code ! //-------------------------------------------------------------------------------- //Hello, //This code is issued from Me & Mike LOBANOVSKY and works under MSVC++ & LCC Win32 but coded in //pure C + little ASM : //Enjoy and take care //!!!!!!!!!!!! POWER !!!!!!!!!!!! //If you appreciate this sample code, please register to FBSL //Code: /* CallDllFx("Sleep","kernel32",1, 1000); CallDllFx("SleepEx","kernel32",2, 2000, 1); CallDllFx("WritePrivateProfileString","kernel32", 4, "Section1", "SecondKey", "By golly, it works.", "c:\\appname.ini"); */ int WINAPI CallDllFx (char *FuncName, char *DllName, int nArgs, ...) { HINSTANCE hInst = 0; FARPROC lpAddr = 0; int arg = 0; int result = 0; char buff[128] = {'\0'}; va_list ap; int argtable[128]; //[nArgs]; // in LCC WIN32 because of the Dynamic Support ! memset( &argtable, 0, sizeof(argtable) ); hInst=GetModuleHandle(DllName); if(hInst==NULL) { hInst=LoadLibrary(DllName); } else { DBS( "(0)Library '%s' already loaded !", DllName ); } lpAddr=(FARPROC)GetProcAddress(hInst,FuncName); if(lpAddr==NULL) { sprintf(buff,"%s%s",FuncName,"A"); lpAddr=(FARPROC)GetProcAddress(hInst,buff); } if(lpAddr==NULL) { sprintf(buff,"%s%s","_",FuncName); lpAddr=(FARPROC)GetProcAddress(hInst,buff); } if (lpAddr) { va_start(ap,nArgs); for (register int i=0; i=0; ii--) { arg = argtable[ii]; // _asm("pushl %arg") // in LCC WIN32 __asm push arg // in MSVC++ } va_end( ap ); __try { result = lpAddr(); } __except ( EXCEPTION_EXECUTE_HANDLER ) { if (hInst) FreeLibrary(hInst); return -1; } } if(hInst) FreeLibrary(hInst); return result; }