Can any one point me to the 64bit macro or code that uses the automatic "This is a text string"
invoke TextOut,hDc,100,100,"This is a text string",lengthof ????? ...So that my old eyes don't have to count the lenghthof number. There should be a length count some where in the code, right?
Hi,BugCatcher
.data
szStr db "This a text string",0
...
.code
invoke aStrLen,addr szStr
invoke TextOut,hDC, 100,100,addr szStr,rax
aStrLen proc uses rdi pStrAddr:QWORD
cld
xor rcx,rcx
not rcx
mov rdi,pStrAddr
mov al,0
repnz scasb
not rcx
dec rcx
mov rax,rcx
ret
aStrLen endp
Since you specifically asked for a macro.... After I tried 'fn TextOut, hDc, 100, 100, "This is a text string", len(r9)' which didnt work as I thought it would, I settled on:
invoke TextOut, hDc, 100, 100, "This is a text string", len("This is a text string")
... which does appear to work (I checked this in x64dbg) and might be what you are looking for?
Yes you would have to duplicate the quoted text (as shown), if you dont want to use a defined buffer it appears.
Else use six_L's approach and use a buffer... and any string length function of your choosing.
A little bit later...
Tested and attached...
A little adjustment to six_L's code
.data
szStr db "This a text string",0
szStrLen equ $-szStr-1
...
.code
invoke TextOut,hDC, 100,100,addr szStr,szStrLen
Otherwise you would need to adjust hutch's INVOKE macro.
Quote from: sinsi on December 29, 2024, 01:41:45 PM.data
szStr db "This a text string",0
szStrLen equ $-szStr-1
.code
invoke TextOut,hDC, 100,100,addr szStr,szStrLen
Works, but it's not in a macro. To hide it in a macro, I'd suggest:
CStr macro text:vararg
.const
@sym = byte ptr $
db text,0
@sizesym = $ - @sym
exitm <offset @sym>
endm
.code
mov eax, CStr("123")
mov ecx, @sizesym
mov ebx, CStr("12345")
mov ecx, @sizesym
mov edx, CStr("12345678")
mov ecx, @sizesym
invoke TextOut, hDC, 100, 100, CStr("123"), @sizesym-1
Using assembly-time variables allows to avoid local labels inside macros, thus taking string addresses out of anonymity.
@_japheth:
Nice. :smiley: But will that also work with the 64 bit calling convention?
Quote from: BugCatcher on December 29, 2024, 03:25:32 AMCan any one point me to the 64bit macro or code that uses the automatic "This is a text string"...
I am on an iPad at the moment, I cannot check that myself...
Out of curiosity, I'll check in a little while when I am back inside.
.DATA
jat db "Just a test", 0
.CODE
invoke TextOut, PtDC, 7, 2, addr jat, sizeof jat-1
(why use a simple solution if you can do it with a one-hundred line macro, yeah...)
@_japheth:
Quote from: zedd151 on December 30, 2024, 03:03:25 AMBut will that also work with the 64 bit calling convention?
Short answer, no. Tested with ml64 Version 14.00.24210.0
QuoteAssembling: generic64.asm
***************************
ERROR Unknown argument type -> offset @sym
***************************
test file attached below with CStr fail
I also tested "CStr" macro in 32 bit... for completeness...
Quote(19) : error A2107: cannot have implicit far jump or call to near label
_
Assembly Error
Press any key to continue . . .
Another option.... perhaps... @BugCatcher:
try DrawText?? you dont need string length, but will need to initialize a rect structure:
mov rct.left, 100
mov rct.top, 100
mov rct.bottom, 122
mov rct.right, 280
invoke DrawText, hDc, "This is a text string", -1, addr rct, DT_LEFT
Hi BugCatcher!
Quote from: BugCatcher on December 29, 2024, 03:25:32 AMCan any one point me to the 64bit macro or code that uses the automatic "This is a text string"
You are thinking in
reparg macro :thumbsup:
But to obtain string and length of string you need a lttle modification (perhaps name could be
repargl):
repargl MACRO arg
LOCAL nustr,pnu,siznustr
LOCAL quot
quot SUBSTR <arg>,1,1
IFIDN quot,<"> ;; if 1st char = "
.data
align 16
nustr db arg,0 ;; write arg to .DATA section
siznustr equ $-nustr
pnu dq nustr ;; get pointer to it
.code
EXITM <pnu, siznustr> ;; return the pointer and length
ELSE
.err Not a quoted string ;; else return error
ENDIF
ENDM
then you use like:
invoke TextOut,hDc,100,100,repargl("This is a text string")
Regards, HSE
Note: you need a pointer only if you are using
Hutch's invoke macro. Other way instead
pnu, just return
offset nustr
Quote from: zedd151 on December 30, 2024, 03:39:28 AMShort answer, no. Tested with ml64 Version 14.00.24210.0
Assembling: generic64.asm
***************************
ERROR Unknown argument type -> offset @sym
***************************
True, an offset cannot be used as an immediate operand in 64-bit (with a few exceptions).
Quote(19) : error A2107: cannot have implicit far jump or call to near label
Yes, that was a little aptitude test ... there's something missing in the macro :biggrin:
Quote from: zedd151 on December 30, 2024, 03:39:28 AM@_japheth:
Quote from: zedd151 on December 30, 2024, 03:03:25 AMBut will that also work with the 64 bit calling convention?
Short answer, no. Tested with ml64 Version 14.00.24210.0
QuoteAssembling: generic64.asm
***************************
ERROR Unknown argument type -> offset @sym
***************************
Ml64 have no problem, nor x64 ABI.
Error message is from Hutch's invoke macro. He don't liked offset, but there is no problem when pointing to .data section.
I suggested several times to update that macro (like I made long time ago), but here you are :biggrin:
Take me some time to find where I post one of that :biggrin: :
Alternative macros64 : OFFSET and &. (https://masm32.com/board/index.php?topic=9693.0)
From everything I have seen here BugCatcher, it might be way easier to just use a buffer for your string.
@ _japheth: :biggrin:
@ HSE: :biggrin:
Quote from: zedd151 on December 30, 2024, 07:06:40 AMFrom everything I have seen here BugCatcher, it might be way easier to just use a buffer for your string.
"No hay mas ciego que el que no quiere ver"
(There is no one more blind than he who does not want to see)
No hay tiempo ahora.. or something like that. :tongue:
"I ain't got time right now". I'll look at that later. :biggrin:
The way I do it now is to simply count the length of the string.
invoke TextOut hDc,100,100,"This is a string",16 But its not good on my eyes for super long strings.
TextOut expects a string pointer. I haven't been able to find the code that changes this into a pointer.
"This is a pointer"?
Hi BugCatcher!
Quote from: BugCatcher on December 31, 2024, 12:47:46 AMinvoke TextOut hDc,100,100,"This is a string",16
For only that use fn macro (https://github.com/ASMHSE/SmplMath/blob/main/accs/macros.inc#L16):
fn TextOut hDc,100,100,"This is a string",16
If you are using Ml64, previously you have declare somewhere:
@WordSize equ 8
Regards, HSE
Turns out the code to get the string pointer is in the 64bit TextOut function itself (gdi32). It loads the string length first. So I can't cheat to get the string length before the function starts. So y'all right, for large strings the best way is the old way to create a buffer and get lengthof from the buffer.
Quote from: BugCatcher on December 31, 2024, 02:59:08 AMTurns out the code to get the string pointer is in the 64bit TextOut function itself (gdi32).
I am pretty sure (> 90%) that it's the 'invoke' macro (in masm64 SDK) that does that, (supplying the pointer to the string to TextOut, that is).
But yes I noticed that as well, when I was trying to find a 'work around' that does what you wanted to do.
Tweaking the 'invoke' macro (in the masm64 sdk), it
might be possible to get the string length there, and return that in a register (rax maybe). That will take some work to get working without screwing up any other functionality of that macro though. Kind of beyond my level of knowledge unfortunately, and may not even be possible if rax is needed elsewhere in the macro. I might take a look at that proposal, but I will need plenty of 'spare time', as it may not be an easy (for me) task.