如何在C#中使用C ++静态库? [英] How to use c++ static library in c# ?

查看:778
本文介绍了如何在C#中使用C ++静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中使用c ++静态库?

案例场景是:

1)我有一个静态库(从VC ++编译的.lib文件).
2)我没有静态库的代码.
3)没有与静态库相关的任何dll.
4)我必须将此静态库中的函数调用到C#项目中.
5)静态库中有数百个函数.

如何实现呢?

请提供详细步骤.

(注意:关于这个主题,我走过很多话题,但没人回答这个问题.)

在此先谢谢您.

How to use c++ static library in c# ?

The case scenario is:

1) I have a static library (a .lib file compiled from VC++).
2) I don''t have the code of static library.
3) No any dll related to static library.
4) I have to call the functions from this static library into C# project.
5) There are hundreds of functions in the static library.

How to achieve this ?

Please give detailed steps.

(Note : I have gone thru many threads on this topic none of them answers this Q.)

Thanks in advance.

推荐答案

您需要的另一个选择是编写包装库的托管C ++代码,并且可以从C#中调用它.我认为没有自动的方法,没有dll,必须创建一个dll,托管会更容易.
The other option you have is to write managed C++ code that wraps the library, and can be called from C#. There''s no automatic way to do it, you don''t have a dll, you''ll have to create one, managed will be easier, I reckon.


C#可以仅使用DLL或COM组件调用C ++.

您将需要创建一个调用.LIB函数的包装DLL.
对于.LIB文件中的每个函数,请在DLL中创建并导出一个函数.
C# can call into C++ only using either a DLL or a COM component.

You will need to create a wrapper DLL that invokes the .LIB functions.
For each function in the .LIB file create and export a function in the DLL.


这篇关于如何在C#中使用C ++静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆