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"
......
}
struct
{
char *szLabel;
char *szDesc;
}
sysmetrics[]=
{
"SM_CXSCREEN","Screen width in pixels",
"SM_CYSCREEN","Screen Height in pixels"
......
}
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
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
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:
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:
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. :)
You can change that to .386, .486, 586 ... if you want to. :)
I got it!
Thanks again.:)
Thanks again.:)
Much better solution.
Macro stolen from gfalen. :)
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