Dynamically calling functions in a DLL through function pointers

Source: Internet
Author: User

/******************************************************************/
///name       : Getkey
//function   : Verify password
//access     : public
/ /para       :
//         1.: const std::string &strdata
//           : value to participate in Password checksum
// return     : Checksum value
//author     : Hzh
//date        : 2005-04-21
/**************************************************************** /
Const std::string getkey (const std::string &strdata)

 std::string result = "";
 if (strdata = = "")
 {
  return result;
 .}

Dynamically load the DLL and call the inside function
HInstance Dllinst = LoadLibrary ("Codekey.dll");
if (Dllinst = NULL)
{
Throw Std::exception ("Unable to boot dynamic library Codekey.dll");
}

function pointer Codekey to ensure consistency with functions that need to be called in the DLL
char * (__stdcall * codekey) (const char *) = NULL;
Try
{
Point to function address in DLL
Codekey = (char* (__stdcall*) (const char *))
GetProcAddress (Dllinst, "Codekey");
if (Codekey)
{
function pointers Call DLL functions
result = Codekey (Strdata.c_str ());
}
Else
{
Throw std::exception ("Compile password error");
}
}
catch (...)
{
Throw std::exception ("error calling Dynamic library Codekey.dll.") " );
}
Release Library
FreeLibrary (Dllinst);

return result;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.