AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Probleme von ShellExecute unter Win2003 Server 64 Bit
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme von ShellExecute unter Win2003 Server 64 Bit

Ein Thema von BrinkschulteManfred · begonnen am 28. Apr 2008 · letzter Beitrag vom 5. Mai 2008
 
Benutzerbild von nicodex
nicodex

Registriert seit: 2. Jan 2008
Ort: Darmstadt
286 Beiträge
 
Delphi 2007 Professional
 
#17

Re: Probleme von ShellExecute unter Win2003 Server 64 Bit

  Alt 5. Mai 2008, 15:40
Man kann versuchen die File System Redirection des WOW64-"Emulators" für den Aufruf zu deaktivieren.
Delphi-Quellcode:
function Wow64DisableWow64FsRedirection(out AOldValue: Pointer): BOOL; stdcall;
type
  TFNRealApiProc = function(out AOldValue: Pointer): BOOL; stdcall;
const
  RealApiName = 'Wow64DisableWow64FsRedirection';
{$WRITEABLECONST ON}
const
  Initialized: Integer = 0;
  RealApiProc: TFNRealApiProc = nil;
{$WRITEABLECONST OFF}
begin
  if Initialized = 0 then
  begin
    RealApiProc := TFNRealApiProc(GetProcAddress(GetModuleHandle(kernel32),
      RealApiName));
    InterlockedIncrement(Initialized);
  end;
  if Assigned(RealApiProc) then
    Result := RealApiProc(AOldValue)
  else
  begin
    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    Result := False;
  end;
end;

function Wow64RevertWow64FsRedirection(AOldValue: Pointer): BOOL; stdcall;
type
  TFNRealApiProc = function(AOldValue: Pointer): BOOL; stdcall;
const
  RealApiName = 'Wow64RevertWow64FsRedirection';
{$WRITEABLECONST ON}
const
  Initialized: Integer = 0;
  RealApiProc: TFNRealApiProc = nil;
{$WRITEABLECONST OFF}
begin
  if Initialized = 0 then
  begin
    RealApiProc := TFNRealApiProc(GetProcAddress(GetModuleHandle(kernel32),
      RealApiName));
    InterlockedIncrement(Initialized);
  end;
  if Assigned(RealApiProc) then
    Result := RealApiProc(AOldValue)
  else
  begin
    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    Result := False;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
const
  FileName = 'sigverif.exe';
var
  ExecCode: Integer;
  RevertFs: BOOL;
  OldValue: Pointer;
  MsgText: string;
begin
  ExecCode := E_UNEXPECTED;
  RevertFs := False;
  try
    ExecCode := Integer(ShellExecute(Handle, nil, FileName, nil, nil, SW_SHOW));
    case ExecCode of
      ERROR_FILE_NOT_FOUND,
      ERROR_PATH_NOT_FOUND,
      SE_ERR_DLLNOTFOUND:
        begin
          RevertFs := Wow64DisableWow64FsRedirection(OldValue);
          if RevertFs then
            ExecCode := Integer(
              ShellExecute(Handle, nil, FileName, nil, nil, SW_SHOW));
        end;
    end;
  finally
    if RevertFs then
      Wow64RevertWow64FsRedirection(OldValue);
  end;
  MsgText :=
    'ShellExecute: $' + IntToHex(ExecCode, 8) + ' (' + IntToStr(ExecCode) +
    ')'#13#10'FsRedirected: ' + BoolToStr(RevertFs, True);
  if ExecCode <= 32 then
    MsgText := MsgText + #13#10#13#10 + SysErrorMessage(ExecCode);
  ShowMessage(MsgText);
end;
Allerdings kann es diverse Probleme geben (Falls die API intern einen neuen Thread erzeugt, dann 'erbt' dieser nicht den Status der File System Redirection. Und falls die API intern DLLs laden muss (32-bit), dann wird dies fehlschlagen, da die 64-Bit DLLs gefunden werden).

Wie Luckie bereits erwähnte, besteht die 'saubere' Lösung aus einer nativen (64-Bit) Version deines Programms (oder der Nutzung eines nativen out-of-process (COM-)Objekts).
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:19 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz