如何使用delphi自动调用TC的编译器、链接器对C++的Code进行编译链接并且生成exe,然后获得编译器的相关信息以及程序运行的输入和输出?...高手请进~

  • 主题发起人 dream_flyer
  • 开始时间
D

dream_flyer

Unregistered / Unconfirmed
GUEST, unregistred user!
如何使用delphi自动调用TC的编译器、链接器对C++的Code进行编译链接并且生成exe,然后获得编译器的相关信息以及程序运行的输入和输出?...高手请进~(200分)<br />问题如下:
如何使用delphi自动调用TC的编译器、链接器对C++的Code进行编译链接并且生成exe,然后获得编译器的相关信息以及程序运行的输入和输出?...

ps:
1.对于编译器以及链接器的调用,windows sdk api一般有三种做法:winexec、shellexexc以及createprocess,一般来说我觉得createprocess是解决调用外部程序的最好方法
2.获得编译器编译信息怎么做?我看过tc编译器的参数选项,就是没看懂,请教精通编译器的高手了
3.对了获得输入和输出,我知道可以用重定向来做,createprocess是最好的方法,请给出代码
谢谢
 
由于涉及内容比较烦琐,此问题设置为800分(这里我设置200,余下的分数我会分别给出)
对于回答有价值的网友依次给分
 
1和3:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
hReadPipe,hWritePipe:THandle;
si:STARTUPINFO;
lsa:SECURITY_ATTRIBUTES;
pi:pROCESS_INFORMATION;
mDosScreen:String;
cchReadBuffer:DWORD;
ph:pChar;
fname:pChar;
i,j:integer;
begin
fname:=allocmem(255);
ph:=AllocMem(5000);
lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);
lsa.lpSecurityDescriptor :=nil;
lsa.bInheritHandle :=True;

if CreatePipe(hReadPipe,hWritePipe,@lsa,0)=false then
begin
ShowMessage('Can not create pipe!');
exit;
end;

fillchar(si,sizeof(STARTUPINFO),0);
si.cb :=sizeof(STARTUPINFO);
si.dwFlags :=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);
si.wShowWindow :=SW_HIDE;
si.hStdOutput :=hWritePipe;
StrPCopy(fname,'nbtstat -a 192.168.0.15');

if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False then
begin
ShowMessage('can not create process');
FreeMem(ph);
FreeMem(fname);
Exit;
end;

while(true) do
begin
if not PeekNamedPipe(hReadPipe,ph,1,@cchReadBuffer,nil,nil) then break;
if cchReadBuffer&lt;&gt;0 then
begin
if ReadFile(hReadPipe,ph^,4096,cchReadBuffer,nil)=false then break;
ph[cchReadbuffer]:=chr(0);
Memo1.Lines.Add(ph);
end
else if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then break;
Sleep(100);
end;

ph[cchReadBuffer]:=chr(0);
Memo1.Lines.Add(ph);
CloseHandle(hReadPipe);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(hWritePipe);
FreeMem(ph);
FreeMem(fname);
end;

end.

2. 恐怕帮不上忙了。但如果你用gcc做编译器,这儿倒是有一个现成的,
Dev C++,用Delphi做的C/C++集成开发环境,开放源代码:
http://sourceforge.net/projects/dev-cpp/
 
我回去研究一下
没有人对这方面感兴趣嘛?。。。。。
 
tc编译器,我不熟,但它都有说明,链接器也是一样,建个批处理文件就行,或者
自己编译-》链接,其它的就不难,关键是编译器,链接器的参数选项含义,你把它
贴上来,大家帮你看看;
 
建议你到这个站点询问一下编译器的参数。

http://61.153.195.10:8080/
罗云彬的编程乐园,WINDOWS汇编高手,那里面应该有了解编译器的吧。
 
顶部