AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Looking 4 help

Ein Thema von Mr.Sade · begonnen am 25. Feb 2003 · letzter Beitrag vom 27. Feb 2003
 
Mr.Sade

Registriert seit: 25. Feb 2003
17 Beiträge
 
Delphi 6 Enterprise
 
#6

SetWindowLong and GWL_USERDATA error

  Alt 27. Feb 2003, 08:06
Hello people

I'm sorry about the title

I'm having another problem.
I'm using SetWindowLong with GWL_USERDATA to store a pointer, doing that I dont have to declare a dinamic array to store the values returned by SetWindowLong and GWL_WNDPROC.
So I have this to store a pointer to the window:

Delphi-Quellcode:
procedure NotepadCreated(Handle: HWND);
var
  Win: PWinInfo;
begin
  New(Win);
  Win^.Handle := Handle;
  Win^.OldPtr := GetWindowLong(Handle, GWL_WNDPROC);
  { lets subclass it }
  SetWindowLong(Handle, GWL_WNDPROC, Integer(@NotepadProc));
  { assign pointer to window }
  SetWindowLong(Handle, GWL_USERDATA, Integer(@Win));
end;
when the hook sends me a message that notepad is clossing I have this:
Delphi-Quellcode:
procedure NotepadDestroyed(Handle: HWND);
var
  Win: PWinInfo;
begin
  Win := PWinInfo(GetWindowLong(Handle, GWL_USERDATA));
  { set oldptr back}
  SetWindowLong(Handle, GWL_WNDPROC, Win^.OldPtr);
  { free memory pointer}
  Dispose(Win);
end;
Well, that works good.
The problem is when closing my application.
I have to set back all notepad pointers so I call CleanNotepadPtrs.
Delphi-Quellcode:
function EnumWins(Handle: HWND; lParam: LPARAM): Boolean;
    stdcall;
var
  szClass: array [0..256] of Char;
  Win: PWinInfo;
begin
  ZeroMemory(@szClass, 256);
  GetClassName(Handle, szClass, 256);
  if szClass = 'Notepadthen
  begin
    Win := PWinInfo(GetWindowLong(Handle, GWL_USERDATA));
    { set back ptr }
    SetWindowLong(Handle, GWL_WNDPROC, Win^.OldPtr);
    { free memory }
    Dispose(Win);
  end;
  Result := True;
end;

procedure CleanNotepadPtrs;
begin
  EnumWindows(@EnumWins, 0);
end;
Well, You see, It's the same as before, but Notepad crashes.
do you know what could I been doing wrong ?
I have also tried to send a message inside NotePadWndProc and
read the pointer (GWL_USERDATA) and then that sets back the pointer (GWL_WNDPROC), but also causes an error

Thank You.
Mr.Sade
  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 21:25 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