当前位置:首页 » 多媒体相关

如何调用dll?在线等待!!!


我是刚学编写dll的,下面的一段程序不知出错在那?多谢指教!!!  
  #include   <math.h>  
  #include   <string.h>  
  void   main(void)  
  {  
  typedef   int(*pmax)(int   a,int   b);  
  typedef   int(*pmin)(int   a,int   b);  
  hinstance   hdll;  
  pmax   max  
  hdll=loadlibrary("mydll.dll");//加载动态链接库mydll.dll文件;  
  max=(pmax)getprocaddress(hdll,"max");  
  a=max(5,8);  
  cout<<"a="<<a<<endl;  
  freelibrary(hdll);//卸载mydll.dll文件;  
  }    
  再有就是这两个头文件是否正确?谢谢

推荐阅读

  • 文件扩展名导致的安全问题 [详细内容]
  • 合作传闻证实 Sun英特尔达成战略同盟 服务器存储频道 [详细内容]
  • 4核Clovertown!Sun与Intel合作细节 服务器存储频道 [详细内容]
  • windows文件扩展名确认的漏洞 [详细内容]
  • E-100A的F1使用心得 [详细内容]
  • 授权费太高,印政府拟向微软关上大门 服务器存储频道 [详细内容]
  • VFP9.0中设计与使用表单和报表 [详细内容]
  • 网友回答:
    网友:antijpn

    string.h是已经被c++标准抛弃的头文件,有的编译系统里面可能保留了这个头文件,而像vc++.net   2003已经彻底丢弃了这个头文件  
      使用的时候应该使用#include   <string>,这样使用的就是c++标准库里面的string  
      math.h是c里面提供的数学函数库,这个是正确的  
       
      dll的调用好像是正确的

    网友:micropentium6

    cout<<"a="<<a<<endl;  
      你使用了<iostream>库吗?暴露了std名空间吗?  
      hdll=loadlibrary("mydll.dll");  
      你的loadlibrary()的第二个参数呢?你需要指明你调用的dll中的函数名

    网友:test7979

    i   服了   u,    
       
      一段代码竟然有嘎许多错  
       
      #include   <windows.h>  
      #include   <iostream>  
       
      using   namespace   std;  
       
      typedef   int(*pmax)(int   a,int   b);  
      typedef   int(*pmin)(int   a,int   b);  
       
      void   main(void)  
      {  
      hinstance   hdll;  
      pmax   max;  
      int   a;  
      hdll=loadlibrary("mydll.dll");//加载动态链接库mydll.dll文件;  
      max=(pmax)getprocaddress(hdll,"max");  
      a=(*max)(5,8);  
      cout<<   "a="   <<   a   <<   endl;  
      freelibrary(hdll);//  
      }  
     

    .

    讨论区

    Login