Author Topic: Iczelion tutorial 35 Highlighting  (Read 21555 times)

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: Iczelion tutorial 35 Highlighting
« Reply #15 on: September 18, 2013, 11:12:55 PM »
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

  • Member
  • *****
  • Posts: 12933
  • Assembler is fun ;-)
    • MasmBasic
Re: Iczelion tutorial 35 Highlighting
« Reply #16 on: September 19, 2013, 02:33:14 AM »
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

  • Guest
Re: Iczelion tutorial 35 Highlighting
« Reply #17 on: September 19, 2013, 05:32:13 AM »
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

  • Guest
Re: Iczelion tutorial 35 Highlighting
« Reply #18 on: September 19, 2013, 06:11:50 AM »
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

  • Member
  • *****
  • Posts: 12933
  • Assembler is fun ;-)
    • MasmBasic
Re: Iczelion tutorial 35 Highlighting
« Reply #19 on: September 19, 2013, 08:36:39 AM »
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

  • Guest
Re: Iczelion tutorial 35 Highlighting
« Reply #20 on: September 19, 2013, 02:56:07 PM »
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

  • Member
  • *****
  • Posts: 12933
  • Assembler is fun ;-)
    • MasmBasic
Re: Iczelion tutorial 35 Highlighting
« Reply #21 on: September 19, 2013, 04:40:52 PM »
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.


the 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

  • Guest
Re: Iczelion tutorial 35 Highlighting
« Reply #22 on: September 20, 2013, 01:07:58 AM »
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

  • Member
  • ****
  • Posts: 564
Re: Iczelion tutorial 35 Highlighting
« Reply #23 on: September 20, 2013, 02:21:57 AM »
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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Iczelion tutorial 35 Highlighting
« Reply #24 on: September 20, 2013, 02:25:47 AM »
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

  • Member
  • ****
  • Posts: 564
Re: Iczelion tutorial 35 Highlighting
« Reply #25 on: September 20, 2013, 02:37:36 AM »
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

  • Member
  • ****
  • Posts: 564
Re: Iczelion tutorial 35 Highlighting
« Reply #26 on: September 20, 2013, 02:51:34 AM »
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

  • Member
  • *****
  • Posts: 12933
  • Assembler is fun ;-)
    • MasmBasic
Re: Iczelion tutorial 35 Highlighting
« Reply #27 on: September 20, 2013, 02:55:25 AM »
      invoke SendMessage,hWnd,EM_GETTEXTRANGE,0,addr txtrange

Looks extremely useful indeed :bgrin:

Antariy

  • Member
  • ****
  • Posts: 564
Re: Iczelion tutorial 35 Highlighting
« Reply #28 on: September 20, 2013, 12:29:09 PM »
      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

  • Member
  • *****
  • Posts: 12933
  • Assembler is fun ;-)
    • MasmBasic
Re: Iczelion tutorial 35 Highlighting
« Reply #29 on: September 20, 2013, 03:21:22 PM »
Sorry, Alex, I forgot the "no irony" tag. That SendMessage is indeed missing, you are perfectly right :t