Clive Richmond
4-Sep-2018, 05:05 AM
We have a method to process certain messages in the windows queue using PeekMessage. The original source was from a package published by Christian Berkhout and later modified by Garret Mott (https://support.dataaccess.com/Forums/showthread.php?1002-Modified-ProcessMessages-Package&highlight=processmessages).
Since it uses GetBuff we decided to update it for 19.1. However, the new code will eventually crash triggering an 'Access violation error.' Not sure what have missed but does anyone know how to fix it?
Old Code.
TYPE tMsg
Field tMsg.hwnd As Handle
Field tMsg.message As Integer
Field tMsg.wParam As Integer
Field tMsg.lParam As Integer
Field tMsg.Time As DWord
Field tMsg.pt As Pointer
END_TYPE
Function ProcessMessage GLOBAL Returns Boolean
Boolean bMessageFound bTemp
Pointer pMsg
Integer iPendingMessage
String sMsg
Move (False) To bMessageFound
ZeroType tMsg To sMsg
Move (AddressOf(sMsg)) To pMsg
If (PeekMessage(pMsg, 0, 0, 0, PM_REMOVE)) Begin
GetBuff From sMsg at tMsg.message To iPendingMessage
If (iPendingMessage = WM_PAINT) Begin
Move (True) To bMessageFound
Move (TranslateMessage(pMsg)) To bTemp
Move (DispatchMessage(pMsg)) To bTemp
End
End
Function_Return bMessageFound
End_Function // ProcessMessage
New Code.
Use tWinStructs.pkg
Struct tMsg
Handle hWndOwner
Integer iMessage
Integer wParam
Integer lParam
DWord dwTime
tWinPoint ltPoint
DWord dwPrivate
End_Struct
Function ProcessMessage GLOBAL Returns Boolean
tMsg ltMsg
Boolean bMessageFound bTemp
Pointer pMsg
Move (False) To bMessageFound
Move (AddressOf(ltMsg)) To pMsg
If (PeekMessage(pMsg, 0, 0, 0, PM_REMOVE)) Begin
If (ltMsg.iMessage = WM_PAINT) Begin
Move (True) To bMessageFound
Move (TranslateMessage(pMsg)) To bTemp
Move (DispatchMessage(pMsg)) To bTemp
End
End
Function_Return bMessageFound
End_Function
Since it uses GetBuff we decided to update it for 19.1. However, the new code will eventually crash triggering an 'Access violation error.' Not sure what have missed but does anyone know how to fix it?
Old Code.
TYPE tMsg
Field tMsg.hwnd As Handle
Field tMsg.message As Integer
Field tMsg.wParam As Integer
Field tMsg.lParam As Integer
Field tMsg.Time As DWord
Field tMsg.pt As Pointer
END_TYPE
Function ProcessMessage GLOBAL Returns Boolean
Boolean bMessageFound bTemp
Pointer pMsg
Integer iPendingMessage
String sMsg
Move (False) To bMessageFound
ZeroType tMsg To sMsg
Move (AddressOf(sMsg)) To pMsg
If (PeekMessage(pMsg, 0, 0, 0, PM_REMOVE)) Begin
GetBuff From sMsg at tMsg.message To iPendingMessage
If (iPendingMessage = WM_PAINT) Begin
Move (True) To bMessageFound
Move (TranslateMessage(pMsg)) To bTemp
Move (DispatchMessage(pMsg)) To bTemp
End
End
Function_Return bMessageFound
End_Function // ProcessMessage
New Code.
Use tWinStructs.pkg
Struct tMsg
Handle hWndOwner
Integer iMessage
Integer wParam
Integer lParam
DWord dwTime
tWinPoint ltPoint
DWord dwPrivate
End_Struct
Function ProcessMessage GLOBAL Returns Boolean
tMsg ltMsg
Boolean bMessageFound bTemp
Pointer pMsg
Move (False) To bMessageFound
Move (AddressOf(ltMsg)) To pMsg
If (PeekMessage(pMsg, 0, 0, 0, PM_REMOVE)) Begin
If (ltMsg.iMessage = WM_PAINT) Begin
Move (True) To bMessageFound
Move (TranslateMessage(pMsg)) To bTemp
Move (DispatchMessage(pMsg)) To bTemp
End
End
Function_Return bMessageFound
End_Function