Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with WinExec

Status
Not open for further replies.

swordfish1973

Technical User
Nov 6, 2003
13
IT
I need to launch an Excel file from my project, I tried WinExec but it seems to do nothing when I try:

void __fastcall TForm::Button2Click(TObject *Sender)
{
WinExec("excel.exe C:\Projects_Borland5\BookTracker\\zero_curve.xls", SW_SHOW);
}

Can anyone tell me why?
Thank you
 
I think you should use CreateProcess

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Thank you.
I tried with ShellExecute and it seems to work!
 
ShellExecute still exist only for compatibility with Win16

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Did you type this in correct?
WinExec("excel.exe C:\Projects_Borland5\BookTracker\\zero_curve.xls", SW_SHOW);

Shouldn't it have been WinExec("excel.exe C:\\Projects_Borland5\\BookTracker\\zero_curve.xls", SW_SHOW); ?

James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
I used also the double \\ on the whole string, but didn't work anyway....
 
Hail!

The first thing you need is the path of the excel.exe. If this is not in the path environment variable this will not run. Check the FindExecutable API function. After this you should use CreateProcess and WaitForSingleObject.

The code:

//AnsiString FileName - hold the "c:\\xxx\\something.ext"

char executable[MAX_PATH+1];
FindExecutable(FileName.c_str(),NULL,executable);

FileName=AnsiString("\"")+AnsiString(executable)+"\" \""+FileName+"\"";

STARTUPINFO SI;
PROCESS_INFORMATION PI;
ZeroMemory(&SI,sizeof(SI));
SI.cb=sizeof(SI);
if (CreateProcess(NULL,FileName.c_str(),NULL,NULL,0,0,NULL,NULL,&SI,&PI))
{
WaitForSingleObject(PI.hProcess,INFINITE);
CloseHandle(PI.hProcess);
CloseHandle(PI.hThread);
};


Enjoy.

[blue]unbornchikken[/color]
 
By the way, Excel is something more than a simple executable.
You can use CoCreateInstance to run it as an ActiveX object. In this case you will get full control on this application. So you can use functions inside it to create/manipulate/open .xls files.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top