作者iamso1 (可愛活潑小獸兒)
看板C_Sharp
標題[問題] C#中引入C++的dll檔
時間Tue Aug 25 19:10:18 2009
我上網查了一下有關如何引用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)
推 leicheong:return type就是int啊... :O 08/25 20:07
→ leicheong:public static extern int CommOpen(int index, 08/25 20:11
→ leicheong:int com_port); 08/25 20:11
→ iamso1:對不起 我突然有種恍然大悟的感覺XD 08/25 23:56
→ iamso1:extern "C" __declspec(dllexport) int __stdcall 08/25 23:57
→ iamso1:那上面那串 是要轉成dll檔才需要用到嗎?? 08/25 23:57
推 leicheong:那些都只是指定calling convension吧. P/Invoke會自己 08/27 22:00
→ leicheong:處理... :P 08/27 22:00