News:

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

Param wsprintf

Started by gvjuwlfomxqk, February 08, 2011, 07:10:56 PM

Previous topic - Next topic

gvjuwlfomxqk

Bonjour, je suis bloquer, je recherche a mettre un parametre en plus mais rien ne passe.
Je voudrais mettre la date entre Gen et les chiffres (%03u = 000 + loop inc 1)

Hello, I'm blocked, I was looking to put an extra parameter but nothing happens.
I would put the date between Gen and figures (%03u = 000 + loop inc 1)

%s\Gen_%03u.TXT
%s\Gen_%DATE%-%TIME%_%03u.TXT




call time
call Day
push offset lpOutime
push offset lpOutdate
call lstrcat

Time proc near
invoke GetSystemTime,offset lpSystemTime
movzx eax, lpSystemTime.wHour
movsx ebx, lpSystemTime.wMinute
movsx edi, lpSystemTime.wSecond
invoke wsprintf,addr lpOutime,addr lpFmt,str$(eax),str$(ebx),str$(edi)
ret
Time endp
Day proc near
movzx eax, lpSystemTime.wDay
movsx ebx, lpSystemTime.wMonth
movsx edi, lpSystemTime.wYear
invoke wsprintf,addr lpOutdate,addr lpFmt2,str$(eax),str$(ebx),str$(edi)
ret
Day endp


invoke  wsprintf,offset FileName,SADD("%s\Gen_%03u.TXT"),offset FileName,dwFileNameCount

qWord

What exactly is the problem? - look here:
Quoteinclude masm32rt.inc
.code
main proc
LOCAL sz[256]:BYTE
LOCAL dwFileNameCount:DWORD
   
    .if !rv(GetStdHandle,STD_OUTPUT_HANDLE)
        invoke AllocConsole
    .endif
   
    mov dwFileNameCount,1
    fn  wsprintf,ADDR sz,"Gen_%04u.TXT",dwFileNameCount
    print ADDR sz,13,10

    mov dwFileNameCount,1234
    fn  wsprintf,ADDR sz,"Gen_%04u.TXT",dwFileNameCount
    print ADDR sz,13,10
   
    inkey
    invoke ExitProcess,0

main endp
end main
FPU in a trice: SmplMath
It's that simple!

gvjuwlfomxqk

Thanks... For help.
include masm32rt.inc

include \masm32\macros\macros.asm
.data
lpSystemTime  SYSTEMTIME <>
lpFmt  db "%sh%smin%s",0
lpFmt2  db "%s-%s-%s_",0
.data?
lpOutime db 100 dup (?)
lpOutdate db 100 dup (?)

.code
main proc
LOCAL sz[256]:BYTE
LOCAL dwFileNameCount:DWORD
   
    .if !rv(GetStdHandle,STD_OUTPUT_HANDLE)
        invoke AllocConsole
    .endif


invoke GetSystemTime,offset lpSystemTime
movzx eax, lpSystemTime.wHour
movsx ebx, lpSystemTime.wMinute
movsx edi, lpSystemTime.wSecond
invoke wsprintf,addr lpOutime,addr lpFmt,str$(eax),str$(ebx),str$(edi)
movzx eax, lpSystemTime.wDay
movsx ebx, lpSystemTime.wMonth
movsx edi, lpSystemTime.wYear
invoke wsprintf,addr lpOutdate,addr lpFmt2,str$(eax),str$(ebx),str$(edi)

invoke lstrcat,offset lpOutdate,offset lpOutime

mov dwFileNameCount,1
fn  wsprintf,ADDR sz,"Gen_%s_%03u.TXT",offset lpOutdate,dwFileNameCount
print ADDR sz,13,10


   
inkey
invoke ExitProcess,0

main endp
end main

Magnum

This is what I get for today, 2/9/11.

Gen_9-2-2011_14h9min36_001.TXT
Press any key to continue ...
Have a great day,
                         Andy

donkey

.data
dateformat DB "yyyy'-'MM'-'dd'_'",0
timeformat DB "hh'h'mm'm'ss's_%0.3u.txt'",0
dwFileNameCount dd 1

.data?
sztime db 256 dup (?)
FileName db MAX_PATH dup (?)

.code

mov DWORD PTR [sztime],"_NEG"
invoke GetDateFormat,2048,NULL,NULL,offset dateformat,offset sztime + 4,64
add eax,offset sztime + 3
invoke GetTimeFormat,2048,NULL,NULL,offset timeformat,eax,64
invoke wsprintf,offset FileName,offset sztime,[dwFileNameCount]


Output:

GEN_2011-02-09_11h08m46s_001.txt

You may also want to take a look at GetTempFileName if all you need is a unique file name.

Edgar
"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

donkey

#5
Here's another one, gets rid of the final wsprintf but limits the dwFileNameCount to a maximum of 255

.data
dateformat DB "'GEN_'yyyy'-'MM'-'dd'_'",0
timeformat DB "hh'h'mm'm'ss's_000.txt'",0
dwFileNameCount dd 1
.data?
FileName db MAX_PATH dup (?)

.code

invoke GetDateFormat,2048,NULL,NULL,offset dateformat,offset FileName,64
add eax,offset FileName -1
invoke GetTimeFormat,2048,NULL,NULL,offset timeformat,eax,64
mov eax, [dwFileNameCount]
aam
mov dl,al
shr eax,8
aam
shl eax,8
mov al,dl
shl eax,8
add eax,3030302eh
bswap eax
mov DWORD PTR [FileName+25],eax


output:

GEN_2011-02-09_11h08m46s_001.txt

EDIT: Added support up to 255
"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

donkey

Still playing around with this, if you're not concerned with the time being human readable, you can use a timestamp instead of the nicely readable date and time.

.data?
SysTime FILETIME <?>
dwFileNameCount DD ?

.code
invoke GetSystemTimeAsFileTime,offset SysTime
mov eax,[SysTime.dwLowDateTime]
mov edx,[SysTime.dwHighDateTime]
sub eax,0D53E8000h
sbb edx,0019DB1DEh
mov ecx,10000000
div ecx
invoke wsprintf,offset FileName,"GEN_%u_%0.3u.txt",eax,[dwFileNameCount]


Output:

GEN_1297284751_001.txt

1297284751 is translatable back to a  file time programatically:

; converts a timestamp to a FILETIME structure
mov eax,[TimeStamp]
mov edx,10000000
mul edx
add eax,0D53E8000h
adc edx,0019DB1DEh
mov [SysTime.dwLowDateTime],eax
mov [SysTime.dwHighDateTime],edx

"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