I have this code for a simple window that generates an acess violation. It works fine if i move the WNDCLASSEX struct to the top of .data
Im i doing something wrong?
thanks an laters.
X
forgot the file...
hi,
the behaviour of the WSTR-macro has changed (MASM32v11): the macro assumes to be called from the code segment, thus it switch back to .code after creating the string. In your case the WNDCLASSEX-structure is placed in the code segment, which has the read-only attribute.
However, you can use the UCSTR-macro instead:
UCSTR MainWindowClass, "MainWindowClass",0
(do not forget the term. zero)
Quote from: qWord on January 15, 2012, 04:55:35 PM
However, you can use the UCSTR-macro instead:
UCSTR MainWindowClass, "MainWindowClass",0
(do not forget the term. zero)
Or, if you prefer a syntax closer to MyString db "hello", check UcInData (http://www.masm32.com/board/index.php?topic=18131.msg152920#msg152920):
include \masm32\include\masm32rt.inc
include UcInData.asm
.data
ucText uc$("This is a test", 13, 10, "with two lines", 0)
ucTitle uc$("This is a title", 0)
.code
start: invoke MessageBoxW, 0, offset ucText, offset ucTitle, MB_OK
exit
end start
Thanks guys. Yeah q, you mentioned that somewhere already in another thread (or something similar). I forgot.
Laters
As per the documentation for WSTR,
WSTR MACRO lblname,arglist:VARARG
Write a UNICODE string to the DATA section from the CODE section.
Quote from: hutch-- on January 15, 2012, 11:19:58 PM
As per the documentation for WSTR,
The previous \masm32\macros\ucmacros.asm says
macro to declare UNICODE string data in the .DATA section.
SYNTAX:
WSTR MyString,"This is a test"
So that has
changed, and therefore might break some existing code. IMHO there should be a macro using a syntax as close as possible to the standard Masm data declaration:
.data
; Ascii:
MyTextA db "This is a test", 13, 10, "with two lines", 0
; Unicode:
MyTextW dw$("This is a test", 13, 10, "with two lines", 0)
Below a proposal. It is reasonably short at 27 lines, does what it needs to do, and returns the correct values for sizeof and lengthof.
include \masm32\include\masm32rt.inc
dw$ MACRO args:VARARG
LOCAL ux$, pp, is
ux$ equ <>
FOR arg, <args>
is INSTR <arg>, <">
if is
is INSTR 2, <arg>, <">
else
is INSTR <arg>, <'>
if is
is INSTR 2, <arg>, <'>
endif
endif
if is
pp=2
WHILE pp lt is
c1$ SUBSTR <arg>, pp, 1
ux$ CATSTR ux$, <, ">, c1$, <">
pp=pp+1
ENDM
else
ux$ CATSTR ux$, <, >, <arg>
endif
ENDM
ux$ SUBSTR ux$, 2
ux$ CATSTR <dw >, ux$
EXITM ux$
ENDM
.data
; Ascii:
MyTextA db "This is a test", 13, 10, "with two lines", 0
MyTitleA db "This is a title", 0
; Unicode:
MyTextW dw$("This is a test", 13, 10, "with two lines", 0)
MyTitleW dw$("This is a title", 0)
.code
start:
invoke MessageBoxA, 0, offset MyTextA, offset MyTitleA, MB_OK
invoke MessageBoxW, 0, offset MyTextW, offset MyTitleW, MB_OK
exit
end start
Quote from: jj2007 on January 16, 2012, 12:53:01 AMIMHO there should be a macro using a syntax as close as possible to the standard Masm data declaration
see macros.asm: UCSTR,UCCSTR,uc$() and ucc$().
WSTR does what it is documented to do. RE the old version, UNICODE was not developed in the earlier version of masm32 where the current version has produced a system that WSTR is part of.
If you need to directly write large amounts of UNICODE data to the data section use the following macro.
.data
A2WDAT "First block of text", mytext
A2WDAT "Second block of text"
A2WDAT "Third block of text"
A2WDAT "Fourth block of text"
dw 0
.code
This macro technique allows much larger than the 240 character limit of a single line macro.
> IMHO there should be a macro using a syntax as close as possible to the standard Masm data declaration
There is, it uses DW but cannot accept characters. You can use this technique if you enter all of the characters as numbers.