Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to run exe files in delphi

658 views
Skip to first unread message

Joe

unread,
Oct 14, 2000, 7:28:56 PM10/14/00
to
How do you run external exe files in a delphi program,
I have searched through the help file thoughroughly and can't find any way
of doing this.

Any Help would be much appreciated.

Thanks.


Thomas Nelvik

unread,
Oct 14, 2000, 9:06:41 PM10/14/00
to
Joe wrote:
> How do you run external exe files in a delphi program,
> I have searched through the help file thoughroughly and can't find any
way
> of doing this.


Easiest is to use

{uses ShellAPI}
ShellExecute(
HInstance,
NIL,
PCHAR('c:\myapp.exe'),
PCHAR('parameters if any'),
PCHAR('default folder if any'),
SW_SHOWNORMAL { or any of the other sw_ constants});

You can also use CreateProcess() if you need to control the new process.

Both functions is found in the Win32 help.

-ThomasN


Joe

unread,
Oct 15, 2000, 3:00:00 AM10/15/00
to
I know these questions may be stupid but how do I use win32 code in my VCL
based project, I am using delphi 5.

Cheers.

Thomas Nelvik

unread,
Oct 15, 2000, 3:00:00 AM10/15/00
to
Joe wrote:
> I know these questions may be stupid but how do I use win32 code in my
VCL
> based project, I am using delphi 5.
>
> Cheers.


You use it much like other code.
But often you will have to do some typecasts such as the PChar to
string.

The question is not stupid, but I'm not quite sure if I got it right so
here's some more notes....

If the code is already imported by Delphi, you just add the unit to your
uses clause.
If not, you must import them yourself.
If you look at the winAPI units shipped with Delphi, (windows.pas,
shellapi.pas, etc., perhaps located at "$(DELPHI)\Source\Rtl\Win\" )
you'll see how it's done.

Eg:
The ShellExecute function is imported the ShellAPI.pas file aprx like
this:

function ShellExecute(hWnd: HWND; Operation, FileName, Parameters,
Directory: PChar; ShowCmd: Integer): HINST; stdcall; external
'shell32.dll' name 'ShellExecuteA';

You must know the size and number of parameters, the calling convention
(most often "stdcall"), the library (.dll) and the name or index of the
function. This should all be documented in the Win32 help. (Also check
the QuickInfo button on the help page).


Did that make any sense :) ?

Regards
-ThomasN

Bruce Roberts

unread,
Oct 15, 2000, 3:00:00 AM10/15/00
to

"Joe" <J...@orange123.freeserve.co.uk> wrote in message
news:39e9...@news.server.worldonline.co.uk...

> I know these questions may be stupid but how do I use win32 code in my VCL
> based project, I am using delphi 5.


In the case of the ShellExecute call you need to add the ShellAPI unit to a
uses clause in the unit. The majority of win 32 calls (including
CreateProcess) are defined in Windows.PAS which is automatically added to
the interface uses clause by the IDE when designing form units - so you
don't need to do anything special, just add the calling code.

Joe

unread,
Oct 15, 2000, 3:00:00 AM10/15/00
to
Yes thanks I've got it working now.
My version of delphi does not include the win32 help file.
I forgot to put uses, shellapi in. doh!.

Thanks again.

> Joe wrote:
> > I know these questions may be stupid but how do I use win32 code in my
> VCL
> > based project, I am using delphi 5.
> >

Bill Gupta

unread,
Oct 22, 2000, 3:00:00 AM10/22/00
to
Shell execute and createprocess are not easy at all.

At least I could not manage them(forgive me if I have a learning problem)

So I hunted around and found a gem

use
Winexecute

it takes just two arguments.

This is the most similar in operation to the Shell command that I use in VB,

Thanks
Razor

pssst.... I am absolutely new to Delphi, but I know VB well.


Joe <J...@orange123.freeserve.co.uk> wrote in message
news:39e9...@news.server.worldonline.co.uk...

> I know these questions may be stupid but how do I use win32 code in my VCL
> based project, I am using delphi 5.
>
> Cheers.
>
>

GRS

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
"Bill Gupta" <nom...@whatsamail.com> wrote in message news:8t31n5$ruc$1...@news.vsnl.net.in...

> Shell execute and createprocess are not easy at all.
>
> At least I could not manage them(forgive me if I have a learning problem)
>
> So I hunted around and found a gem
>
> use
> Winexecute
>
> it takes just two arguments.
>

BUT... it is only provided for backwards compatibility with old 16-bit applications and will eventually be phased out of the API.

I do strongly urge you to get to grips with at least ShellExecute.

GRS.

wpgf...@my-deja.com

unread,
Oct 25, 2000, 3:00:00 AM10/25/00
to
Hi I used the ShellExecute command and it works great. My next problem
is how do i keep the user from closing the calling program. I need to
make sure that the program that was called is closed first.

Thanks in advance,
J


In article <8t31n5$ruc$1...@news.vsnl.net.in>,


"Bill Gupta" <nom...@whatsamail.com> wrote:
> Shell execute and createprocess are not easy at all.
>
> At least I could not manage them(forgive me if I have a learning
problem)
>
> So I hunted around and found a gem
>
> use
> Winexecute
>
> it takes just two arguments.
>

> This is the most similar in operation to the Shell command that I use
in VB,
>
> Thanks
> Razor
>
> pssst.... I am absolutely new to Delphi, but I know VB well.
> Joe <J...@orange123.freeserve.co.uk> wrote in message
> news:39e9...@news.server.worldonline.co.uk...
> > I know these questions may be stupid but how do I use win32 code in
my VCL
> > based project, I am using delphi 5.
> >
> > Cheers.
> >
> >


Sent via Deja.com http://www.deja.com/
Before you buy.

0 new messages