Dynamically call the function in the DLL through the function pointer

xiaoxiao2021-04-05  262

/ ************************************************** ***************** //// Name: getKey // function: Check password // access: public // Para: // 1. Const std :: string & strdata //: Participate in password verification // return: check value // author: hzh // Date: 2005-04-21 / **************** *********************************************************** / const st: string getKey (const st: :: string ") {std :: string results ="; if (strdata == ") {Return Result;}

// Dynamically load the DLL, and call the function in it hinstance dllinst = loadLibrary ("codekey.dll"); if (dllinst == null) {throw std :: exception ("Unable to guide dynamic library codekey.dll");} / / Function pointer codekey, guarantee and DLL need to be called to declare unanimous char * (__stdcall * codekey) (const char *) = null; try {// pointing to function addresses in DLL codeKey = (char * (__stdcall *) (Const CHAR *)) GetProcaddress (Dllinst, "CodeKey"); if (codekey) {// function pointer call DLL function Result = codekey (strdata.c_str ());} else {throw std :: exception ("Compilation Password error" );}} Catch (...) {throw std :: exception ("call dynamic library codekey.dll error!");} // Release library Freelibrary (DLLINS);

Return Result;}

转载请注明原文地址:https://www.9cbs.com/read-132213.html

New Post(0)