如何在 C# 中编写我自己的包装器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/749520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to write my own wrapper in C#?
提问by Skuta
In my other question, I've been trying to find someone who knows where to find free open source OCR library for C#. However, it seems there is only C++ library and obviously, C++ is not C#.
在我的另一个问题中,我一直在寻找知道在哪里可以找到 C# 的免费开源 OCR 库的人。但是,似乎只有 C++ 库,显然,C++ 不是 C#。
One of the responds suggested to write my own wrapper in C#. I have pretty much no idea how to do it, where to learn to do it, or what it actually is - except I believe it's calling C++ methods in dll by changed method calls, .. that's just assumption, indeed.
其中一个回应建议用 C# 编写我自己的包装器。我几乎不知道怎么做,在哪里学习做它,或者它实际上是什么 - 除了我相信它通过更改的方法调用在 dll 中调用 C++ 方法,..这确实只是假设。
Please, help out one more newbie. Thank you
请再帮助一位新手。谢谢
采纳答案by Sunny Milenov
回答by Not Sure
If you're wrapping is very simple, you can get away with P/Invoke. If you actually want managed objects, your easiest solution is probably to write the wrapper in C++/CLI (formerly Managed C++), as that provides a full feature set for managed/unmanaged interop.
如果您的包装非常简单,则可以使用P/Invoke。如果您确实需要托管对象,那么最简单的解决方案可能是在 C++/CLI(以前称为托管 C++)中编写包装器,因为它为托管/非托管互操作提供了完整的功能集。