News:

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

How exactly do you INVOKE wsprintf?

Started by Mark Jones, July 03, 2005, 09:29:59 PM

Previous topic - Next topic

Mark Jones

 I've been able to use wsprintf before by manually calling it like this:


    mov eax, pFileSize
    push eax
    movsx eax, pSFT.wMinute
    push eax
    movsx eax, pSFT.wHour
    push eax
    movsx eax, pSFT.wDay
    push eax
    movsx eax, pSFT.wMonth
    push eax
    movsx eax, pSFT.wYear
    push eax
    lea eax, pFileName
    push eax
   
szText szTimeFormat, "%s, %04u/%u/%u@%u:%02u, %u bytes.",13,10,0 ; Myfile.asm, 2005/4/19@14:38, 12345 bytes.
    push offset szTimeFormat
    lea eax, szTmp
    push eax
    call wsprintf   ; line too long to INVOKE


But how you you INVOKE it? This new test refuses to run:


.data
szTemp1         db  "c:\file1.txt",0
szTemp2         db  "c:\file2.txt",0
paramsFormat    db  "%s /p %s",0

.data?
params          db  256 dup(?)

.code
    invoke wsprintf,addr params,addr paramsFormat,addr szTemp1,addr szTemp2


After the call, params should == "c:\file1.txt /p c:\file2.txt" but it just crashes.

If I reverse the invoked arguments,


    invoke wsprintf,addr szTemp2,addr szTemp1,addr paramsFormat,addr params


It will execute, but not produce any result. Help please. :)

(Why in the @#^(@%$ did Microsoft keep this calling convention???
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Mark Jones

I found the problem. It had to do with the szText macro actually. During testing, I usually put strings in the code using the szText macro. Well it looks like wsprintf doesn't like them. Once I actually defined the strings properly in .data and .data? (as the code shows) it started working properly. :red :toothy

Sorry for the
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

donkey

#2
Hi Mark,

You might like to try my  lszCatPlus function in my strings.lib library. Works like wsprintf but allows you to specify the string order as well as use duplicates etc... You might find it interesting, it is MASM and GoAsm compatible and source is included...

http://www.assembler.ca/files/Strings.zip

lszCatPlus:
Performs a formatted multiple concatentation
This is a C calling convention function, the caller is responsible for the stack
ECX is guaranteed to be preserved for counting loops
Parameters:
buffer = Pointer to a buffer to hold the resulting string
szFmt = Pointer to a format string that controls that concatenation
arg0..arg9 = Pointers to null term. strings or dwords, index of arg matches the format

The buffer must be large enough to hold the entire string.

szFmt has the following format:
where # is the 0 based parameter for that position
ie %[type]0 = arg0, %[type]1 = arg1 etc...
You can repeat parameters ie "%u0 %x1 %x1 %s2"
Or put them out of order "%s2 %u0 %i3 %x1"

Types:
%s# = Inserts a string pointed to by argument
%i# = Converts argument to a signed integer (i must be lower case)
%u# = Converts argument to an unsigned integer (u must be lower case)
%x# = Converts argument to a hex string (x must be lower case)

It is then followed by up to 10 arguments (0-9)
For a % sign use %%
Strings arguments are limited to a maximum of 1023 bytes
Returns the pointer to the buffer
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Mark Jones

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08