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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute windows function. 1

Status
Not open for further replies.

PANTLORD

Programmer
Aug 28, 2001
49
EU
RE:ShellExecute(EnumHandle, 'Open', @Connected ,'','', SW_SHOWMAXIMIZED)

Hi there,

I just have a query about this API function in particular the 3rd parameter which specifies the path to file to be acted upon.

It specifies that this parameter should be in the form of a pointer to a string however when I do this as shown above, it will not work if instead I pass a straight string to this function it works fine,, any ideas????

Thanks
SPBT

 
Try the following code snippet (It will return true if the file was executed succefully):

function TForm1.RunIt(FileName: String): boolean;
begin
Result := ShellExecute(Handle, 'open', PChar(Filename), '', '', SW_SW_SHOWMAXIMIZED) >32;
end;
Andreas Nordlund
Software developer
 
This is the Executefile function.
I use this rather than calling shellexecute directly, But you can see the correct way of calling shellexecute.

It is part of Fmxutils.pas which is in demos/doc/filemanex folder there are several useful functions in here.
( But watch out for the bug in the filecopy function fixed in D4 and above)


function ExecuteFile(const FileName, Params, DefaultDir: string;
ShowCmd: Integer): THandle;
var
zFileName, zParams, zDir: array[0..79] of Char;
begin
Result := ShellExecute(Application.MainForm.Handle, nil,
StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
StrPCopy(zDir, DefaultDir), ShowCmd);
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top