News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Win32 My First Window

Started by tda0626, April 24, 2024, 11:05:19 AM

Previous topic - Next topic

NoCforMe

Here's the complete conversion, using the StrLen() function from the MASM32 library:

LOCAL y:DWORD, stringPtr:DWORD
; Assuming that "i" is in a variable called "index":

; Calculate y-position:
MOV EAX, index
MUL cyChar
MOV y, EAX ;Save in local var.

; Get address of string to display:
MOV EAX, SIZEOF SYSMETRIC_ENTRY
MUL index
ADD EAX, OFFSET sysmetrics
MOV stringPtr, EAX

; Get length of string (using StrLen() from MASM32 library):
INVOKE StrLen, EAX

; Display the string:
INVOKE TextOut, hdc, 0, y, stringPtr, EAX
Assembly language programming should be fun. That's why I do it.

tda0626

Worked out almost all of the compile errors but this one

sysmets1.asm(195) : error A2026: constant expected

195                          mov eax, NUMLINES


jj2007

Have you defined NUMLINES somewhere?

NUMLINES=123 or
NUMLINES equ <123>

tda0626

#138
Quote from: jj2007 on May 04, 2024, 11:18:18 PMHave you defined NUMLINES somewhere?

NUMLINES=123 or
NUMLINES equ <123>


It was defined in that inc file I made.

Definition is
NUMLINES EQU  $sysmetricsSize / sizeof SYSMETRIC_ENTRY

SYSMETRIC_ENTRY STRUCT

iIndex    DD ?
szLabel   DD ?
szDesc    DD ?

SYSMETRIC_ENTRY    ENDS

sysmetrics    LABEL SYSMETRIC_ENTRY

SYSMETRIC_ENTRY <SM_CXSCREEN, chr$("SM_CXSCREEN"), chr$("Screen width in pixels")>
...

$sysmetricsSize    EQU $ - sysmetrics

jj2007

Try NUMLINES = $sysmetricsSize / sizeof SYSMETRIC_ENTRY after $sysmetricsSize EQU $ - sysmetrics

tda0626

I got the same error message. I have been trying to figure this out for hours now.

jj2007

Post complete code, and I'll see.

NoCforMe

Got to be something simple.
What assembler are you using?
Assembly language programming should be fun. That's why I do it.

tda0626

Quote from: NoCforMe on May 05, 2024, 04:40:34 AMGot to be something simple.
What assembler are you using?

MASM

Quote from: jj2007 on May 05, 2024, 02:57:41 AMPost complete code, and I'll see.

It is attached with the inc file.

Please take a look at the WM_PAINT section. I had a hard time translating the c code over even with NoCforMe's help. I am sure there are some errors the compiler isn't picking up. The Petzold code is below just in case someone doesn't have this book.

case WM_PAINT :
 hdc = BeginPaint (hwnd, &ps) ;
 for (i = 0 ; i < NUMLINES ; i++)
 {
 TextOut (hdc, 0, cyChar * i,
 sysmetrics[i].szLabel,
 lstrlen (sysmetrics[i].szLabel)) ;
 TextOut (hdc, 22 * cxCaps, cyChar * i,
 sysmetrics[i].szDesc,
 lstrlen (sysmetrics[i].szDesc)) ;
 SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;
 TextOut (hdc, 22 * cxCaps + 40 * cxChar, cyChar * i, szBuffer,
 wsprintf (szBuffer, TEXT ("%5d"),
 GetSystemMetrics (sysmetrics[i].iIndex))) ;
 SetTextAlign (hdc, TA_LEFT | TA_TOP) ;
 }
 EndPaint (hwnd, &ps) ;
 return 0 ;

NoCforMe

I made your sysmets.inc into a stand-alone .asm file (added what was needed to make it assemble). It assembled without errors. All I added was include \masm32\include\masm32rt.inc (needed for the chr$ macro).

I did have a really weird problem after I downloaded the file. It originally opened with Notepad, and I edited it there. For some reason there were 3 characters at the beginning of the file, non-ASCII, that I could not get rid of and which caused assembler errors ("invalid character in file"). Only after I edited it with my own editor (EdAsm) did those spurious characters disappear. ??? But I suspect this may have nothing to do with your problem.

Hmm; after looking at your .asm source (sysmets1.asm), maybe the problem is that you're including your .inc file immediately after the MASM32 include file:
.386

option    casemap: none

include \masm32\include\masm32rt.inc
include sysmets.inc
which may be bad because you open a .data section immediately in the .inc file.
Try putting that include after your .data statement (and remove .data from the .inc file). After all, all it's really doing is defining data (plus a couple constants based on that data).
Also, there's no need for the .386 and the option casemap statements, since they're covered in masm32rt.inc.
Also, and this is just icing on the cake, I'd bracket the include for masm32rt.inc with .nolist and .list. Otherwise your listing (.lst) file will be needlessly humongous. (I don't know why Hutch didn't put that in that file.)

Assembly language programming should be fun. That's why I do it.

sudoku

"NUMLINES EQU  $sysmetricsSize / sizeof SYSMETRIC_ENTRY" in your include file...

Masm detects a "/" in the file as a line continuation character...? whoops... line continuation is "\"
I rarely if ever, use that. Hence my mistake. :tongue:
:cool:

NoCforMe

Nope. That line assembled fine for me; "/" is the division operator in MASM.
The backslash ("\") is the line continuation character.
Assembly language programming should be fun. That's why I do it.

sudoku

Quote from: NoCforMe on May 05, 2024, 05:37:47 AMThe backslash ("\") is the line continuation character.
Yes, I checked and corrected my post. My bad.  :cool:
:cool:

NoCforMe

Aaaaaargh. See, this is why I hate macros.

JJ, since you're an expert in this area, could you take a look at the attached listing file? This is the result of assembling his sysmets1.asm.

What a frigging mess! That chr$ macro bounces back and forth between .data and .code. (Why?) And I honestly cannot tell from that listing what is going on in terms of what data is actually being defined there. I think that may have something to do with this problem. I get the same error, "constant expected" with NUMLINES. I don't think the length of that data area (sysmetrics) can be determined correctly for some reason.

Of course I understand that without using the chr$ macro it would be a total pain in the ass to create this structure, as you'd have to create each and every string individually, give it a name, then plug those names into the structure.

Help!

Just to be crystal clear, what is needed is for chr$ to create a separate anonymous string in .data and put a pointer to that string in the SYSMETRIC_ENTRY structure (not the string data itself).
Assembly language programming should be fun. That's why I do it.

NoCforMe

Sorry, my bad: I see the problem. chr$ is the wrong macro.
It's used when you want to include a text string in code, not data: it creates an anonymized (nameless) string in .data but emits the address of that string in .code so it can be used in, say, an INVOKE. So it ain't gonna work here.

What's needed is the equivalent to the C TEXT macro, that (somehow) creates the anonymized string in the data section but in a different place from the current location, then puts a pointer to that text where you need it. How would it even do that?

I've enlisted the help of JJ, who's a macro expert. Hopefully he can help us sort this out.
Assembly language programming should be fun. That's why I do it.