我想在我的vb.net项目中运行或包含c ++或python代码 [英] i wanna run or compire c++ or python code in mine vb.net project

查看:118
本文介绍了我想在我的vb.net项目中运行或包含c ++或python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我想在我的vb.net项目中运行或包含c ++或python代码
我可以这样做吗?
任何源代码?
任何想法吗?任何组件??
any Trick ??

hi every body
i wanna run or compire c++ or python code in mine vb.net project
can i do this??
any source code ??
any idea??any component???
any Trick??

推荐答案

首先,您可以使用System.Diagnostics.Process.Start方法之一执行任何外部应用程序:
http://msdn.microsoft.com/en-us/library/system.diagnostics. process.aspx [^ ].

请注意,您可以将外部进程(编译器,C ++或Python代码,已编译的应用程序等)的输出重定向到某个流,并在父进程中使用它.为此,您将需要重定向StandardOutputStandardError.请参阅:
http://msdn.microsoft.com/en-us/library/system. diagnostics.process.standardoutput.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. diagnostics.process.standarderror.aspx [ ^ ].

上面引用的两个MSDN帮助文章都包含一些重定向代码示例.

如果不是C ++,而是C ++/CLI,则可以在主机应用程序中动态编译和加载.NET程序集.如果您需要使此类代码可重载,则这是一个非常复杂的问题,因为无法卸载程序集,您将需要创建和卸载单独的应用程序域,并且需要在IPC的应用程序域边界范围内进行操作.您可以在我过去的答案中找到更多详细信息:
创建使用可重载插件的WPF应用程序... [^ ],
AppDomain拒绝加载程序集 [使用CodeDom生成代码 [创建使用可重载插件的WPF应用程序... [ ^ ],
动态加载用户控件 [在现有实例上的C#反射InvokeMember [ http://en.wikipedia.org/wiki/IronPython [ http://ironpython.net/ [ ^ ].

我提到的所有选项可能适用也可能不适用.我不知道你的目标,这就是原因.下次,请开始提出您的问题,并解释您的最终目标.

—SA
First of all, you can execute any external application using one of System.Diagnostics.Process.Start methods:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].

Pay attention that you can redirect output of your external process (a compiler, C++ or Python code, compiled application, etc.) to some stream and use it in your parent process. To do so, you will need to redirect StandardOutput and StandardError. Please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standarderror.aspx[^].

Both MSDN help article referenced above contain some redirection code samples.

If you really mean not C++, but C++/CLI, you can dynamically compile and load the .NET assembly in your host application. This is a pretty complex problem if you need to make such code reloadable, because there is no way to unload an assembly, you you would need to create and unload separate Application Domains and worth through the Application Domain boundary with IPC. You can find further detail in my past answers:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^],
Dynamically Load User Controls[^],
C# Reflection InvokeMember on existing instance[^].

As to the Python, you also can think about using Python for .NET. Such thing does exist, called IronPython:
http://en.wikipedia.org/wiki/IronPython[^],
http://ironpython.net/[^].

All the options I mentioned may or may not be applicable. I don''t know you goals, that''s why. Next time, please start asking your question with explanation of your ultimate goals.

—SA


Sergey ...你好吗?首先我尝试在您的网站上发送评论,但我可能没有问题...哈哈
关于它不是不是很小的Visual Studio ...但是我考虑了,这是我未来的项目.....
所以现在
我正在这个项目中工作,我需要一些python脚本和c ++的源代码...并且我应该使用它们表示何时运行我copmile并运行...所以
你的主意是什么...或其他主意.. ??
:)
hi Sergey ...how are you??first i tried send comment on your website but i couldn''t maybe have problem...LOL
and about it not exactly small Visual Studio...but i think about it and this is my future project.....
so now
i am working on a project in this i need to some script of python and some source code of c++...and i should to use of them mean when is run i copmile them and run...so
what is your idea....or others idea..??
:)


看看 SharpDevelop [
Have a look at SharpDevelop[^] - it even includes a c# to vb converter.

SharpDevelop also supports IronPython - so there you have all you''re asking for :-D

Best regards
Espen Harlinn


这篇关于我想在我的vb.net项目中运行或包含c ++或python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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