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
Antwort Antwort
Mr.Sade

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

Looking 4 help

  Alt 25. Feb 2003, 03:14
does anybody understand english here ?
sorry, I dont know how to read german, just English and Spanish.
if so, I looking for your help!!
thank you
Mr.Sade
  Mit Zitat antworten Zitat
Benutzerbild von Darty
Darty

Registriert seit: 8. Jun 2002
Ort: Kronau
731 Beiträge
 
#2
  Alt 25. Feb 2003, 07:44
Sure, anyone would understand english. You don't found help in your language ?
Matthias Knebel
Mfg M. Knebel [-Darty-]
- Gehörlose Delphianer gibt es selten -
www.team-knebel.de
  Mit Zitat antworten Zitat
Mr.Sade

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

Cool :)

  Alt 25. Feb 2003, 08:53
I have look for help in my language, but they have not work on Hooks, Subclassing, and MMF.

I would like to Subclass Notepad, I have set a CBT hook to know when windows are created and destroyed.
If the window's created class is equal to "Notepad" I subclass it and store some values on Memory with MMF to share the data.
Inside my new Notepad WNDPROC function I add a dynamic menu to it, and when I click in it, I will show a messagebox like You clicked item 1, etc.

Everything works good with with 1 instance, but when I open more than one instance of notepad it crashes.
I think I need an array to stored the values that SetWindowLong returns
for each instance of Notepad
If someone would like to help me to finish my proyect I will send you my Dll Code.
It's about Hooks, Subclassing and MMF.
Thanks

P.S: my ICQ number is you would like to contact me: 102211848
Mr.Sade
  Mit Zitat antworten Zitat
janjan

Registriert seit: 16. Jan 2003
Ort: Bonn ("links über Königswinter ")
240 Beiträge
 
Delphi 4 Standard
 
#4
  Alt 25. Feb 2003, 09:15
Have you ever tried http://www.experts-exchange.com/?
Die Wichtigkeit eines Postings im Forum ist reziprok zur Anzahl der enthaltenenen, kumulierten Ausrufungszeichen!!!
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#5
  Alt 25. Feb 2003, 10:23
Hello MrSade,
even english speaking members are always welcome in this message board. But we would appreciate it if you would choose a better title for your thread next time.

Concerning your problem: The first step would be to use an array of pointer for the values that are returned by SetWindowLong. But the problem which instance of Notepad is activated still remains. For that problem I don't know a solution either - sorry.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Mr.Sade

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

SetWindowLong and GWL_USERDATA error

  Alt 27. Feb 2003, 09: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
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#7
  Alt 27. Feb 2003, 14:15
procedure:
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;
Does Win^.OldPtr really have a valid value? Try this:
Win^.OldPtr := PWinInfo(GetWindowLong(Handle, GWL_USERDATA));
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Mr.Sade

Registriert seit: 25. Feb 2003
17 Beiträge
 
Delphi 6 Enterprise
 
#8
  Alt 27. Feb 2003, 19:48
Hello people

I think all is working now.
I haven't try it with delphi, because I am at school right now,
but I will do it later, when I get home.
I have ported my delphi code to assembly language, MASM32
and I have change some parts and it works good

the parts that I changed are:
Delphi-Quellcode:
procedure NotepadCreated(Handle: HWND);
var
  OldPtr: Integer;
begin
  { invoke  SetWindowLong, Handle, GWL_WNDPROC, ADDR NotepadProc
    invoke  SetWindowLong, Handle, GWL_USERDATA, eax  }


  { lets subclass it and assign pointer }
  OldPtr := SetWindowLong(Handle, GWL_WNDPROC, Integer(@NotepadProc));
  SetWindowLong(Handle, GWL_USERDATA, OldPtr);
end;
and when cleaning everything:
Delphi-Quellcode:
{ EnumWins proc Handle:DWORD, lParam:LPARAM
    invoke  RtlZeroMemory, ADDR Buffer, 256
    invoke  GetClassName, Handle, ADDR Buffer, 256
    invoke  lstrcmpi, ADDR Buffer, ADDR Notepad
    .IF eax == 0
        invoke  SendMessage, Handle, WM_STOPSUBCLASSING, 0, 0
    .ENDIF
    mov    eax, TRUE
    ret
EnumWins endp }

function EnumWins(Handle: HWND; lParam: LPARAM): Boolean;
    stdcall;
var
  szClass: array [0..256] of Char;
begin
  ZeroMemory(@szClass, 256);
  GetClassName(Handle, szClass, 256);
  if szClass = 'Notepadthen
    SendMessage(Handle, WM_STOPSUBCLASSING, 0, 0);
  Result := True;
end;

Inside NotepadWndProc:
Delphi-Quellcode:
  { Msg == WM_STOPSUBCLASSING
      invoke  GetWindowLong, Handle, GWL_USERDATA
      invoke  SetWindowLong, Handle, GWL_WNDPROC, eax  }

  WM_STOPSUBCLASSING:
  begin
    OldPtr := GetWindowLong(Handle, GWL_USERDATA);
    SetWindowLong(Handle, GWL_WNDPROC, OldPtr);
  end;

so if it works with MASM, it should work with Delphi6
Thank You for your time
Mr.Sade
  Mit Zitat antworten Zitat
jbg

Registriert seit: 12. Jun 2002
3.483 Beiträge
 
Delphi 10.1 Berlin Professional
 
#9
  Alt 27. Feb 2003, 20:00
Zitat:
EnumWin:
Delphi-Quellcode:
  if szClass = 'Notepadthen
  begin
    Win := PWinInfo(GetWindowLong(Handle, GWL_USERDATA));
    { set back ptr } 
    SetWindowLong(Handle, GWL_WNDPROC, Win^.OldPtr);
    { free memory } 
    Dispose(Win);
  end;
I see the problem within Dispose(). Dispose uses the memory manager of the calling process. But your Hook-Dll is executed in many processes. So what you do in this code is freeing memory not allocated by this process.
  Mit Zitat antworten Zitat
Antwort Antwort


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 02:18 Uhr.
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