Author Topic: EM_EXSETSEL problem...  (Read 26203 times)

PsYcHoCoDe

  • Guest
EM_EXSETSEL problem...
« on: September 21, 2012, 09:31:21 PM »
- what i'm trying to actually do: implement search algo (already did it), from a secondary DlgProc (separate dialog, of course), then display the result as a MARKED/SELECTED TEXT in the ascii buffer of the rich edit control using EM_EXSETSEL (this should 'select the defined text, right?)...
- what actually happens: if result is found, the secondary dlgProc closes the dlg, storing the found result's RVA (it's GlobalAlloc'd buff) in a global dword... after that the MAIN dlg proc call the calculation of parameters and actually sending the msg (posted just below is this proc...)...
- result of SendMessageTimeout: returns TRUE (it worked?!), GetLastError: (ERROR_ACCESS_DENIED)... and there's no text actually being selected in the richedit == it actually didn't worked...

- yeah, this is my first meeting with RICHEDIT controls' coding, i'm not really into sophisticated gui stuff usually...

P.S.: yep, i've tryed to load the structure (wParam of msg) with RVA's, tried it with OFFSET's too... nothing happens in both occasions... any ideas, guys?!

MarkFoundString PROC rvaFound:DWORD
LOCAL dwTemp:DWORD
LOCAL rChar:CHARRANGE
    invoke szLen, addr srchString
    mov edx, txtAddr
    mov ecx, rvaFound
    sub ecx, edx ; getting offsets...
    mov rChar.cpMin, ecx
    add eax, ecx
    mov rChar.cpMax, eax
    invoke SendMessageTimeout, hTxt, EM_EXSETSEL, 0, addr rChar, SMTO_NORMAL, 30*1000, addr dwTemp
    ret
MarkFoundString ENDP

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1196
Re: EM_EXSETSEL problem...
« Reply #1 on: September 21, 2012, 09:51:32 PM »
If SendMessageTimeout returned true, then the function succeeded and your call to GetLastError is meaningless, because functions that succeed do not necessarily clear the last-error code value. You can test this by using SetLastError to clear the last-error code value immediately before the SendMessageTimeout call.
Well Microsoft, here’s another nice mess you’ve gotten us into.

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #2 on: September 21, 2012, 09:56:15 PM »
@MichaelW, yes, i know about that, so it's tested... by saying the SendMessageTimeout returns GetLastError, i actually mean that the particular function returns this last error...i always do that, when necessary  :t

P.S: OS = Windows 2009 Embedded (xp-alike), SDK = masm v10 with ml v.10x and updated linker (ms link.exe)...  + i always check everything with immunity dbgr... ;)

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: EM_EXSETSEL problem...
« Reply #3 on: September 22, 2012, 01:06:05 AM »
Why are using  SendMessageTimeout()? - AFAICS it makes only sense, if the destination window is created from another thread - otherwise it behaves like SendMessage().
MREAL macros - when you need floating point arithmetic while assembling!

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #4 on: September 22, 2012, 01:21:45 AM »
@qWord: sometimes hepled me in the past, so i just thought it'ld be kinda 'safer' if i use the timeout... now as u mention it, yeah, it doen't really make much sense, indeed... i just need to get it done somehow, though... maybe i should indeed try this with 'plain' SendMessage?

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #5 on: September 22, 2012, 06:16:18 PM »
come on, won't someone giva a actual solution to this?! :redface:

sinsi

  • Guest
Re: EM_EXSETSEL problem...
« Reply #6 on: September 22, 2012, 06:38:45 PM »
Well, what are srchString, txtAddr and rvaFound?
Not enough code.

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #7 on: September 22, 2012, 06:55:11 PM »
@sinsi: srchString is  a pointer, txtAddr & rvaFound too are pointers, mate ;)Allocated , using GlobalAlloc..

sinsi

  • Guest
Re: EM_EXSETSEL problem...
« Reply #8 on: September 22, 2012, 07:12:34 PM »
Pointers to what?

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #9 on: September 22, 2012, 07:19:50 PM »
srchString is a pointer to default allocated memory. rvaFound is too the same... txtAddr ir allocated using GlobalAlloc...

P.S: everithin's either dinamically allocated(the usual idea), or statically defined inside the source...  8)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: EM_EXSETSEL problem...
« Reply #10 on: September 22, 2012, 07:56:45 PM »
Psycho,

If successful search in a richedit control is what you are after, look in the example code of MASM32, "example06\riched". It works fine.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #11 on: September 22, 2012, 11:42:06 PM »
i just tested it with using SendMessage api instead of sendMessageTimeout... it seems the same - LastError == ERROR_ACCESS_DENIED....

@hutch:  of the examples seems that it's actually using offsets, so i didi it that way... alas, still ain't working...

P.S.: eax == 05h and LastError == ERROR_ACCESS_DENIED...

any ideas about that?! (it's being called from the main dialog procedure, that manages the actual richedit controls)...

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: EM_EXSETSEL problem...
« Reply #12 on: September 23, 2012, 02:11:48 AM »

At this time , the ACCESS is only DENIED to your code.
To got an answer post it here.
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: EM_EXSETSEL problem...
« Reply #13 on: September 23, 2012, 02:51:47 AM »
Psycho,

Your problem can have a dozen different causes. RichEd is an ill-mannered pig, but your chances are good to get an answer because both hutch and myself (and I guess, a few others here) have an awful lot of (bad) experience with RichEd.

However, guessing is not our strong point. Strip your code from anything that you consider valuable and/or confidential, and post the complete source.

Cheers,
jj

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #14 on: September 23, 2012, 03:18:37 AM »
alas, i pasted ony this piece, cuz almost all of anything else would be considered confidential atm... :/ if it wasn't i would upload somewere the whole thing and post a link... :/

P.S: ye, i wouldn't really mess with richedit items, if i have hadn't do it that way...