[Delphi] dynamicly load an external function / procedure
Publicado: 25 Jun 2008, 13:12
Código: Seleccionar todo
type
TShellexecute = function(hWnd: HWND; Operation, FileName, Parameters,
Directory: PChar; ShowCmd: Integer): HINST; stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
hLib: cardinal;
MyShellExecute: TShellexecute;
begin
hLib := LoadLibrary('shell32.dll');
if hLib <> 0 then
begin
@MyShellexecute := GetProcAddress(hLib, 'ShellExecuteA');
if not Assigned(MyShellexecute) then
begin
RaiseLastOSError;
exit;
end;
end
else
begin
RaiseLastOSError;
exit;
end;
MyShellexecute(Form1.Handle, 'open', 'Notepad.exe', nil, nil, SW_NORMAL);
end;
Source:[Enlace externo eliminado para invitados]