News:

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

Main Menu

Win32 My First Window

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

Previous topic - Next topic

sinsi

test1 struct
 appname dd ?
test1 ends

.data
test2 test1 <@cstr("Hi")>

.code
start:
    mov eax,test2.appname ;  = pointer to db "Hi",0

zedd151

:undecided:

NoCforMe

OK, man of few words:
Does the OP have to type all that stuff in?
Is it already in the MASM32 stuff?
Assembly language programming should be fun. That's why I do it.

sinsi

OK, man of few words:
 :biggrin:

Does the OP have to type all that stuff in?
  copy paste should work too

Is it already in the MASM32 stuff?
  No, it's mine, all mine mwuhaha

it's been a long night...

NoCforMe

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


NoCforMe

OK, OP: since you've already done all that reformatting, my suggestion is to use sinsi's macros. Just copy and paste his code into your main program, somewhere near the top. (Or put it in an include file, but probably easier for now to just plunk it into your code.)

Then just replace all those chr$s with @cstr.

According to him, it should work.

We await your results.
Assembly language programming should be fun. That's why I do it.

NoCforMe

Quote from: sinsi on May 05, 2024, 12:27:05 PM
Quote from: NoCforMe on May 05, 2024, 12:22:45 PMTested?
yep
I would like to know, however, how those macros work.

Is .const a different initialized data area, separate from .data?
Pardon my ignorance; never heard of that nor used it.
Assembly language programming should be fun. That's why I do it.

tda0626

Quote from: NoCforMe on May 05, 2024, 12:37:49 PMOK, OP: since you've already done all that reformatting, my suggestion is to use sinsi's macros. Just copy and paste his code into your main program, somewhere near the top. (Or put it in an include file, but probably easier for now to just plunk it into your code.)

Then just replace all those chr$s with @cstr.

According to him, it should work.

We await your results.

OK so I can leave the original inc intact except for that modification? Sorry so many macros thrown around in the last couple of threads my eyeballs are going cross eyed. :joking: That stuff is like a foreign language to me.


Tim


NoCforMe

Yes; just copy the macros into it without understanding what they do. (Maybe later ... much later.)

It's pretty much Greek to me, too.
Assembly language programming should be fun. That's why I do it.

sinsi

OK, some comments
;Define a string in the current segment, optionally give it a name
;usage example
;.data
;    cstr MyString,"G'day",13,10
cstr MACRO lbl,string:VARARG
LOCAL s,x,z
    ;;Unicode string
    IFDEF __UNICODE__
        ;;align to unicode's size (16 bits)
        align 2
;;IF lbl is Not Blank
        IFNB <lbl>
    ;;define the label
            lbl LABEL WORD
        ENDIF
;;FOR each element s in string
        FOR s,<string>
    ;;if the first char is quotes
            IFIDN @SubStr(s,1,1),<">
        ;;strip the quotes
                x SUBSTR <s>,2,(@SizeStr(s)-2)
;;FOR each Char in the unquoted string
                % FORC c,<x>
    ;;simplified ASCII to unicode
                    dw "&c"
                ENDM
            ;;no quotes, must be a simple byte (like 13 (CR) or 10 (LF))
            ELSE
                dw s
            ENDIF
        ENDM
;;terminating zero char
        dw 0
    ;ASCII string - steps are the same except 1 byte = 1 char
    ELSE
        IFNB <lbl>
            lbl LABEL BYTE
        ENDIF
        FOR s,<string>
            IFIDN @SubStr(s,1,1),<">
                x SUBSTR <s>,2,(@SizeStr(s)-2)
                % FORC c,<x>
                     db "&c"
                  ENDM
            ELSE
                db s
            ENDIF
        ENDM
        db 0
    ENDIF
ENDM

;Define a string in the .const segment and return its offset
;Use it with INVOKE or in a structure, wherever you need the offset of a string
;Segment-aware, so it will restore the current segment after defining the string in .const
@cstr MACRO string:VARARG
LOCAL s,sss1
;;save the current segment
sss1 TEXTEQU @CurSeg
;;define the string in .const
;;Warning: the .const section is READ-ONLY, you won't be able to alter the string
.const
cstr s,string
;;Restore the segment in use, if I missed one just add it here :)
IFIDNI sss1,<_TEXT>
.code
ELSEIFIDNI sss1,<_BSS>
.data?
ELSEIFIDNI sss1,<_DATA>
.data
ENDIF
;;return the offset of the string
;;32-bit code only
EXITM <offset s>
ENDM
There are plenty of opportunities to streamline it, but it's good enough for me (and I HATE macros :biggrin: )

NoCforMe

Thanks--that helps.
So we're basically declaring the strings in one segment (.const) and putting their offsets in another segment, where our structure lives.

Cool. That's all I need to know; don't want all the gory details on how the sausage is made.

Pretty good for someone who hates macros!
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on May 05, 2024, 02:17:53 PMSo we're basically declaring the strings in one segment (.const) and putting their offsets in another segment, where our structure lives.

More or less (it can be in the same segment, too)

include \masm32\include\masm32rt.inc
include cStr.mac

test1 struct
 appname dd ?
test1 ends

.data
test2 test1 <@cStr("Hi")>
test3 test1 <thestring>

.code
thestring db "why do you need a macro for doing that?", 0    ; could be in .data, too

start:
    mov eax, test2.appname ;  = pointer to db "Hi",0
    print eax, " there, test2", 13, 10

    mov eax, test3.appname
    inkey eax
  exit

end start

TimoVJL

testing with poasm:
.386
.model flat, stdcall

printf PROTO C :PTR,:VARARG
INCLUDELIB msvcrt.lib

str$ MACRO any_text:VARARG
LOCAL txtname
.const
txtname db any_text,0
.data
EXITM <OFFSET txtname>
ENDM

SYSMETRIC_ENTRY STRUCT
    iIndex      DD ?
    labelText   DD ?
    descText    DD ?
SYSMETRIC_ENTRY    ENDS

.data
sysmetrics    LABEL SYSMETRIC_ENTRY
SYSMETRIC_ENTRY <0, str$("SM_CXSCREEN"), str$("Screen width in pixels")>
SYSMETRIC_ENTRY <1, str$("SM_CYSCREEN"), str$("Screen height in pixels")>

fmt db "%s %s",10,0

.code
mainCRTStartup PROC C
    invoke printf, ADDR fmt, sysmetrics.labelText, sysmetrics.descText
    ret
mainCRTStartup ENDP

END
output:SM_CXSCREEN Screen width in pixels
May the source be with you

NoCforMe

Yay! It works.

OP: Use Timo's macro instead (below). Much simpler than sinsi's. Use str$("text") in your structure.

Quote from: TimoVJL on May 05, 2024, 06:48:37 PMstr$ MACRO any_text:VARARG
LOCAL txtname
.const
txtname db any_text,0
.data
EXITM <OFFSET txtname>
ENDM
Even I can understand what's going on there.
Assembly language programming should be fun. That's why I do it.