首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视 ┆淘宝手机在线充值 ┆淘宝游戏点卡充值 
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>NET专区>C#语言>C#如何调用C++写的动态链接库?
C#如何调用C++写的动态链接库?
来源: 发布时间:2008-09-28 发布人: 浏览: 人次   字体: [ ]  
     当VC等调用C#写的COM时,用regasm   /tlb生成TLB文件,也可用tlbexp.exe,在VC等中加载TLB文件,当用C#调用VC等写的COM时,用tlbimp.exe,你可以写一个程序调试一下
     添加System.Runtime.InteropServices命名空间
     如是COM就直接用静态函数调用:                  
  public   static   int   GetNum(  
                          int   lFileSeqNo,  
                          string   sExtType,  
                          string   sExtNumber,  
                          string   sFormID,  
                          string   sOperationDate,  
                          string   sSystemRegistDate,  
                          out   int   lCount,  
                          out   int   lErrorType,  
                          out   int   lErrorCode)  
                  {  
                          int   iRet;  
   
                          WOBCom.ObjClass   obj   =   new   WOBCom.ObjClass();  
                           
                          iRet   =   obj.GetNum(  
                                  lFileSeqNo,  
                                  sExtType,  
                                  sExtNumber,  
                                  sFormID,  
                                  sOperationDate,  
                                  sSystemRegistDate,  
                                  out   lCount,  
                                  out   lErrorType,  
                                  out   lErrorCode);  
   
                          return   iRet;  
                  }  
  如不使COM是普通的DLL  
  不能直接用  
  只能在C++中加一个对外的接口:  
  extern   "C"   __declspec(dllexport)   WOExtConRegObj*   OutGetObjConstructor();  
  extern   "C"   __declspec(dllexport)   void   OutGetObjDestructor(WOExtConRegObj*   outGetObj);  
   
  extern   "C"   __declspec(dllexport)   long   SelectDummyRecord(long   *lErrorType,  
        long   *lErrorCode,  
        WOExtConRegObj*   outGetObj);  
  //  
  extern   "C"   __declspec(dllexport)   WOExtConRegObj*   OutGetObjConstructor()  
  {  
          WOExtConRegObj*   outGetObj   =   new   WOExtConRegObj();     
          return   outGetObj;  
  }  
   
  extern   "C"   __declspec(dllexport)   void   OutGetObjDestructor(WOExtConRegObj*   outGetObj)  
  {  
          delete   outGetObj;  
  }  
   
  extern   "C"   __declspec(dllexport)   long   SelectDummyRecord(long   *lErrorType,  
        long   *lErrorCode,  
        WOExtConRegObj*   outGetObj)  
  {  
  return   outGetObj->SelectDummyRecord(lErrorType,  
  lErrorCode);      
  }  
  C#就可直接调用了  
                  [DllImport("XXX.dll", EntryPoint="SelectDummyRecord", ExactSpelling=false, CallingConvention=CallingConvention.Cdecl)]  
                  private   static   extern   int   SelectDummyRecord(out int lErrorType,out int lErrorCode,int outGetObj);  
   
                  ///   <summary>  
                  ///   </summary>  
                  ///   <remarks>  
                  ///   </remarks>                  
                  ///   <param name="lErrorType"></param>  
                  ///   <param name="lErrorCode"></param>  
                  ///   <returns></returns>  
                  public int SelectDummyRecord(out int lErrorType,out int lErrorCode)  
                  {  
                          int   intRtn;  
   
                          intRtn   =   SelectDummyRecord(  
                                  out   lErrorType,  
                                  out   lErrorCode,  
                                  m_OutGetObj);    
                          return   intRtn;  
                  }  

相 关 文 章   发布商链接
·C#语言基础之范型入门示例,附代码说...
·C#最为常用到的排序算法大全
·Dictionary泛型集合操作使用事例
·如何用C#获取IP地址、子网掩码和网关...
·有助快速理解C#委托和事件之间关系的...
·C#调用C++的函数实现串口通信读写操...
·C#生成XML文件代码一例
·利用C#实现获得指定网页的源代码方法
·什么是抽象类?什么是接口?两者有什么...
·C#代码,Delphi和js脚本写的模拟显示...
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·最为经典的C#操作文件的方法...
·有助快速理解C#委托和事件之...
·C#泛型学习笔记总结
·c#语言从dbf数据库提取数据并
·C#编写控制线程的运行和线程...
·怎样在C#中删除只读文件及其...
·C#函数中返回多个值的两种方...
·如何在C#中插入照片到Excel文
·如何在c#中获取事件注册的方...
·C#对timer类的使用操作代码
·什么是泛型?泛型的一些概述
·C#如何从文本文件读取信息并...
·如何在c#中去掉字符串中的回...
·如何使用C#获取IIS服务器版本...
·什么是泛型编程思想?及其简...
热 门 文 章
·C#如何获取文件路径中的文件...
·c#中收发邮件处理代码(POP3,...
·浅谈接口和抽象类的区别,加...
·什么是c#深拷贝与浅拷贝及其...
·C#语言实现创建、删除和移动...
·C#中关于四舍五入函数的讨论...
·c#中的ArrayList属性祥解及其...
·快速进行List排序的通用方法...
·C#对timer类的使用操作代码
·C#如何从文本文件读取信息并...
·C#语言实现从XML文件导出数据...
·用C#编写ActiveX控件代码实例
·如何在c#中去掉字符串中的回...
·String.Split 方法使用及其代...
·C#语言绘制实时曲线图代码实...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .