c++ - Explicit DLL function calling any function -
i'm trying make experimental interpreted language based on tutorial http://compilers.iecc.com/crenshaw/ in c++. want implement system calling dll
functions @ runtime, i'm trying use explicit linking in c++. type of data , amount of arguments undefined, depends of code processed interpreter, tried use variadic function(because unknown amount of arguments) , void pointers(because unknown type of parameter) still don't works.
the below code test later implemented in project:
typedef void* (winapi *_dllproc)(...); // it's variadic because parameters undefined // tried using variadic (like this) // void* calldllfunction(lpcwstr dllname, lpcstr funcname, int numargs, ...) void* calldllfunctiona(lpcwstr dllname, lpcstr funcname, void* val1, void* val2, void* val3, void* val4) { //va_list ap; // tried use variadic // hinstance hinstlib = loadlibrary(dllname); void* retval; _dllproc func = (_dllproc)getprocaddress(hinstlib, funcname); // //va_start(ap, numargs); if (hinstlib != null) { try { retval = (func)(val1, val2, val3, val4); } catch (...) { throw; } } else { cout << "error!" << endl; } //va_end(ap); // freelibrary(hinstlib); // return retval; } int main( void ) { calldllfunctiona(l"user32.dll", "messageboxa", 0, "hello", "title", mb_ok); printf("\n"); system("pause"); return 0; }
the above code show message box:
but displays error message:
probably above error caused because parameters void* wherein correct types (hwnd, lpcstr, lpcstr , uint), values undefined.
so, how can make function call dll function name, type, amount of parameters? possible? how others languages (such python, ruby) during runtime?
Comments
Post a Comment