UseData winMainProcedure in Easycode

Started by NewEasycoder, June 13, 2010, 05:10:48 AM

Previous topic - Next topic

NewEasycoder

Hi I just started with Easycode and had a problem with some of the online tutorials.

The problem I am having is from the tute here: http://www.easycode.cat/English/Tutorial/Chapter2.html

The routine is:

OnResize:

   UseData winMainProcedure

   Invoke GetClientRect, [hWnd], Addr clientRect

   Invoke String, [clientRect.right], Addr clientDimensions, ecDecimal

   Invoke SetText, [hWnd], Addr clientDimensions

   Return (TRUE)

EndU

although the compiler output is

Error!
Line 58 of the include file Window1.asm:-
Could not find data source label given in USEDATA statement:-
UseData UseData winMainProcedure

Now I noticed that Easycode has made a Window1Procedure Frame for me:

Window1Procedure Frame hWnd, uMsg, wParam, lParam
   Mov Eax, [uMsg]
   Mov Ecx, SizeOf WINDOW1_MESSAGES / 8
   Mov Edx, Addr WINDOW1_MESSAGES
:   Dec Ecx
   Js > L2
   Cmp [Edx + Ecx * 8], Eax
   Jne <
   Call [Edx + Ecx * 8 + 4]
   Ret
L2:   Xor Eax, Eax   ;Return (FALSE)
   Ret
EndFthe


So I tried replacing UseData winMainProcedure with UseData Window1Procedure and then I get a different output from the compiler:

Compiling resources...
Assembling: Window1
Linking...

Error!
The following symbols were not defined in the object file or files:-
OnCreate
OnClose
Output file not made

Errors ocurred.

What is going wrong?  Regards


donkey

Hi NewEasycoder,

Although Ramon is much better to answer this and it should be posted in the easycode subforum, chapter 2 page 3 discussed creating a "main event loop" called winMain which would add the code for your winMainProcedure.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Ramon Sala

Hi NewEasyCoder,

Thanks fo using Easy Code!

If the window procedure is named 'Window1Procedure', then the 'UseData' statement should be 'UseData Window1Procedure'. So, the changes you made were right. Also you need to have all routines specified in the WINDOW1_MESSAGES (defined in the .Data section), that is, if there are messages for WM_CREATE and WM_CLOSE, then the corresponding routines must be defined:

OnCreate:
   UseData Window1Procedure
   ;==================================
   ;Write the initialization code here
   ;==================================
   Xor Eax, Eax   ;Return (FALSE)
   Ret
EndU

OnClose:
   UseData Window1Procedure
   ;=========================
   ;Write the final code here
   ;=========================
   Invoke IsModal, [hWnd]
   Or Eax, Eax      ;Cmp Eax, FALSE
   Jz >
   Invoke EndModal, [hWnd], IDCANCEL
   Mov Eax, TRUE   ;Return (TRUE)
:   Ret
EndU

If the routines have any other name defined in WINDOW1_MESSAGES (let's say OnWindow1Create and OnWindow1Close), then the previous code should be:

OnWindow1Create:
   UseData Window1Procedure
   ;==================================
   ;Write the initialization code here
   ;==================================
   Xor Eax, Eax   ;Return (FALSE)
   Ret
EndU

OnWindow1Close:
   UseData Window1Procedure
   ;=========================
   ;Write the final code here
   ;=========================
   Invoke IsModal, [hWnd]
   Or Eax, Eax      ;Cmp Eax, FALSE
   Jz >
   Invoke EndModal, [hWnd], IDCANCEL
   Mov Eax, TRUE   ;Return (TRUE)
:   Ret
EndU


Taking into account the GoAsm compiler error messages, it seems that there is no OnCreate/OnClose code in the '.Code' section.

However, if you cannot find the error, please post (or send it to me) the whole project.

Thanks,

Ramon
Greetings from Catalonia

NewEasycoder

Hi Ramon

I got it working, the error pointed at onCreate and Onclose, so I changed:


WINDOW1_MESSAGES   DD WM_CREATE, OnWindow1Create
               DD WM_CLOSE, OnWindow1Close
to

WINDOW1_MESSAGES   DD WM_CREATE, OnWindow1Create
               DD WM_CLOSE, OnWindow1Close
               DD WM_SIZE, OnResize

rather than using the exact code from the tute which was:

MESSAGES              DD WM_CREATE, OnCreate
            DD WM_CLOSE, OnClose
            DD WM_SIZE, OnResize

Btw so far it looks like it should be exactly the sort of programming IDE for me, are there any other tutorials apart from Bill's that are recommended?

Also although I haven't got to it yet, does Easycode support recursion?  Regards



Ramon Sala

Hi NewWasyCoder,

That's the point! You got it!

You will find good programs for GoAsm in the "Donkey's Stable" (http://www.quickersoft.com/donkey/index.html). Also, there is the Jeremy Gordon's website (Jeremy is the Go Tools author), but is not active now as he is moving.

And yes, Easy Code supports recursion.

Regards,

Ramon
Greetings from Catalonia

NewEasycoder

Glad to hear that its got recursion Ramon :U, I have another problem already though,

Error!
Line 38 of the include file Module1.asm:-
Forward short jump was to a place more than 127 bytes away (by 7 bytes)
Jz >.position_8

I tried it with that jump commented out, and the code compiled and works, so I seem to have hit a 127 byte limit relating to jumps, how should I be doing jumps properly?

donkey

Hi,

Jumps in GoAsm are coded like this:

jmp >.LABEL // this is a short jump
jmp >>.LABEL // this is a long jump

For backward jumps you can use < and << respectively if you want them hard coded but the direction indicator is not compulsory and GoAsm will use long or short whichever is most appropriate.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

NewEasycoder

Hi thanks Donkey, that fixed the error.

Now I noticed that this jump works

Cmp Ebx, 0
            Jz >>.position_0
Cmp Ebx,2
                Jz >>.position_2

but if I don't put the jump in like this:

Cmp Ebx, 0
        Invoke SetLeft, [hButton], 4
       Invoke SetTop, [hButton], 4
Cmp Ebx, 2
        etc

It seems to only apply the comparison to the first line of code following the cmp operator, is it just the way it is, and if so is it better to use jumps or create a separate subroutine to handle if then else statements?




Yuri

In GoAsm there are no if/else's, so you have to use jumps everywhere. Or cmov's. This is a problem at first, but later you can adapt your mind to that.
For example, I do it like this:

cmp eax,[something]
jne >
    invoke func1, [prm1], [prm2]
    jmp > 1
:
invoke func2, [prm1]
    1:


Or so:

invoke CreateSomething, [bla], [bla], [bla]
test eax,eax
jz >.error_create
    invoke WriteSomething, [bla], [bla]
    test eax,eax
    jz >.error_write
        mov eax,NOERROR
.exit
    ret
.error_create
    mov eax,ERROR_SOMETHING_CREATE
    jmp .exit
.error_write
    mov eax,ERROR_SOMETHING_WRITE
    jmp .exit