从我们的应用程序中调用编译器 [英] invoking compiler from our application

查看:102
本文介绍了从我们的应用程序中调用编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在c#中实现多语言代码编辑器.当用户按下编译器按钮在编辑器中键入程序后,c编译器应将文本区域中键入的程序(c程序)作为输入&应该返回其对象,该对象将包含相应的输出(输出或错误,如果有的话).
1)首先如何调用c编译器或将其链接到我们的c#程序?
2)然后如何进行上述场景?
3)如何捕捉c编译器给出的输出?
请针对以上问题提出解决方案.
关于,
thimmanagouda patil

I am implementing multilanguage code editor in c#.after typing program in editor when user presses compiler button,c compiler should take program typed(c program) in text area as input & should return its object that will contains corresponding output(output or error if any) .
1) firstly how to call or link c compiler to our c# program?
2)then how to carried out above scenerio?
3) how to catch output given by c compiler?
please suggest solution to above stuff.
with regards,
thimmanagouda patil

推荐答案

看看我对类似问题的回答: Control.Invoke()与Control.BeginInvoke( ) [ ^ ].另请参见 Treeview Scanner和MD5问题 [ ^ ].

对于线程,我建议使用其他答案,该答案建议创建一个线程包装器,以在避免类型转换的情况下将参数传递给线程:
Look at my Answer to similar question: providing COMPILER, DEBUGGER facility in IDE[^].

A key here is to catch compiler output in stdout and stderr from the process you spawn. I explained it in my Answer. You can re-direct the stream and ready it in some thread which is permanently working and is sleeping (mode exactly, waiting at the blocking stream read operation) when compiler is not working. Every time the thread read some unit of output or error, if should notify UI.

You cannot operate with UI controls from the thread. Instead, you should use Invoke of Invoke required methods of System.Windows.Forms.Control (Forms only) or System.Windows.Threading.Dispatcher (good for both Forms and WPF). I described all the details here: Control.Invoke() vs. Control.BeginInvoke()[^]. See also Problem with Treeview Scanner And MD5[^].

For thread, I recommend use my other Answer which advised to create a thread wrapper for passing parameters to the thread while avoiding type casting: How to pass ref parameter to the thread[^].

—SA


看看 ^ ]中有关如何实现此功能的一些文章和建议.
Take a look here[^] for some articles and suggestions on how to implement this.


这篇关于从我们的应用程序中调用编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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