Who can tell me how can I initialize a structure in static data segment like this in C?
struct
{
char *szLabel;
char *szDesc;
}
sysmetrics[]=
{
"SM_CXSCREEN","Screen width in pixels",
"SM_CYSCREEN","Screen Height in pixels"
......
}
Posted on 2002-10-13 05:13:34 by smartcurl
Testing STRUCT

hFile DD ?
szFileName DB 20 DUP(?)
DB 0 ;String terminate with 0
Testing ENDS

.DATA

myfile Testing <1, "Hello Cruel World">, <2, "Hello World">, <3, "I'm A MArtian">
tests DB "tests", 0

.CODE

start:

invoke MessageBox, HWND_DESKTOP, OFFSET myfile.szFileName, NULL, MB_OK
invoke MessageBox, HWND_DESKTOP, OFFSET myfile[SIZEOF Testing].szFileName, NULL, MB_OK
invoke MessageBox, HWND_DESKTOP, OFFSET myfile[SIZEOF Testing*2].szFileName, NULL, MB_OK
invoke MessageBox, HWND_DESKTOP, OFFSET tests, NULL, MB_OK

invoke ExitProcess, 0

end start
Posted on 2002-10-13 16:55:53 by stryker
Much better solution.
.686

.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDE \dev\masm32\include\windows.inc
INCLUDE \dev\masm32\include\kernel32.inc
INCLUDELIB \dev\masm32\lib\kernel32.lib
INCLUDE \dev\masm32\include\user32.inc
INCLUDELIB \dev\masm32\lib\user32.lib
INCLUDE \dev\masm32\include\shell32.inc
INCLUDELIB \dev\masm32\lib\shell32.lib

LBL STRUCT
szLabel DD ?
szDesc DD ?
LBL ENDS

.DATA

f1 DB "Number One", 0
f2 DB "Number Two", 0
f3 DB "Number Three", 0

lvl LBL <1, OFFSET f1>, <1, OFFSET f2>, <3, OFFSET f3>

.CODE

start:

invoke MessageBox, HWND_DESKTOP, lvl.szDesc, NULL, MB_OK
invoke MessageBox, HWND_DESKTOP, lvl[SIZEOF LBL].szDesc, NULL, MB_OK
invoke MessageBox, HWND_DESKTOP, lvl[SIZEOF LBL*2].szDesc, NULL, MB_OK

invoke ExitProcess, 0

end start
Posted on 2002-10-13 20:07:13 by stryker
Cool! stryker
It's so helpful to me.thank you.but if ".686" means that code must cann't run on Pentium cpu?Maybe this question is too naive.:confused:
Posted on 2002-10-13 20:22:19 by smartcurl
the program still works, it's just that when I code I usually use all available instructions on my p3 when needed. Using .386 -> .586 doesn't allow the use of the CMOVcc instructions... the code above doesn't use any of these instructions, it only uses push and call - generated by invoke.

You can change that to .386, .486, 586 ... if you want to. :)
Posted on 2002-10-13 20:47:39 by stryker
I got it!
Thanks again.:)
Posted on 2002-10-13 20:53:33 by smartcurl
Much better solution.

Macro stolen from gfalen. :)
.686

.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDE \dev\masm32\include\windows.inc
INCLUDE \dev\masm32\include\kernel32.inc
INCLUDELIB \dev\masm32\lib\kernel32.lib
INCLUDE \dev\masm32\include\user32.inc
INCLUDELIB \dev\masm32\lib\user32.lib
INCLUDE \dev\masm32\include\shell32.inc
INCLUDELIB \dev\masm32\lib\shell32.lib

LBL STRUCT
szLabel DD ?
szDesc DD ?
LBL ENDS

t MACRO _str:VARARG
LOCAL @@1
IF @InStr(1, <_str>, <!"> )
.DATA
@@1 DB _str, 0
.DATA
EXITM <OFFSET @@1>
ELSE
EXITM <_str>
ENDIF
ENDM

.DATA

lvl LBL <1, t("Number One")>, <1, t("Number Two")>, <3, t("Number Three")>

.CODE

start:

invoke MessageBox, HWND_DESKTOP, lvl.szDesc, NULL, MB_OK
invoke MessageBox, HWND_DESKTOP, lvl[SIZEOF LBL].szDesc, NULL, MB_OK
invoke MessageBox, HWND_DESKTOP, lvl[SIZEOF LBL*2].szDesc, NULL, MB_OK

invoke ExitProcess, 0

end start
Posted on 2002-10-14 00:51:27 by stryker