News:

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

A few small/quick questions ...

Started by p0wder, July 20, 2006, 10:10:53 PM

Previous topic - Next topic

p0wder

0. Are there any good masm win32 gui tutorials out there? for creating gui objects like a tabbed settings window etc ...

1. What is the difference between variables in the uninitialized data section [.data?] having just a ? after them, versus a <?> ...

2. How can all of this data fit within a byte?


teststuff   DB  "blahhhhh",0
               DB "edffgefersaSSSSSSSSSSSS",00


?

3. I am using some code i found in iczeleons tutorial for a tray icon.


IDM_RESTORE EQU 1000
IDM_EXIT EQU 1010

....

INVOKE AppendMenu, hPopupMenu, MF_STRING, IDM_RESTORE, ADDR szRestore
INVOKE AppendMenu, hPopupMenu, MF_STRING, MyIP, ADDR szIP
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_GRAYED, IDM_RESTORE, ADDR szWebsite
INVOKE AppendMenu, hPopupMenu, MF_GRAYED, IDM_RESTORE, ADDR szAbout
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_GRAYED, IDM_RESTORE, ADDR szSettings
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_STRING, IDM_EXIT, ADDR szExit



I want to be able to somehow call a function instead of IDM_RESTORE or IDM_EXIT ...
Are those EQU just codes somewhere in an include file for exiting or restoring a program from the tray?

BogdanOntanu

Quote from: p0wder on July 20, 2006, 10:10:53 PM
0. Are there any good masm win32 gui tutorials out there? for creating gui objects like a tabbed settings window etc ...

yes, and there are some IDE's that can help there visually

Quote
1. What is the difference between variables in the uninitialized data section [.data?] having just a ? after them, versus a <?> ...

? defines an non initialized simple data type like: db, dw, dd, dq,real4, etc
<?> defines a a complex data type like a STRUC, UNION

Quote
2. How can all of this data fit within a byte?

teststuff   DB  "blahhhhh",0
               DB "edffgefersaSSSSSSSSSSSS",00

?


the string "abcd" when defined as:
DB"abcd",0
is actually defined like
DB "a", "b","c", "d",0

It is just a feature of the compiler to allow this way for your convenience

So a string is just a collection of bytes ... and because of this each one of them can "fit" perfectly

Quote
3. I am using some code i found in iczeleons tutorial for a tray icon.


IDM_RESTORE EQU 1000
IDM_EXIT EQU 1010

....

INVOKE AppendMenu, hPopupMenu, MF_STRING, IDM_RESTORE, ADDR szRestore
INVOKE AppendMenu, hPopupMenu, MF_STRING, MyIP, ADDR szIP
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_GRAYED, IDM_RESTORE, ADDR szWebsite
INVOKE AppendMenu, hPopupMenu, MF_GRAYED, IDM_RESTORE, ADDR szAbout
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_GRAYED, IDM_RESTORE, ADDR szSettings
INVOKE AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
INVOKE AppendMenu, hPopupMenu, MF_STRING, IDM_EXIT, ADDR szExit



I want to be able to somehow call a function instead of IDM_RESTORE or IDM_EXIT ...
Are those EQU just codes somewhere in an include file for exiting or restoring a program from the tray?

Call a function for it and store the result in a variable then INVOKE using the variable instead of IDM_RESTORE

Alternatively your could use some MACRO's to do that in a single line aka replace IDM_RESTORE with macro_func(my_function,my_params)
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

p0wder

How can I save a function in a variable? I only know how to do that in C ...

Mark Jones

Quote from: p0wder on July 20, 2006, 10:10:53 PM
I want to be able to somehow call a function instead of IDM_RESTORE or IDM_EXIT ...
Are those EQU just codes somewhere in an include file for exiting or restoring a program from the tray?

Without all the code it's hard to say exactly what the EQUs are for, but typically you can think of them as compile-time statics. Some may be defined in the .rc file(s) also. There is also TEXTEQU and MACRO, which perform similar functions. These all are conveniences, to help tidy up code.

Quote from: p0wder on July 21, 2006, 04:18:43 PM
How can I save a function in a variable? I only know how to do that in C ...

You're thinking too much like C here. :wink In assembler at the very lowest level, you have only instructions, registers, immediate values, and memory pointers (to a byte/word/dword.) Some instructions can use memory addresses as operands, and some cannot. (Take the INT command for example, the only value it can accept is an immediate value - it isn't designed to handle a memory address.) But MOV on the other hand, one (and only one) of the two operands can be a memory address. This allows you to copy a byte/word/dword into a memory address. However, for MOV to know that the parameter is a memory address and not an immediate value, you have to prefix the operand with BYTE/WORD/DWORD PTR [dest] or OFFSET [dest]. If you have already defined a .DATA variable myVar DD 0 and use it's name as that operand, ML is smart enough to know what you are trying to do and internally "converts" "MOV myVar,1" to "MOV DWORD PTR [myVar],1". At the byte-level, the code for "MOV myVar,1" and "MOV DWORD PTR [myVar],1" is different, and it has to be for the processor to do the right thing.

So then, "variables" and "structures" are nothing more than memory addresses. If you do:

.data
    myVar1 DD 0
    myVar2 DD 1
    myVar3 DD 2


The actual offsets of each of these handles at run-time will probably be 00403000h, 00403004h, and 00403008h and physically look like this:


00403000:  00 00 00 00 01 00 00 00  ........
00403008:  02 00 00 00 00 00 00 00  ........


Remember that data is stored in reverse byte order (little endian order) at the physical level, so "02000000h" is really 2.

So then, how can you save a function in a variable? In reality, you can't. BUT, you CAN save a memory address in a variable, otherwise known as a pointer. Since program code and data are both in memory, obtaining the address of a procedure or function is simple. When you define a PROC in masm, the name of that proc IS the address of that proc. Therefore, to make myVar1 a pointer to that proc, you can either define it that way at compile-time,


.data
    myVar1 DD myProc1
    myVar2 DD 1
    myVar3 DD 2


Or since myVar1 is a "variable," you can change the contents of it at run-time, i.e.


.code
    mov eax,myProc1
    mov myVar1,eax



Note that MOV myVar1,myProc1 is not valid, because the MOV instruction can only take one memory operand.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

p0wder

First off, I would like to thank you Mark for all of your help. The past two weeks I have really learned a lot on this board about Win32asm programming with MASM. Your post above gave me a lot more insight into ASM. I am trying to do what you mentioned above, here is my relevant code:



.DATA

; OpenWindow PROC Address
OpenHomeVar DD OpenHomepage

; this is inside my WndProc PROC WM_CREATE
.CODE
INVOKE AppendMenu, hPopupMenu, MF_STRING, OpenHomeVar, ADDR szWebsite

; .....
; main code block
execute:
; Store PROC Address of OpenHomepage in OpenHomeVar DD
MOV EAX, OpenHomepage
MOV OpenHomeVar, EAX
; EAX = 0
XOR EAX, EAX
; Get this programs handle
INVOKE GetModuleHandle, NULL
MOV    hInstance, EAX
INVOKE WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
;CALL OpenHomepage
INVOKE ExitProcess, EAX
END execute


When I Assemble and Link, everything is fine. When I Right Click on the tray menu, everything is a go, however when I click on the szWebsite on the menu, The program just exits, instead of calling my PROC which opens my URL in the browser.

PBrennick

pOwder,
Yes, it will exit because that is what you are asking it to do.  You need to change:

;CALL OpenHomepage
INVOKE ExitProcess, EAX


Uncomment the CALL OpenHomePage so it can go to the procedure that will do what you want to do.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

p0wder

Actually, the call to Openhomepage is only supposed to be done when the use clicks on the text from szWebsite. I accidentally left the CALL OpenWebpage there when i was trying out the actual procedure. I want it called when the user clicks the tray popup ...

PBrennick

#7
You have to do something, it is not going to happen like it does in Windows where you can doubleclick a file and it will load the helper app.  Try to figure it out and when you need help you can always ask.

[Sorry, my machine crashed and then I got disracted],
Paul
The GeneSys Project is available from:
The Repository or My crappy website