Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi WlanRegisterNotification Problem (https://www.delphipraxis.net/102839-wlanregisternotification-problem.html)

nitschchedu 5. Nov 2007 20:54


WlanRegisterNotification Problem
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo Leute,
wie sicherlich schon einige mitbekommen und auch mit gewirkt haben, an der WLanAPI, ist mal wieder ein Probelm aufgetreten.
Also wie im Titel schon erwähnt geht es um die WlanRegisterNotification.

Volgendes habe ich gemacht.

Delphi-Quellcode:

procedure WLanNotifyProc(pNotifyData: Pndu_WLAN_NOTIFICATION_DATA;
   pContext: PVOID);
begin
   if pNotifyData.NotificationSource = NDU_WLAN_NOTIFICATION_SOURCE_ACM then
  begin
     if Tndu_WLAN_NOTIFICATION_ACM(pNotifyData.NotificationCode) = wlan_notification_acm_scan_complete then
    begin
       SetEvent(THandle(pContext));
    end;
  end;
end;


procedure .... ;
var
  hClient: THandle;
  hScanCompleteEvent: THandle;
  back: DWORD;
begin
  .....
  hScanCompleteEvent := CreateEvent(nil, False, False, nil);
 
  back := WlanRegisterNotification(hClient, NDU_WLAN_NOTIFICATION_SOURCE_ALL,
     True, @WLanNotifyProc, @hScanCompleteEvent, nil, nil);

  ...
 
  if back <> ERROR_SUCCESS then
  begin
     Memo1.Lines.Add('Fehler bei WlanRegisterNotification');
     Exit;
  end;

  back := WlanScan(hClient, @pInterface.InterfaceInfo[0].InterfaceGuid,
     nil, nil, nil);

  if back <> ERROR_SUCCESS then
  begin
     Memo1.Lines.Add('Fehler bei WlanScan');
     Exit;
  end;

  WaitForSingleObject(hScanCompleteEvent, INFINITE);

  ....
end;
So das Problem:
In der Procedure "WLanNotifyProc" wo ich auch schön reinspringe, bekomme ich in der Variable "pNotifyData"
nur Müll und somit komme ich bei "WaitForSingleObject" nicht weiter :-(.

Ich hoffe es kann mir jemand weiter Helfen.
PS: Habe unten noch ein Bild mit dem was im Speicher ist angehangen.

nitschchedu 6. Nov 2007 19:54

Re: WlanRegisterNotification Problem
 
Ok da keiner Antwortet will ich meine Frage anders stellen.
Kann ich einfach eine Procedure Deklarieren und dann mit @name auf PVoid übergeben ?

So ist es in C++ Deklariert.

Code:
// the callback function for notifications
typedef VOID (WINAPI *WLAN_NOTIFICATION_CALLBACK) (PWLAN_NOTIFICATION_DATA, PVOID);


....

DWORD WINAPI
WlanRegisterNotification(
    __in HANDLE hClientHandle,
    __in DWORD dwNotifSource,
    __in BOOL bIgnoreDuplicate,
    __in_opt WLAN_NOTIFICATION_CALLBACK funcCallback,
    __in_opt PVOID pCallbackContext,
    __reserved PVOID pReserved,
    __out_opt PDWORD pdwPrevNotifSource
);
Und meine :

Delphi-Quellcode:
PVOID                     = Pointer;            ///C PVoid
Tndu_WLAN_NOTIFICATION_CALLBACK   = PVOID;

function WlanRegisterNotification(hClientHandle: Handle;
     dwNotifSource: DWORD; bIgnoreDuplicate: Bool;
    funcCallback: Tndu_WLAN_NOTIFICATION_CALLBACK;
    pCallbackContext: PVOID; pReserved: PVOID;
    pdwPrevNotifSource: PDWORD): DWORD; stdcall;

Muetze1 6. Nov 2007 23:40

Re: WlanRegisterNotification Problem
 
Na endlich etwas womit man eine Antwort definieren kann ohne sich erstmal die MSDN installieren zu müssen...

Warum definierst du dir keinen Callback Prototypen?

Delphi-Quellcode:
type
    // Deklaration von WLAN_NOTIFICATION_DATA fehlt noch...
    // durch das Var entfällt das Pxxx
  WLAN_NOTIFICATION_CALLBACK = procedure(var WLAN_Notification_Data: ???; pCallbackContext: Pointer);

function WLanRegisterNotification(hClientHandle: THandle; dwNotifySource: LongWord; bIgnoreDuplicate: LongBool;
  FuncCallBack: WLAN_NOTIFICATION_CALLBACK; pCallbackContext: Pointer; pReserved: Pointer; var pdwPrevNotifySource: LongWord): LongWord; stdcall;

negaH 7. Nov 2007 05:58

Re: WlanRegisterNotification Problem
 
typedef void WINAPI*...

dh. deine Callback sollte wohl stdcall sein ?

Delphi-Quellcode:
procedure WLanNotifyProc(pNotifyData: Pndu_WLAN_NOTIFICATION_DATA; pContext: PVOID); stdcall; // <--
begin
.... bla bla
end;
Gruß Hagen

nitschchedu 7. Nov 2007 07:18

Re: WlanRegisterNotification Problem
 
Omg es geht auf das stdcall wäre ich wohl nie gekommen .... Danke :thumb:
Und das mit dem Callback Prototypen ist auch keine schlechte Idee ! ;-)

Edit: Und schon gibt es ein neues Problem :-(

Ich komme bei WaitForSingleObject(hScanCompleteEvent, INFINITE); nicht weiter.

Muetze1 7. Nov 2007 09:29

Re: WlanRegisterNotification Problem
 
Zitat:

Zitat von nitschchedu
Ich komme bei WaitForSingleObject(hScanCompleteEvent, INFINITE); nicht weiter.

Das heisst?

nitschchedu 7. Nov 2007 09:45

Re: WlanRegisterNotification Problem
 
Also beim Debugen komme ich zu den Punkt
Delphi-Quellcode:
WaitForSingleObject(hScanCompleteEvent, INFINITE);
dann sage ich geh weiter (damit muss er dort anhalten) ... springe nach einer weile in
Delphi-Quellcode:
procedure WLanNotifyProc(pNotifyData: Pndu_WLAN_NOTIFICATION_DATA;
   pContext: PVOID);
wo ich wieder sage
Delphi-Quellcode:
SetEvent(THandle(pContext));
damit er bei
Delphi-Quellcode:
WaitForSingleObject(hScanCompleteEvent, INFINITE);
weiter geht ... aber nix passiert :-(

Weil er muss an der der Stelle warten bis das Scannen fertig ist und dann darf er weiter gehen.

sirius 7. Nov 2007 09:53

Re: WlanRegisterNotification Problem
 
Wird WlanRegisterNotification in einem eigenen Thread ausgeführt?

nitschchedu 7. Nov 2007 09:55

Re: WlanRegisterNotification Problem
 
Jop und zwar von der WlanAPI selbst ... also ich könnte ich nur die Procedure REgistrieren und wenn jemand anders Scant springt er bei mir rein.

Muetze1 7. Nov 2007 09:56

Re: WlanRegisterNotification Problem
 
Das Problem ist einfach nur, dass das Handle von SetEvent() nicht stimmt. Der Result wird dir das bestätigen.

Du übergibst beim Aufruf ein @Handle, also die Adresse der Variable mit dem handle und im CallBack nutzt du den Pointer direkt als Handle.

Also entweder beim Aufruf Pointer(Handle) und Callback so lassen oder im CallBack PHandle(pContext)^ nutzen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:02 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz