C# 调用静态C++库

欢乐的工科小硕 2014-04-23 03:55:22
菜鸟一枚,目前只会用C#调用动态编译的C++库文件,即编译的时候使用Use MFC in a Shared DLL。
求哪位大神知道怎么用C#调用使用了静态库文件编译的库文件,即编译的时候使用Use MFC in a Static Library
...全文
732 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xian_wwq 2014-04-25
  • 打赏
  • 举报
回复
引用 7 楼 u010141025 的回复:
[quote=引用 6 楼 feng_3630 的回复:] [DllImport("PCI_DMC_01.dll", EntryPoint = "_DMC_01_open")] public static extern short CS_DMC_01_open(ref short existcard); 这样的调用
你好,可是用这种方式的话,在C++ dll中定义的类或者自定义类型就无法使用了[/quote] 我见过的情况是c/c++库提供c格式的api,在C#中对应进行封装使用。
  • 打赏
  • 举报
回复
引用 6 楼 feng_3630 的回复:
[DllImport("PCI_DMC_01.dll", EntryPoint = "_DMC_01_open")] public static extern short CS_DMC_01_open(ref short existcard); 这样的调用
你好,可是用这种方式的话,在C++ dll中定义的类或者自定义类型就无法使用了
mjp1234airen4385 2014-04-24
  • 打赏
  • 举报
回复
静态库只能给C++调用。 @2楼,没人给你回帖还是新注册个帐号吧。
桃子先生 2014-04-24
  • 打赏
  • 举报
回复
c#应该是没法直接调用静态库的,除非你编译成动态库。
F_bjtu_wxy 2014-04-24
  • 打赏
  • 举报
回复
你好,这是我在查类似问题时用到的信息,希望对你有帮助 http://wenku.baidu.com/view/24a53722af45b307e87197d5.html
feng_3630 2014-04-24
  • 打赏
  • 举报
回复
[DllImport("PCI_DMC_01.dll", EntryPoint = "_DMC_01_open")] public static extern short CS_DMC_01_open(ref short existcard); 这样的调用
xzweihe 2014-04-23
  • 打赏
  • 举报
回复
先向楼主道个歉,借用你的帖子問个问题,没分了,哎 VC的接口 Bool GetKeyPadStatus( byte * addr, char * pstatus, char * pnumber,byte* ptocounter); C# 调用 [DllImport("KeyPad.dll", CallingConvention = CallingConvention.StdCall)] public static extern bool GetKeyPadstatus(ref byte addr, ref string pstatus, ref string pnumber, ref byte ptocounter); //获取终端状态函数 调用函数 byte address1 = 1; //byte address2 = 2; string pstatus = "0"; //////////这个值 string pnumber = "0000"; byte mtocounter = 0;// bool temp = calldll.GetKeyPadstatus(ref address1, ref pstatus, ref pnumber, ref mtocounter); if (temp) { switch (pstatus[0]) { case '0': label7.Text = "怎么是0 零 没有获得呼叫器的状态值"; break; case 'L': label7.Text = "空闲状态,按了清除键了"; break; case 'E': label7.Text = "暂停状态,按了暂停键"; break; case 'W': label7.Text = "等待" + pnumber; break; case 'P': label7.Text = "呼叫" + pnumber; //重复呼叫 CallAndPrint(); break; case 'M': label7.Text = "转移" + pnumber + "到" + mtocounter.ToString() + "窗口"; break; case 'S': label7.Text = "正在受理" + pnumber; break; case 'U': label7.Text = "呼叫器要求派号"; byte waitnum = 100; //等待人数 calldll.setKeyPadnumber(ref address1, ref pnumber, waitnum); Thread.Sleep(120); CallAndPrint(); break; } } 最后获取的pstatus 值 是 0 也就是我开始刚给他的赋值 谢谢了,帮个忙,弄了一下午了,郁闷死了
iyomumx 2014-04-23
  • 打赏
  • 举报
回复
不能直接使用静态库,要么写点代码编译成DLL,要么用C++/CLI

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧