delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

lParam contains the address to the struct TMessage.
The C++ equivalent code for converting the lParam value to the MSG type will be
Code:

MSG * msg = (MSG*)lParam;
but how would i do this in Delphi http://bbs.prog365.com/images/sites/frown.gif


I am receiving address of the TMessage struct in a variable named lParam. But i am unable to use this address into a pointer of TMessage Type.
delphi Code:
[url=#top]
[/url]Original
                - delphi Code
var
    msg : ^TMessage;
//------------------
function fnGlobalWindowsActivateHook (code:Integer; wParam:Word; lParam:LongWord): LongWord; stdcall;
begin
    msg := lParam;
end;
  1. var
  2.     msg : ^TMessage;
  3. //------------------
  4. function
  5. fnGlobalWindowsActivateHook
  6. (
  7. code:
  8. Integer
  9. ; wParam:
  10. Word
  11. ; lParam:
  12. LongWord
  13. )
  14. :
  15. LongWord
  16. ; stdcall;
  17. begin
  18.     msg := lParam;
  19. end
  20. ;
Copy Code
lParam contains the address to the struct TMessage.
The C++ equivalent code for converting the lParam value to the MSG type will be
Code:
  1. MSG * msg = (MSG*)lParam;
Copy Code
but how would i do this in Delphi

TOP

Try
delphi Code:
[url=#top]
[/url]Original
                - delphi Code
var
    msg : TMessage;
//------------------
function fnGlobalWindowsActivateHook (code:Integer; wParam:Word; lParam:LongWord): LongWord; stdcall;
begin
    msg := TMessage(lParam);
end;
  1. var
  2.     msg : TMessage;
  3. //------------------
  4. function
  5. fnGlobalWindowsActivateHook
  6. (
  7. code:
  8. Integer
  9. ; wParam:
  10. Word
  11. ; lParam:
  12. LongWord
  13. )
  14. :
  15. LongWord
  16. ; stdcall;
  17. begin
  18.     msg := TMessage
  19. (
  20. lParam
  21. )
  22. ;
  23. end
  24. ;
Copy Code
You might need to define lparam as Integer rather than LongWord.
Clive

TOP

well, i can't change the method signature since it is required by win32 API that the callback function should have the following signature.
However, i tried this to typecast but failed
Delphi Code:
[url=#top]
[/url]Original
                - Delphi Code
msg := TMessage(lParam);
  1. msg := TMessage
  2. (
  3. lParam
  4. )
  5. ;
Copy Code

TOP

What is the Windows API call and what is the Windows callback called?
I could find no references anywhere to anything called
fnGlobalWindowsActivateHook

TOP

abstract:

lParam contains the address to the struct TMessage.
The C++ equivalent code for converting the lParam value to the MSG type will be
Code:

MSG * msg = (MSG*)lParam;
but how would i do this in Delphi http://bbs.prog365.com/images/sites/frown.gif



Originally Posted by clivew
What is the Windows API call and what is the Windows callback called?
I could find no references anywhere to anything called
fnGlobalWindowsActivateHook
well fnGlobalWindowsActivateHook is my callback function.
The main functions are setwindowshookex - this is win32 function and you can find it's documentation. in documentation it is listed that i can hook number of global message that windows process. among those message one message is WH_GETMESSAGE. to receive that message i have to give "setwindowshookex" a pointer to a function, so that windows can call that function (which would be written by me before calling default routine). now that function has to have the following signature
delphi Code:
[url=#top]
[/url]Original
                - delphi Code
function anyFunctionName (code:Integer; wParam:Word; lParam:LongWord): LongWord; stdcall;
  1. function
  2. anyFunctionName
  3. (
  4. code:
  5. Integer
  6. ; wParam:
  7. Word
  8. ; lParam:
  9. LongWord
  10. )
  11. :
  12. LongWord
  13. ; stdcall;
Copy Code
and in my case the anyFunctionName = fnGlobalWindowsActivateHook
now the documentation of WH_GETMESSAGE says that i'll receive the address to the struct of type MSG. that is the problem where i have been stuck. I want to convert that pointer of MSG to the Delphi corresponding record/strcut so that i may receive the remaining informaiton.

TOP

ok the specigfic problem is solved.
it should be
delphi Code:
[url=#top]
[/url]Original
                - delphi Code
var
   msg : TMsg;
begin
   msg := PMsg (lParam)^;
  1. var
  2.    msg : TMsg;
  3. begin
  4.    msg := PMsg
  5. (
  6. lParam
  7. )
  8. ^;
Copy Code
Thanks

TOP

Glad you have your solution.
I would recommend that next time you include the API call for which this is the callback function in your original post.
Without that information it is hard for us to be sure to what those method parameters refer and, therefore, to figure out where the error occurs.
We have nothing to go on but what you post
Clive

TOP

Thanks Clive. I'll surely keep this in mind while posting next time



lParam contains the address to the struct TMessage.
The C++ equivalent code for converting the lParam value to the MSG type will be
Code:

MSG * msg = (MSG*)lParam;
but how would i do this in Delphi http://bbs.prog365.com/images/sites/frown.gif

TOP

Back Forum