Board index » cppbuilder » Newbie Shellexecute and app path

Newbie Shellexecute and app path


2007-06-21 03:18:09 PM
cppbuilder112
I am trying to run a exe from builder.
I have this working using the following
ShellExecute(NULL, "open", "d:\\MyApp:, NULL, NULL, SW_SHOW);
What I want to do is replace the "Myapp" with a variable as follows
String apppath;
apppath = ExtractFilePath(Application->ExeName) + "MyApp.exe";
ShellExecute(NULL, "open", apppath , NULL, NULL, SW_SHOW);
The above code gives me a error
[C++ Error] Unit1.cpp(26): E2342 Type mismatch in parameter 'lpFile' (wanted
'const char *', got 'AnsiString')
I do not know how to resolve this
TIA
Sam
 
 

Re:Newbie Shellexecute and app path

Il Thu, 21 Jun 2007 17:18:09 +1000, "sam" < XXXX@XXXXX.COM >ha scritto:
[snip]
Quote
String apppath;
apppath = ExtractFilePath(Application->ExeName) + "MyApp.exe";
ShellExecute(NULL, "open", apppath , NULL, NULL, SW_SHOW);

The above code gives me a error
[C++ Error] Unit1.cpp(26): E2342 Type mismatch in parameter 'lpFile' (wanted
'const char *', got 'AnsiString')
[snip]
Hi Sam,
try with:
ShellExecute(NULL, "open", apppath.c_str() , NULL, NULL, SW_SHOW);
Regards
Giuliano
 

Re:Newbie Shellexecute and app path

Ciao Giuliano
This compiles with no errors BUT does not start exe
Sam
<Giuliano>wrote in message
Quote
Il Thu, 21 Jun 2007 17:18:09 +1000, "sam" < XXXX@XXXXX.COM >ha scritto:

[snip]
>String apppath;
>apppath = ExtractFilePath(Application->ExeName) + "MyApp.exe";
>ShellExecute(NULL, "open", apppath , NULL, NULL, SW_SHOW);
>
>The above code gives me a error
>[C++ Error] Unit1.cpp(26): E2342 Type mismatch in parameter 'lpFile'
>(wanted
>'const char *', got 'AnsiString')
[snip]

Hi Sam,

try with:

ShellExecute(NULL, "open", apppath.c_str() , NULL, NULL, SW_SHOW);

Regards

Giuliano
 

{smallsort}

Re:Newbie Shellexecute and app path

Working.
I had a typo
Thanking you
Sam
<Giuliano>wrote in message
Quote
Il Thu, 21 Jun 2007 17:18:09 +1000, "sam" < XXXX@XXXXX.COM >ha scritto:

[snip]
>String apppath;
>apppath = ExtractFilePath(Application->ExeName) + "MyApp.exe";
>ShellExecute(NULL, "open", apppath , NULL, NULL, SW_SHOW);
>
>The above code gives me a error
>[C++ Error] Unit1.cpp(26): E2342 Type mismatch in parameter 'lpFile'
>(wanted
>'const char *', got 'AnsiString')
[snip]

Hi Sam,

try with:

ShellExecute(NULL, "open", apppath.c_str() , NULL, NULL, SW_SHOW);

Regards

Giuliano
 

Re:Newbie Shellexecute and app path

"sam" < XXXX@XXXXX.COM >wrote in message
Quote
[C++ Error] Unit1.cpp(26): E2342 Type mismatch in parameter 'lpFile'
(wanted 'const char *', got 'AnsiString')
I do not know how to resolve this
Use AnsiString's c_str() method, ie:
AnsiString apppath = ExtractFilePath(Application->ExeName) +
"MyApp.exe";
ShellExecute(NULL, "open", apppath.c_str(), NULL, NULL, SW_SHOW);
With that said, you should use CreateProcess() instead of
ShellExecute() to run .exe files.
STARTUPINFO si = {sizeof(STARTUPINFO), 0};
PROCESS_INFORMATION pi = {0};
if( CreateProcess(NULL, apppath.c_str(), NULL, NULL, FALSE, 0,
NULL, NULL, &si, &pi) )
{
//...
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
Gambit
 

Re:Newbie Shellexecute and app path

Remy,
Quote
With that said, you should use CreateProcess() instead
of ShellExecute() to run .exe files.
You have made me curious. What are your reasons that ShellExecute not be
used?
FWIW: I also use CreateProcess to run them, avoiding ShellExecute whenever I
can but only because I want to avoid the additional processing overhead in
ShellExecute and from a worry that it may fire off the wrong EXE.
. Ed
Quote
Remy Lebeau wrote in message
news: XXXX@XXXXX.COM ...
 

Re:Newbie Shellexecute and app path

"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
You have made me curious. What are your reasons that
ShellExecute not be used?
ShellExecute() calls CreateProcess() internally, so it is redundant
and unnecessary. Also, like you said: "to avoid the additional
processing overhead". ShellExecute() is a very general-purpose
function that does a lot of different things, whereas running an .exe
is a very specific operation that CreateProcess() was specifically
designed for.
Gambit
 

Re:Newbie Shellexecute and app path

Thank you for the info I will use CreateProcess
Sam
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
news:467a7977$ XXXX@XXXXX.COM ...

>You have made me curious. What are your reasons that
>ShellExecute not be used?

ShellExecute() calls CreateProcess() internally, so it is redundant
and unnecessary. Also, like you said: "to avoid the additional
processing overhead". ShellExecute() is a very general-purpose
function that does a lot of different things, whereas running an .exe
is a very specific operation that CreateProcess() was specifically
designed for.


Gambit