关于CreateProcess和C字符串(100分)

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

DelphiBB

Unregistered / Unconfirmed
GUEST, unregistred user!
一、
bool __fastcall TFormMain::DataLoadOut(Char* Cmd)
{
bool Result = false;
unsigned long ExitCode;
STARTUPINFO *StartupInfo = new STARTUPINFO;
PROCESS_INFORMATION *ProcessInfo = new PROCESS_INFORMATION;
StartupInfo->cb = sizeof(STARTUPINFO);
StartupInfo->dwFlags=STARTF_USESHOWWINDOW;
StartupInfo->wShowWindow=SW_SHOWNORMAL;
if (CreateProcess(NULL,Cmd,NULL,NULL,true,
CREATE_NEW_CONSOLE|NORMAL_PRIORITY_CLASS,NULL,NULL,StartupInfo,ProcessInfo))
{
WaitForSingleObject(ProcessInfo->hProcess,INFINITE);
GetExitCodeProcess(ProcessInfo->hProcess,&ExitCode))
//问题1.在此处应该对这个GetExitCodeProcess的返回值和ExitCode如何处理?
}//成功建立进程;
CloseHandle(ProcessInfo->hProcess);
CloseHandle(ProcessInfo->hThread);
delete StartupInfo;
delete ProcessInfo;
return Result;
}
注:程序流程上的一些问题不必细究
二、有一个按钮调用上面的函数
void __fastcall TFormMain::Button1Click(TObject *Sender)
{
Char *CMD2 = "bcp syscolumns out c://aaaa.txt -c -t, -S180.1.90.68 -Usa -Paaa111";
Char *CMD = ListBox1->Items->Strings[0].c_str();
for (int i =0;i<3;i++)
{
//调用CMD2没有问题
//调用CMD时,就没法执行了,调试可以看到CMD = ????,因为为了程序通用,
//所以要用StringList来传入字符串,应该如何传?
DataLoadOut(CMD);
}
 
分数加多100,大家都来看看呀!
 
大家都来帮个忙呀,在Delphi下很容易就实现了.上面的问题我觉得都是C语言没有用
好的原因,但是怎么用呢.....
 
1.
BOOL GetExitCodeProcess(
HANDLE hProcess, // handle to the process
LPDWORD lpExitCode // address to receive termination status
);

Parameters:
hProcess
Handle to the process.
Windows NT: The handle must have PROCESS_QUERY_INFORMATION access.
lpExitCode
Pointer to a 32-bit variable to receive the process termination status.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
2.
没用过bcb,不明白下面这居是什么意思。c_str()是什么?
ListBox1->Items->Strings[0].c_str();
Listbox如果取第一行字符串用Listbox1->Items[0]
or ListBox1->Items->STrings[0]
怎么还有个c_str()跟在后面。
Char *CMD = PChar(ListBox1->Items->Strings[0]) 不行吗?

 

Similar threads

I
回复
0
查看
521
import
I
I
回复
0
查看
592
import
I
I
回复
0
查看
631
import
I
后退
顶部