函数指针动态调用dll中的函数

转载自:http://blog.csdn.net/hzhxxx/article/details/821089

/******************************************************************/
///name       : GetKey
//function    : 校验密码
//access      : public
//para        :
//         1. : const std::string &strdata
//            : 参与密码校验的值
//return      : 校验后值
//author      : hzh
//date        : 2005-04-21
/*******************************************************************/
const std::string GetKey(const std::string &strdata)

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

 //动态加载 dll,并调用里面的 函数
 HINSTANCE DllInst = LoadLibrary("codekey.dll" );
 if( DllInst == NULL )
 {
  throw std::exception( "无法引导动态库 codekey.dll" );
 }
 
 //函数指针 CodeKey,保证和 dll 中需要调用的函数申明一致
 char * ( __stdcall * CodeKey)(const char *) = NULL;
 try
 {
  //指向 dll 中函数地址
  CodeKey = (char* ( __stdcall* )(const char * ))
   GetProcAddress(DllInst,"CodeKey");
  if(CodeKey)
  {
   //函数指针调用 dll 函数
   result = CodeKey(strdata.c_str());
  }
  else
  {
   throw std::exception("编译密码出错");
  }
 }
 catch( ... )
 {
  throw std::exception( "调用动态库codekey.dll出错!" );
 }
 //释放库
 FreeLibrary(DllInst);

 return result;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值