News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Iczelion tutorial 35 Highlighting

Started by Fumio, September 17, 2013, 02:58:20 PM

Previous topic - Next topic

qWord

There is a missing RET in NewRichEditProc. You should also add a stack probe to that callback, because of the large buffer (more than 2 pages). Also, the USES directive for ESI, EDI and EBX would make the code more clear.

EDIT: BufferSize @ NewRichEditProc is filled with the buffer address!
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Still crashing. There are also three pushads but four popads in that proc, but that's not the cause (there's a break in one of the branches).

This helps:
ScanMore:
                repne scasb
                ; je NextSkip
                jmp NoMoreHit

... but that's not a solution, of course. The crash happens after the rep scasb. Check the ecx value in particular.

Fumio

Hello jj2007: Here is another clue. As noted, dedndave's bat file allows the exe to compile and work fine; however, if the /STACK:2000000,2000000 is removed from the link options in the bat file the program builds and crashes. I have not been able to build in Radasm with the /STACK:2000000,2000000  option but only with the
option /STACK:2000000, although the number must be in its hex form I believe the problem is not in the code but in the linker
Fumio

Fumio

Hello: Remembered the Radasm foible of using a | in place of a comma to use option /STACK:2000000, 2000000. the program still crashes, but it is definitely doing something different. The window displays with green gibberish in top left corner and two alerts that the program has stopped working appear.

jj2007

The stack error is only a symptom of a deeper problem.
ca. line 900:
      pop edi
      .while sdword ptr esi>0  ; esi can be negative

ca. line 932:
      ; invoke RtlZeroMemory,pString,ecx  ; pString is a bad pointer

Fumio

And the Thick Plottens: Attached is a working tut35 created in Radasm 2.2.1.5.  I hope I have attached all pertinent files in the two zip files. one shows the project options where the STACK option was added. It is late for me and I will experiment a bit more tomorrow. Absolutely nothing to do with the code itself; But two things I changed: first used the original Resource.h file and second, rather ten cut and paste Iczelion's code into Radasm I copied and then renamed the files and voila it worked. Note that I did not build a debug version of the working exe but the release. What ever the problem is I don't believe it can be the code but must have something to do with the cut and paste procedure in Radasm and the /STACK:2000000,2000000 option.
regards Fumio

jj2007

Congrats, it seems to work, so you are lucky :P

Just for the record:
- While esi>0 is wrong. Depending on what kind of garbage you find on the stack, esi can assume negative values, and you enter into an almost endless loop (I've seen it crash).
- as qWord suggested, stack probing would be a nice idea. This is sufficient to solve your inexistent "not enough stack problem":
   LOCAL pt:POINT
   and dword ptr [esp+6*1024], 0
   and dword ptr [esp+2*1024], 0
   .if uMsg==WM_PAINT
- only two of the files are "pertinent" aka needed, *.asm and *.rc, all the rest serves only to please the IDE.
- there is still a missing ret in the WM_CLOSE handler, and the only reason why it doesn't crash is that this branch is never used.


Quote from: qWord on September 18, 2013, 11:12:55 PMthe USES directive for ESI, EDI and EBX would make the code more clear.

Good idea in principle but won't work with the big buffer because uses implies
add esp, -2850h
push ebp
... and bang!

Fumio

jj2007, dedndave, qword, and others, thank you for your interest and help concerning this issue. I will have another look at the two different .exe and if I find anything new I will let you know. I plan to imlement the stack probe and either remove the unused close branch or alter it as previously described.
Thanks again
Fumio

Antariy

The difference is:

      ;===================================================================
      ; Get the visible text into buffer
      ;===================================================================
      lea eax,buffer
      mov txtrange.lpstrText,eax
      invoke SendMessage,hWnd,EM_GETTEXTRANGE,0,addr txtrange
      mov esi,eax      ; esi == size of the text   
      .if esi>0
         mov BufferSize,eax

dedndave

Jochen is right - the WM_CLOSE message is only sent to the main window
child windows get WM_DESTROY, but not WM_CLOSE
i guess the proper place to un-subclass would be in the main window WndProc, WM_DESTROY

Antariy

Unsubclassing itself is buggy:

invoke SetWindowLong,hWnd,GWL_WNDPROC,addr OldWndProc   


But the main difference is still in this http://masm32.com/board/index.php?topic=2379.msg24746#msg24746 post.

Antariy

Add this http://masm32.com/board/index.php?topic=2379.msg24746#msg24746
and this:

mov [esp+8*1024],eax
mov [esp+4*1024],eax

after
   LOCAL pt:POINT


and delete bold from message above, so the prog posted in previous page will work :t

jj2007

Quote from: Antariy on September 20, 2013, 02:21:57 AM
      invoke SendMessage,hWnd,EM_GETTEXTRANGE,0,addr txtrange

Looks extremely useful indeed :bgrin:

Antariy

Quote from: jj2007 on September 20, 2013, 02:55:25 AM
Quote from: Antariy on September 20, 2013, 02:21:57 AM
      invoke SendMessage,hWnd,EM_GETTEXTRANGE,0,addr txtrange

Looks extremely useful indeed :bgrin:

Jochen, I don't quite understand what you mean with this message, I did not really follow this "guess a bug" thread. But you may implement the changes mentioned and see that they fix the program.

jj2007

Sorry, Alex, I forgot the "no irony" tag. That SendMessage is indeed missing, you are perfectly right :t