vba 如何将 VB 程序与 C++ 程序混合使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8319795/
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 mix a VB program with a C++ Program
提问by Monkeyanator
I have a C++ program that I wrote, and I would like to give it a user interface. Is there any way I can run a C++ program and put the information from the program onto the UI of a VB Application?
我有一个我写的 C++ 程序,我想给它一个用户界面。有什么方法可以运行 C++ 程序并将程序中的信息放到 VB 应用程序的 UI 上?
回答by sehe
Sure.
当然。
Use
用
- COM
- COM Interop
- P/Invoke (a.k.a.
Declare
in VB) - Oh, I forgot: C++/CLR if you intend to use Windows only
- 通讯
- COM互操作
- P/Invoke(
Declare
在 VB 中又名) - 哦,我忘了:C++/CLR 如果你打算只使用 Windows
I suggest you write the whole application in a managed language (e.g. VB.Net) and only invoke C++ library functions for the performance critical work (or for legacy code that you already have, of course).
我建议您用托管语言(例如 VB.Net)编写整个应用程序,并且只调用 C++ 库函数来执行性能关键工作(当然,或者您已经拥有的遗留代码)。
回答by Drew Chapin
I think the easiest solution would be to put your C++ code into a DLL, and call your code from VB. Have a look at this article for more information...
我认为最简单的解决方案是将您的 C++ 代码放入 DLL 中,然后从 VB 调用您的代码。看看这篇文章了解更多信息......
回答by Keith Nicholas
you can mix C++ and .NET
你可以混合 C++ 和 .NET
easiest is if you target your C++ code to the CLR, but you can also mix .NET and native code.
最简单的方法是将 C++ 代码定位到 CLR,但您也可以混合使用 .NET 和本机代码。
either way you basically make your C++ program a library your VB code can use.
无论哪种方式,您基本上都可以使您的 C++ 程序成为您的 VB 代码可以使用的库。