最近做個專案,需要圖形介面,說到圖形介面,
c#要比
c++更容易實現,但是組內的其他人不怎麼會使
c#,一般都用
c++,這樣就需要將
c++生產為
dll檔案,然後在
c#程式彙總對其進行呼叫了。下面進行舉例:
在
vc++工程中
#include
#include
usingnamespacestd;
extern"c"int_declspec
(dllexport)add(inta,intb);
extern"c"void_declspec
(dllexport)stringadd(char*a,char*b,char*c);
// lib.cpp
#include"stdafx.h"
#include"lib.h"
extern"c"int_declspec
(dllexport)add(inta,intb)
extern"c"void_declspec
(dllexport)stringadd(char*a,char*b,char*c)
將生成好的
dll檔案放到
c#生成的可執行檔案目錄中,然後在
c#程式中進行如下呼叫。
c#工程中
[dllimport("lib.dll")]
publicstaticexternintadd(inta,intb);
[dllimport("lib.dll")]
publicstaticexternvoidstringadd(stringbuildera,stringbuilderb,stringbuilderc);
privatevoidbutton1_click(objectsender,eventargse)
這樣我們便實現了
c#中對
c++生成的
dll檔案的呼叫。
c 呼叫c c 的dll檔案例項
1 c 中的函式宣告 extern c declspec dllexport int stdcall testfunc int a,char b,一般有入參,出參,返回值。這裡舉例a為入參,b為出參,返回值為整數,比如0。並把dll檔案放到c 同目錄下,比如 bin debug 或 bin rele...
C 呼叫C 的dll總結
舉例 netcontrol.cs using system using system.collections.generic using system.text using system.runtime.interopservices 這句必不可少 namespace netcontrol 1.dl...
c 呼叫c 的dll 例項
一 使用 clr編譯mfc可執行檔案或規則c dll函式.1 開啟 專案屬性 對話方塊,方法是右鍵單擊 解決方案資源管理器 中的專案並選擇 屬性 2 展開 配置屬性 旁邊的節點並選擇 常規 在右側窗格中的 專案預設值 下,將 公共語言執行庫支援 設定為 公共語言執行庫支援 clr 3 在相同的窗格中...