Periodically getting an access violation from a PeekMessage. This is not my call to PeekMessage, it's from Application.Run. Stack trace from MadExcept shows Application.Run calling PeekMessage which in turn is calling kiUserCallBackDispatcher.
Delphi 2009.
Stack trace is:
callstack crc : $0202d0d7, $a09d5671, $3195cde5
exception number : 1
exception class : EAccessViolation
exception message : Access violation at address 0202D0D7. Write of address 00310038.
main thread ($1650):
0202d0d7 +000 ???
7c90e470 +010 ntdll.dll KiUserCallbackDispatcher
7e4193fd +162 USER32.dll PeekMessageW
0050b2a4 +01c infraWrapper90.exe Forms TApplication.ProcessMessage
0050b3ea +00a infraWrapper90.exe Forms TApplication.HandleMessage
0050b715 +0c9 infraWrapper90.exe Forms TApplication.Run
I assume this means that PeekMessage() is making a call to one of one my Window Procedures to process a message, and it can't find that Window procedure. At first I didn't see why Peekmessage would be calling any window procedure as it is just peeking at messages but from futher reading on here and elsewhere I think I see that:
- PeekMessage() will process SendMessages() sent from other threads
- PeekMessage() will sometimes handle Paint messages
- Someone else has reported seeing PeekMessage calling a Window procedure for other messages, such as WM_ERASEBKGND.
From MSDN:
During this call, the system delivers pending, nonqueued messages, that is, messages sent to windows owned by the calling thread using the
SendMessage
,SendMessageCallback
,SendMessageTimeout
, orSendNotifyMessage
function.
Which I don't quite understand as I thought SendMessage() calls were handled immediately. Someone else seemed to think this only applied when the SendMessage was from another thread.
I can't duplicate this in a stand alone project. From the error it appears as if PeekMessage is calling a Window Procedure which no longer exists - but I've tried doing this myself by intentionally destroying a form then doing a SendMessage() and Postmessage() to an invalid window handle and Windows just seems to ignore it. I've tried posting messages from a form's destructor to itself and all sorts of other things but I can't get it to fail.
Any suggestions as to anything else to check? Thanks in advance.
Rick