2

SendMessageTimeout 呼び出しが失敗した (つまり、0 を返した) が、その後の GetLastError が 0 (成功) を返した場合、呼び出しが失敗した理由を特定する方法はありますか?

私が使用しているコード (以下) は、数十人のユーザーに対しては正常に動作しますが、2 人のユーザーに対しては、上記の最初の文で説明したように SendMessageTimeout が失敗します。

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);
...
4

0 に答える 0