[問題] C#中引入C++的dll檔

看板C_Sharp (C#)作者 (可愛活潑小獸兒)時間16年前 (2009/08/25 19:10), 編輯推噓3(306)
留言9則, 3人參與, 最新討論串1/1
我上網查了一下有關如何引用Dll檔的文章 知道了要使用dllimport這方法 就是 [DllImport("我要引入的dll檔")] 然後 public static extern ReturnType FunctionName(type arg1,type arg2,...); 但是 我發現上面那行中的"ReturnType" 好像都不是固定的 請問這裏要看哪裡判斷呢? 接著是FunctionName的部分 我c++的dll中 程式碼是 extern "C" __declspec(dllexport) int __stdcall CommOpen(int index, int com_port); extern "C" __declspec(dllexport) int __stdcall CommOpenS(int index, char *com_name); extern "C" __declspec(dllexport) int __stdcall CommClose(int index); .. .. .. .. .. .. 以下略 請問 我函式名稱應該從哪裡開始用呢?? 是public static extern 然後接int __stdcall CommOpen(int index, int com_port); 還是前面的extern "C" _declspec(dllexport)也要? 或是其他方式呢@@a 想請版友們幫忙解答一下 感恩 -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.128.142.113 ※ 編輯: iamso1 來自: 140.128.142.113 (08/25 19:10)

08/25 20:07, , 1F
return type就是int啊... :O
08/25 20:07, 1F

08/25 20:11, , 2F
public static extern int CommOpen(int index,
08/25 20:11, 2F

08/25 20:11, , 3F
int com_port);
08/25 20:11, 3F

08/25 23:56, , 4F
對不起 我突然有種恍然大悟的感覺XD
08/25 23:56, 4F

08/25 23:57, , 5F
extern "C" __declspec(dllexport) int __stdcall
08/25 23:57, 5F

08/25 23:57, , 6F
那上面那串 是要轉成dll檔才需要用到嗎??
08/25 23:57, 6F

08/27 22:00, , 7F
那些都只是指定calling convension吧. P/Invoke會自己
08/27 22:00, 7F

08/27 22:00, , 8F
處理... :P
08/27 22:00, 8F

08/28 00:21, , 9F
可以參考一下 #1AQT6eER
08/28 00:21, 9F
文章代碼(AID): #1AayQTmc (C_Sharp)
文章代碼(AID): #1AayQTmc (C_Sharp)