News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

OllyDbg and LastErr

Started by jj2007, April 10, 2008, 09:57:43 AM

Previous topic - Next topic

jj2007

I have run into (just another) odd behaviour of the RichEdit control: EM_SETPARAFORMAT returns ERROR_INVALID_HANDLE, code 6, although the handle is perfectly valid, and although the message performs what it is supposed to do, i.e. the para gets properly formatted.
So you might ask if it does the job, where's the problem?
Curiosity, curiosity...! So I tried to isolate the problem using Olly - see snippet below (the args are not being used).
Question: Is there any way to let Olly stop when LastErr is being set in the Registers window? That message takes ages in animation mode, and I always miss the point when LastErr is being set...

SetParaFormat proc ParaFt:DWORD, ParaFtMask:DWORD
LOCAL pf2:PARAFORMAT2
  call ClearLocals ; zero-initialises the PARAFORMAT2 structure
  ; int 3 ; for launching Olly
  mov pf2.cbSize, sizeof pf2
  mov pf2.dwMask, PFM_RIGHTINDENT or PFM_SPACEBEFORE or PFM_SPACEAFTER
  mov pf2.dySpaceBefore, 100
  mov pf2.dySpaceAfter, 150
  invoke SendMessage, hRE, EM_SETPARAFORMAT, 0, addr pf2
  .if eax
invoke ShowWinErr, chr$("SetPara") ; will complain about error 6
  .endif
  ret
SetParaFormat endp

Tedd

Quote
EM_SETPARAFORMAT

Return Value
    If the operation succeeds, the return value is a nonzero value.
    If the operation fails, the return value is zero.

There is no error.
If the function succeeds, the LastErr value is meaningless - ignore it.
(And change your error check to "if !eax" or "if eax==0" :P)


For the record: if you want to 'catch' where LastErr is set, it's generally set using the "SetLastError" function, so you could set a breakpoint on that function and see where it returns to/is called from. (The 'LastErr' value is whatever gets returned by "GetLastErorr()")
No snowflake in an avalanche feels responsible.

jj2007

Thanx, interesting... so somewhere in the deep deep depth of Windows the EM_SETPARAFORMAT produces an error (always, apparently), but it succeeds nonetheless.

Tedd

Not necessarily - EM_SETPARAFORMAT may never even touch the LastErr value, it could've been left over from some previous unrelated error. Ignore the value UNLESS you're given a failure indication.
No snowflake in an avalanche feels responsible.

jj2007

Quote from: Tedd on April 11, 2008, 12:38:18 PM
Not necessarily - EM_SETPARAFORMAT may never even touch the LastErr value, it could've been left over from some previous unrelated error. Ignore the value UNLESS you're given a failure indication.

I checked before the call, LastErr is clean. I happens inside the call, and it happens always...