If a SendMessageTimeout call fails (i.e., returns 0), but a subsequent GetLastError returns 0 (success), is there any way to determine why the call failed?
The code I'm using (below) works fine for dozens of our users but for two users the SendMessageTimeout fails as described in the first sentence above.
function TQBInfo.GetFormCellText(bTestForCaret: boolean = True): string;
const
BUFSIZE = 4096;
TIMEOUT_MSECS = 4000;
var
Wnd: HWnd;
dwResult: DWORD;
buf: array of char;
sLastErrorText: string;
begin
Result := '';
Wnd := GetEditControlWindow; //Custom function to find the target window
if Wnd = 0 then
exit;
SetLastError(0);
FLastError_GetFormCellText := 0; //FLastError_GetFormCellText is an object field
SetLength(buf, BUFSIZE + 1);
if SendMessageTimeout(Wnd, WM_GETTEXT, BUFSIZE + 1, LongInt(@buf[0]),
SMTO_ABORTIFHUNG or SMTO_BLOCK,
TIMEOUT_MSECS,
dwResult) = 0 then begin //0 = Failed or timed out
FLastError_GetFormCellText := GetLastError;
//...at this point, FLastError_GetFormCellText is always 0 in the failure case I'm seeing
if FLastError_GetFormCellText = ERROR_TIMEOUT then
sLastErrorText := 'ERROR_TIMEOUT'
else
sLastErrorText := SysErrorMessage(FLastError_GetFormCellText);
...