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

jj2007

Quote from: NoCforMe on May 05, 2024, 06:40:08 AMWhat's needed is the equivalent to the C TEXT macro, that (somehow) creates the anonymized string in the data section

From A window in 30 lines of code:

.data   ; initialised data section
wc   WNDCLASSEX <WNDCLASSEX, 0, WndProc, 0, 0, 1, 2, 3, COLOR_BTNFACE+1, 0, txClass, 4>
txClass   db "Masm32GUI", 0         

TimoVJL

Quote from: NoCforMe on May 05, 2024, 06:40:08 AMWhat'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?

C TEXT() macro is only for selecting between ANSI or UNICODE

TEXT macro (winnt.h)

#ifdef  UNICODE
#define __TEXT(quote) L##quote
#else
#define __TEXT(quote) quote
#endif
May the source be with you

NoCforMe

But but but ... hmmm, that's not a macro; that's the "pain-in-the-ass" way I said would be the other way to do this.

Isn't there some macro that behaves like C TEXT? (Although I have no idea how that would work: it would have to define the anonymous strings in some other part of the data section than what was being defined.)

Something like:
S <SM_CXSCREEN, TEXT("SM_CXSCREEN"), TEXT("Screen width in pixels")>
such that data would end up being defined thus:
S <SM_CXSCREEN, ?000001, ?000002>

 . . . . .

?000001  DB "SM_CXSCREEN", 0
?000002  DB "Screen width in pixels", 0
Assembly language programming should be fun. That's why I do it.

NoCforMe

Quote from: TimoVJL on May 05, 2024, 07:57:04 AMC TEXT() macro is only for selecting between ANSI or UNICODE

TEXT macro (winnt.h)

#ifdef  UNICODE
#define __TEXT(quote) L##quote
#else
#define __TEXT(quote) quote
#endif
Timo, that's __TEXT, not TEXT. Petzold uses it all over the place in his book:
struct {
    int
    TCHAR * szLabel;
    TCHAR * szDesc;
}
sysmetrics[] =
{  SM_CSSCREEN, TEXT ("CM_CXSCREEN"), TEXT ("Screen width in pixels"),
    . . .
Anyhow, whatever it's called, it's exactly what we need here, but in MASM.
Assembly language programming should be fun. That's why I do it.

TimoVJL

I just missed to add this too
#define TEXT(quote) __TEXT(quote)
poasm accept thisstr$ MACRO any_text:VARARG
LOCAL txtname
txtname db any_text,0
EXITM <OFFSET txtname>
ENDM
May the source be with you

NoCforMe

Quote from: tda0626 on May 05, 2024, 05:00:54 AM----

OK, in the meantime while we're trying to see if there exists a suitable macro, you can get this working by coding it up thus:
First, define all the strings and give them (simple) names (for the sake of avoiding too much typing):
S1a  DB "SM_CXSCREEN", 0
S1b  DB "Screen width in pixels", 0
and so on.

Then just stick those names into the structure:
SYSMETRIC_ENTRY <SM_CXSCREEN, S1a, S1b>
and so on. It's a bit of typing, but maybe you can semi-automate it with Excel or something. You seem pretty resourceful.

It'll work, I promise.
Assembly language programming should be fun. That's why I do it.

zedd151

Hmmm.. maybe find someone who can compile Petzolds C example, and attach the executable... then look at the resultant disassembly??? Should give some workable ideas how to approach the problem in assembly.

NoCforMe

I don't think that would help.
I'm willing to bet that it would show the structure and the strings that are pointed to in that structure end up in two different parts of .data. What it wouldn't show is how those strings got put in that separate place (i.e., how the TEXT macro functions).

Keep in mind that the structure has to be contiguous, with no intervening data (like text) between or in any of the elements.
Assembly language programming should be fun. That's why I do it.

zedd151

How about this TEXT macro
It has to be defined somewhere. Meaning the contents of the macro.

I just now noticed that TimoVJL poted the same link and info already... above.

Will either of these work? Seems to be what the TEXT macro is doing as far as I can tell.
    STRING MACRO sname,quoted_text
      LOCAL quoted@@@@
      .data
        quoted@@@@ db quoted_text,0
        align 8
        sname dq quoted@@@@
      .code
    ENDM

      STRING MACRO data_label,quoted_text:VARARG
        IFNDEF __UNICODE__
          .data
            data_label db quoted_text,0
            align 4
          .code
        ELSE
          WSTR data_label,quoted_text,0
        ENDIF
      ENDM
The first is from the masm64 sdk, the second from masm32 sdk.

zedd151

...
Dangit! I quoted my post instead of modifying it.

Mods!! delete this errant post, please.  :smiley:

NoCforMe

NO!
Can't you see that those macros would declare the text string at the place where the macro is being invoked? Meaning right smack in the middle of the structure, which won't work. We want pointers to text strings in the structure, not the strings themselves.

Besides, both of those macros shift back to .code, which is definitely not wanted here! It's all got to be in .data.
Assembly language programming should be fun. That's why I do it.

sinsi

cstr MACRO lbl,string:VARARG
LOCAL s,x,z
    IFDEF __UNICODE__
        align 2
        IFNB <lbl>
            lbl LABEL WORD
        ENDIF
        FOR s,<string>
            IFIDN @SubStr(s,1,1),<">
                x SUBSTR <s>,2,(@SizeStr(s)-2)
                % FORC c,<x>
                     dw "&c"
                  ENDM
            ELSE
                dw s
            ENDIF
        ENDM
        dw 0
    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

@cstr MACRO string:VARARG
LOCAL s,sss1
sss1 TEXTEQU @CurSeg
.const
cstr s,string
IFIDNI sss1,<_TEXT>
.code
ELSEIFIDNI sss1,<_BSS>
.data?
ELSEIFIDNI sss1,<_DATA>
.data
ENDIF
EXITM <offset s>
ENDM

NoCforMe

OK. Did you just come up with that? If so, appreciate the effort.
However, I have no friggin' idea what those do or how they work.
Care to explain?
Where (in the .data section) do the strings get declared?

Could you show the OP how to use this?

One possible clue: @cstr includes .const; is this a separate section of initialized data where the strings go?
And then the macro emits offset s before it exits, giving us the pointer; is that right?
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on May 05, 2024, 08:55:58 AMWe want pointers to text strings in the structure, not the strings themselves.
I played around a bit with those. I did get a pointer into the code section, but not into a structure. Nothing ventured, nothing gained. I am obviously NOT a macro guy.  :tongue:


@sinsi: but will that work within a structure? Does it need parenthesis? example cstr(mystring, "my string")

NoCforMe

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