网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C#怎么调用C++动态链接库

这篇文章主要讲解了“C#怎么调用C++动态链接库”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“C#怎么调用C++动态链接库”吧!

成都创新互联于2013年开始,先为鼓楼等服务建站,鼓楼等地企业,进行企业商务咨询服务。为鼓楼企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

当VC等调用C#写的COM时,用regasm   /tlb生成TLB文件,也可用tlbexp.exe,在VC等中加载TLB文件,当用C#调用VC等写的COM时,用tlbimp.exe,你可以写一个程序调试一下

下面介绍C#调用C++动态链接库方法。

添加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#调用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++写的动态链接库的问题。

感谢各位的阅读,以上就是“C#怎么调用C++动态链接库”的内容了,经过本文的学习后,相信大家对C#怎么调用C++动态链接库这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


当前题目:C#怎么调用C++动态链接库
文章出自:http://bjjierui.cn/article/pdcego.html

其他资讯