![]() |
Dynamischer Win-API-Call
Hallo zusammen,
ich würde gerne die neue API-Funktion ShutdownBlockReasonCreate nutzen, dazu habe ich eine dynamische Einbindung dieser Funktion gemacht. Leider ist das Result des Aufrufs immer 0/false: -> 'Create ausgeführt + nicht erfolgreich' (sowohl bei der Create- als auch bei der Destroy-Funktion) Vielleicht hat mir jemand einen Tipp?
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; ListBox1: TListBox; procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QueryEndSession; private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} type TSDBlockReasonCreate = function(fHandle: hWnd; pwszReason: LPCWSTR): Boolean; TSDBlockReasonDestroy = function(fHandle: hWnd): Boolean; function VistaPlus: Boolean; begin result := false; case Win32Platform of 2: case Win32MajorVersion of 6: result := true; end; end; end; procedure TForm1.WMQueryEndSession(var Msg: TWMQueryEndSession); var SDBlockReasonCreate: TSDBlockReasonCreate; SDBlockReasonDestroy: TSDBlockReasonDestroy; AppInfoChar, AppInfoWideChar: PWideChar; DLLHandle: THandle; FuncPtr: TFarProc; xInt: Integer; begin inherited; if VistaPlus then begin ListBox1.Items.Add('IsVista'); DLLHandle := LoadLibrary('user32.dll'); FuncPtr := GetProcAddress(DLLHandle, 'ShutdownBlockReasonCreate'); if FuncPtr <> nil then begin ListBox1.Items.Add('Create gefunden'); @SDBlockReasonCreate := FuncPtr; GetMem(AppInfoChar, 255); AppInfoWideChar := StringToWideChar('Testanwendung läuft noch.', AppInfoChar, 255); if SDBlockReasonCreate(Form1.Handle, AppInfoWideChar) = true then ListBox1.Items.Add('Create ausgeführt + erfolgreich') else begin ListBox1.Items.Add('Create ausgeführt + nicht erfolgreich'); ListBox1.Items.Add(IntToStr(GetLastError)); end; FreeMem(AppInfoChar); FuncPtr := nil; end else ShowMessage('Funktion oder DLL nicht gefunden!'); FreeLibrary(DLLHandle); end; for xInt := 25 downto 0 do begin Sleep(1000); if (xInt mod 5 = 0) and (xInt < 25) then ListBox1.Items.Add('Fünftel geschafft'); Label1.Caption := IntToStr(xInt); Application.ProcessMessages; end; if VistaPlus then begin ListBox1.Items.Add('IsVista'); DLLHandle := LoadLibrary('user32.dll'); FuncPtr := GetProcAddress(DLLHandle, 'ShutdownBlockReasonDestroy'); if FuncPtr <> nil then begin ListBox1.Items.Add('Destroy gefunden'); @SDBlockReasonDestroy := FuncPtr; if SDBlockReasonDestroy(Form1.Handle) = true then ListBox1.Items.Add('Destroy ausgeführt + erfolgreich') else begin ListBox1.Items.Add('Destroy ausgeführt + nicht erfolgreich'); ListBox1.Items.Add(IntToStr(GetLastError)); end; FuncPtr := nil; end else ShowMessage('Funktion oder DLL nicht gefunden!'); FreeLibrary(DLLHandle); end; Msg.Result := 1; end; end. |
Re: Dynamischer Win-API-Call
Zitat:
Im MSDN steht If the call succeeds, the return value is nonzero. Lass das = true weg und probiers nochmal. Wenns dann immernoch nicht klappt, koennte das Ergebnis von GetLastError aufschluss geben. greetz Mike |
Re: Dynamischer Win-API-Call
Hallo Mike,
danke, aber das ist es nicht - hatte ich zuerst weg, aber laut MSDN2 müsste exakt 1 (true) zurückgegeben werden. Es funktioniert auch nicht, und GetLastError liefert 0 zurück. |
Re: Dynamischer Win-API-Call
Zitat:
![]() Im MSDN2 steht Return Value If the call succeeds, the return value is nonzero. If the call fails, the return value is zero. To get extended error information, call GetLastError. greetz Mike |
Re: Dynamischer Win-API-Call
Zitat:
Allerdings war das Result von GetLastError 0, was mich auch überraschte und mir leider die Möglichkeit nimmt, das Problem einzugrenzen. :-( Dass ich stdcall auch bei dynamisch eingebundenen DLL-Funktionen nutzen muss, wusste ich nicht. Werde es damit mal kurz probieren. |
Re: Dynamischer Win-API-Call
Super, das hat das Problem gelöst, tausend Dank!
Ist mir jetzt in der Tat etwas peinlich, weil ich auf das stdcall bei DLL-Aufrufen immer zuerst schaue und es bei mir selbst nicht bemerkt habe - aber ich muss gestehen, dass ich bisher alle DLLs statisch eingebunden habe, was diesmal aufgrund der Inkompatibilität zu älteren Systemen logischerweise nicht möglich war! :-) Man lernt nie aus... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:28 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-2025 by Thomas Breitkreuz