成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C#調(diào)用C++動態(tài)鏈接庫方法介紹

開發(fā) 后端
本文回答了C#調(diào)用C++動態(tài)鏈接庫的問題。

當VC等調(diào)用C#寫的COM時,用regasm   /tlb生成TLB文件,也可用tlbexp.exe,在VC等中加載TLB文件,當用C#調(diào)用VC等寫的COM時,用tlbimp.exe,你可以寫一個程序調(diào)試一下

下面介紹C#調(diào)用C++動態(tài)鏈接庫方法。

添加System.Runtime.InteropServices命名空間

如是COM就直接用靜態(tài)函數(shù)調(diào)用:                  

  1. public   static   int   GetNum(     
  2.                           int   lFileSeqNo,     
  3.                           string   sExtType,     
  4.                           string   sExtNumber,     
  5.                           string   sFormID,     
  6.                           string   sOperationDate,     
  7.                           string   sSystemRegistDate,     
  8.                           out   int   lCount,     
  9.                           out   int   lErrorType,     
  10.                           out   int   lErrorCode)     
  11.                   {     
  12.                           int   iRet;     
  13.       
  14.                           WOBCom.ObjClass   obj   =   new   WOBCom.ObjClass();     
  15.                               
  16.                           iRet   =   obj.GetNum(     
  17.                                   lFileSeqNo,     
  18.                                   sExtType,     
  19.                                   sExtNumber,     
  20.                                   sFormID,     
  21.                                   sOperationDate,     
  22.                                   sSystemRegistDate,     
  23.                                   out   lCount,     
  24.                                   out   lErrorType,     
  25.                                   out   lErrorCode);     
  26.       
  27.                           return   iRet;     
  28.                   }     

如不使COM是普通的DLL  

不能直接用  

只能在C++中加一個對外的接口:  

  1. extern   "C"   __declspec(dllexport)   WOExtConRegObj*   OutGetObjConstructor();     
  2. extern   "C"   __declspec(dllexport)   void   OutGetObjDestructor(WOExtConRegObj*   outGetObj);     
  3.       
  4. extern   "C"   __declspec(dllexport)   long   SelectDummyRecord(long   *lErrorType,     
  5.         long   *lErrorCode,     
  6.         WOExtConRegObj*   outGetObj);     
  7. //     
  8. extern   "C"   __declspec(dllexport)   WOExtConRegObj*   OutGetObjConstructor()     
  9. {     
  10.           WOExtConRegObj*   outGetObj   =   new   WOExtConRegObj();        
  11.           return   outGetObj;     
  12. }     
  13.       
  14. extern   "C"   __declspec(dllexport)   void   OutGetObjDestructor(WOExtConRegObj*   outGetObj)     
  15. {     
  16.           delete   outGetObj;     
  17. }     
  18.       
  19. extern   "C"   __declspec(dllexport)   long   SelectDummyRecord(long   *lErrorType,     
  20.         long   *lErrorCode,     
  21.         WOExtConRegObj*   outGetObj)     
  22. {     
  23. return   outGetObj->SelectDummyRecord(lErrorType,     
  24. lErrorCode);         
  25. }     

就可直接用C#調(diào)用C++動態(tài)鏈接庫了    

  1. [DllImport("XXX.dll", EntryPoint="SelectDummyRecord", ExactSpelling=false, CallingConvention=CallingConvention.Cdecl)]     
  2.  private   static   extern   int   SelectDummyRecord(out int lErrorType,out int lErrorCode,int outGetObj);     
  3.  
  4.  ///   < summary>     
  5.  ///   < /summary>     
  6.  ///   < remarks>     
  7.  ///   < /remarks>                     
  8.  ///   < param name="lErrorType">< /param>     
  9.  ///   < param name="lErrorCode">< /param>     
  10.  ///   < returns>< /returns>     
  11.  public int SelectDummyRecord(out int lErrorType,out int lErrorCode)     
  12.  {     
  13.          int   intRtn;     
  14.  
  15.          intRtn   =   SelectDummyRecord(     
  16.                  out   lErrorType,     
  17.                  out   lErrorCode,     
  18.                  m_OutGetObj);       
  19.          return   intRtn;     
  20.  }    

這樣就解決了C#調(diào)用C++寫的動態(tài)鏈接庫的問題。

【編輯推薦】

  1. C#程序中的數(shù)據(jù)顯 示:自定義標簽和XML、XSL
  2. C#自定義事件是如何生成的
  3. C# 自定義控件dll文件的生成步驟
  4. C#自定義快捷鍵的實現(xiàn)
  5. C#自定義事件的步驟介紹
責任編輯:book05 來源: hi.baidu
相關推薦

2024-03-01 20:59:11

C#DLL開發(fā)

2011-05-18 17:15:45

2009-08-28 16:19:30

C#實現(xiàn)修改動態(tài)鏈接庫

2010-02-01 17:37:35

C++調(diào)用C鏈接庫

2012-01-06 10:25:50

JavaDLLC++

2021-09-01 05:11:13

C# 動態(tài)鏈接庫

2023-03-15 15:58:11

Python動態(tài)庫C++

2011-04-08 09:52:44

C++C#DLL

2009-08-24 18:09:13

C#調(diào)用Oracle數(shù)

2009-08-25 14:42:41

由C++轉向C#

2009-09-17 18:14:05

C#動態(tài)數(shù)組

2009-08-07 16:10:20

C#調(diào)用API

2009-08-20 12:29:46

C#調(diào)用PInvoke

2009-08-31 16:33:28

C#調(diào)用Dispose

2009-08-31 18:05:14

C#調(diào)用WalkTre

2023-08-02 10:10:00

C#C++

2009-09-02 11:02:57

C#動態(tài)數(shù)組

2009-08-20 16:25:59

C# 匿名方法

2009-08-19 14:35:12

C++和C#相互調(diào)用C

2009-08-14 17:27:56

C#方法參數(shù)
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 91在线网站| 99精品免费 | 成人欧美一区二区三区黑人孕妇 | 中文字幕在线观看视频一区 | 欧美日韩亚洲国产 | 国产激情视频在线 | 亚洲欧美中文日韩在线v日本 | 亚洲97 | 国产精品视频观看 | 91资源在线 | 欧美成人精品一区二区男人看 | 黄毛片 | 久久久久国产精品一区二区 | 欧美美乳 | 欧美性猛片aaaaaaa做受 | av手机在线 | 欧美一区二区三区视频 | 在线免费亚洲视频 | www操操 | 黑人巨大精品欧美黑白配亚洲 | 欧美成年网站 | 久久久成 | 亚洲成人99| 日韩精品一区二区三区中文字幕 | 男女深夜网站 | 五十女人一级毛片 | 日韩精品一区二区三区久久 | 亚洲午夜av久久乱码 | 中文字幕免费 | 国产一区精品 | 伊人精品久久久久77777 | 日本不卡免费新一二三区 | av在线免费观看网址 | 日韩在线一区二区 | 欧美一区二区三区在线 | 国产精品久久久久久久久久久久冷 | 国产精品久久久久9999鸭 | 久久精品视频一区二区三区 | 久久久国产一区 | 国产精品99久久久久久久vr | 欧美操操操 |