News:

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

download status

Started by ragdog, June 23, 2007, 05:49:08 AM

Previous topic - Next topic

ragdog

hi guys


i have this code from genesys downloader

and I would like to print the downloaded  bytes in megabytes
can help their me further

OnProgressProc PROC lpThis:DWORD, ulProgress:DWORD,ulProgressMax:DWORD,ulStatusCode:DWORD,szStatusText:DWORD
   
     cmp ulProgress,1024
     jne @next
    inc Done
   
  @next:
   invoke wsprintf, addr szStringBuff, CTEXT("%i Mb %i bytes"), Done,ulProgress
   
   invoke SendMessage, hBytes, WM_SETTEXT, 0, offset szStringBuff
   invoke SendMessage, hProgress,PBM_SETRANGE32,0,ulProgressMax
   invoke SendMessage, hProgress,PBM_SETPOS,ulProgress, 0
   mov eax, S_OK
   ret
OnProgressProc ENDP

Shantanu Gadgil

Hi,

Small world ... eh!...similar software ... similar issues  :bg  :wink
I had done it in C so will post the code ... maybe that would help ?
It takes care of GB, MB, KB or Bytes

Note: File sizes larger 4GB are not handled !!!  :lol

*** The "FLOAT" part would have to be done with the help of the FPU (I think).


if(dwSize >> 30)
{
DWORD dd;
FLOAT ff;
ff = (FLOAT) (dwSize & 0x3fffffff);
ff *= 100;
ff /= 1073741824L;

dd = (DWORD)ff % 100;

wsprintf(szTemp,"%u.%u GB",(dwSize >> 30),dd);
}
else
if(dwSize >> 20)
{
wsprintf(szTemp,"%u.%u MB",(dwSize >> 20),
((dwSize * 100) >> 20) % 100);
}
else
if(dwSize >> 10)
{
wsprintf(szTemp,"%u.%u KB",(dwSize >> 10),
(((dwSize * 100) >> 10) % 100) );
}
else
{
wsprintf(szTemp,"%lu bytes", dwSize);
}
SetDlgItemText(hDlg,IDS_SIZE, szTemp);



Regards,
Shantanu
To ret is human, to jmp divine!

ragdog

thx

i understand not

can anywhere convert to masm32 lang for my problem

thx in forward

donkey

Hi Ragdog,

I once did a floating point routine for converting memory size in bytes to Gigabytes plus a decimal fraction, it can easily be converted to a default of megabytes. Note that this routine is not limited to 4GB.

GoAsm syntax
MemorySizeToString FRAME pDriveSize,pOutput
uses ebx
LOCAL dwDivisor :D
LOCAL float :Q

// Default is in gigabytes
mov ebx," GB"
mov eax,[pDriveSize]
// Load st0 with the size qword
fild Q[eax]
// check to see if the size is greater than 1 GB
mov D[dwDivisor],1073741824
ficom  D[dwDivisor]
fstsw ax
fwait
sahf
ja >
// check to see if the size is greater than 1 MB
mov ebx," MB"
mov D[dwDivisor],1048576
ficom  D[dwDivisor]
fstsw ax
fwait
sahf
ja >
// The size is less than a MB so measure it in KB
mov ebx," KB"
mov D[dwDivisor],1024
:
fild D[dwDivisor]
fdivp st1,st0

fstp Q[float]
mov eax,[float]
mov ecx,[float+4]
CInvoke(msvcrt.dll:_gcvt,eax,ecx,6,[pOutput])

mov [dwDivisor],ebx
invoke szCat,[pOutput],offset dwDivisor
RET
ENDF



By the way the routine that Shantanu Gadgil posted is easily converted since it uses only API calls to do the conversion.

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

ragdog

thanks donkey :U

greets
ragdog

Shantanu Gadgil

Hi,

Something along these lines ???
...

.const
szGB  db  '%u.%u GB',0
szMB  db  '%u.%u MB',0
szKB  db  '%u.%u KB',0
szBytes  db  '%u bytes',0

.data?
szTemp  db  512 dup(?)
.code

...

;for the MBs
mov eax, dwSize
shr eax, 20
.if eax > 0
  mov dwNum, eax
 
  xor edx, edx
  mov eax, dwSize
  mov ebx, 100
  mul ebx
 
  shr eax, 20
  xor edx, edx
  mov ebx, 100
  div ebx
  ;edx should now have the remainder
 
  invoke  wsprintf, addr szTemp, addr szGB, dwNum, edx
  jmp @f
.endif

;KBs here ...

;bytes here ...

@@:
invoke  SetDlgItemText, hDlg, IDS_SIZE, addr szTemp


Regards,
Shantanu
To ret is human, to jmp divine!

donkey

Quote from: ragdog on June 23, 2007, 06:14:25 PM
thanks donkey :U

greets
ragdog

No problem Ragdog, but I should caution that my routine works on 64 bit numbers only, you can use the CDQ to convert a dword to a qword if you like however for 32 bit numbers Shantanu's routine is probably much much faster and equally as accurate. However it does not easily adapt to allowing for dynamic precision or the capability to handle truly large files (> 4GB).
"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

ragdog

to donkey

it is correct convert to masm32?

MemorySizeToString proc  pDriveSize:DWORD,pOutput:DWORD
LOCAL dwDivisor :DWORD
LOCAL float :QWORD

;// Default is in gigabytes
    mov ebx," GB"
    mov eax,[pDriveSize]
;// Load st0 with the size qword
   fild QWORD PTR[eax]
;// check to see if the size is greater than 1 GB
    mov DWORD PTR[dwDivisor],1073741824
  ficom DWORD PTR[dwDivisor]
  fstsw ax
  fwait
   sahf
     ja @1
;// check to see if the size is greater than 1 MB
    mov ebx," MB"
    mov DWORD PTR[dwDivisor],1048576
  ficom DWORD PTR[dwDivisor]
  fstsw ax
  fwait
   sahf
     ja @1
;// The size is less than a MB so measure it in KB
    mov ebx," KB"
    mov DWORD PTR[dwDivisor],1024
@1:
   fild DWORD PTR[dwDivisor]

  fdivp st(1), st(0)
   fstp QWORD PTR[float]
    mov eax,DWORD PTR[float]
    mov ecx,DWORD PTR[float+4]
Invoke crt__gcvt,eax,ecx,6,[pOutput]
    mov [dwDivisor],ebx
invoke lstrcat,[pOutput], dwDivisor
ret
MemorySizeToString ENDP


regards ragdog

donkey

Hi ragdog,

GoAsm automatically reverses quoted text moved into a register, so where you see

mov ebx, " MB"

you will have to change it to

mov ebx, "BM "

or some such. I no longer run MASM on my machine so I cannot compile the version you posted but someone here might be able to. Other than that one small issue it looks OK but I may have missed something, MASM just looks so messy to me now that I have trouble reading it.

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