使用痛饮用C#的时候什么是最好的做法? [英] What are the best practices when using SWIG with C#?

查看:94
本文介绍了使用痛饮用C#的时候什么是最好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人在那里使用与C#的痛饮库?如果你有,你有没有发现什么缺陷,什么是使用该库的最佳方法?我想用它作为该用C语言编写的程序的包装,我想换行的头文件,我可以在我的.NET应用程序中使用它们。

Has anybody out there used the SWIG library with C#? If you have, what pitfalls did you find and what is the best way to use the library? I am thinking about using it as a wrapper for a program that was written in C and I want to wrap the header files where I can use them in my .NET application.

我计划运行在Linux和Windows应用程序,因此原因,我寻找到痛饮。的P / Invoke是不是一种选择。

I plan on running the application on Linux and Windows, therefore the reason I am looking into SWIG. P/Invoke is not an option.

推荐答案

我认为错误的早期海报所做的就是阅读文档,而不是看的例子。

I think the mistake the earlier posters did was read the docs and not look at the examples.

几个小时前,我需要一些接口的C ++类,C#。我看着在我痛饮目​​录(我已经有它的其他工作),找到例子/ CSHARP /班,浏览了$ C $目录c,加载的解决方案,grokked它,把它抄了,把我的code,它的工作,我的工作已完成。

A few hours ago I needed to interface some C++ classes to C#. I looked in my Swig dir (I already had it for other work), found the directory Examples/csharp/class, browsed the code, loaded the solution, grokked it, copied it, put in my code, it worked, my job was done.

随着中说,产生的P / Invoke code是不是所有需求的解决方案。根据您的项目,很可能只是简单给自己写一些简单的API包装或写托管C ++(查找SlimDX对于这个一个极好的例子)。

With that said, generated P/Invoke code isn't a solution for all needs. Depending on your project, it may be just as simple to write some simple API wrappers yourself or write managed C++ (Look up SlimDX for a superb example of this).

有关我的需求,这是简单和容易 - 我有 mystuff.dll ,现在除了我可以出货 mystuffnet.dll 。我会同意,DOC是很难进入。

For my needs, it was simple and easy - I had mystuff.dll, and now in addition I can ship mystuffnet.dll. I'll agree that the doc is difficult to get into.

编辑:我注意到OP只提到C.对于这一点,你并不真正需要痛饮,只需使用usual C#/ C dllimport的互操作语法。当你想要让痛饮成为有用的 C ++类从C#调用。

I noticed the OP only mentioned C. For that, you don't really need Swig, just use the usual C#/C DLLImport interop syntax. Swig becomes useful when you want to let C++ classes be invoked from C#.

这篇关于使用痛饮用C#的时候什么是最好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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