News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Macro issue

Started by minor28, December 03, 2009, 02:25:41 PM

Previous topic - Next topic

minor28

We have the CTEXT macro. I have tryed to develop it to write a BSTR in data segment like this. BSTR("MyString") to get something like this.



.data
        dd 16
szMyString db "M",0,"y",0,"S",0,"t",0,"r",0,"i",0,"n",0,"g",0,0



for example


BSTR macro y:vararg
LOCAL sym
local buffer[256]:byte

invoke MultiByteToWideChar,CP_ACP,0,y,-1,addr buffer,sizeof buffer

invoke lstrlen,y
shl eax

data segment
eax
sym db buffer,0
data ends

exitm <offset sym>
endm


I haven't the faintest idea how to solve this. Does anybody know how to do it, if it is possible at all?

drizz

The truth cannot be learned ... it can only be recognized.

qWord

hi,

see the file in attachment

usage:

wData LableName,"what ever",10,13,"bla"

it creates an dword filled with string size (in bytes) follwed by zero terminated unicode string.

regards, qWord
FPU in a trice: SmplMath
It's that simple!

jj2007

Quoteinvoke MessageBoxW, 0, wChr$("Hello Masm32"), wChr$("Unicode in MasmBasic is simple:"), MB_OK

->MasmBasic

minor28

Thanks qWord. What a complicated macro. I don't understand all of your code but with a few changes it will work fine for my purpose.


wData macro args:VARARG
LOCAL sym
        .
.
.
.
  _Label struct
  db (sizeTotal+2) dup (?) ;; +2 for zero terminator
  _Label ends
 
  data segment
  align 4
;;Number of bytes in the following data string, terminator not include.
dd SIZEOF _Label-2
sym label _Label
  iArg = 0
  REPEAT nArg
IFIDN @CatStr(<wData_Line_>,%(iArg)),<"">
ELSEIFIDN @CatStr(<wData_Line_>,%(iArg)),<''>
ELSEIFB @CatStr(<wData_Line_>,%(iArg))
  ELSE
  dw @CatStr(<wData_Line_>,%(iArg))
  ENDIF
  iArg = iArg + 1
  ENDM
  dw 0
  data ends
 
  exitm <offset sym>
endm


The length prefix does not include the terminator and the label should be at the first undicode character. Sometimes I need the string two times why named label is exchange for sym.

Thank you all for your help.