News:

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

Masm32.lib

Started by hojozs, February 05, 2007, 08:05:25 PM

Previous topic - Next topic

hojozs

Hello,
What Wrong do I do?
I have made with some conversions in masm32.lib - atodw, dwtoa,
atool, ltoa, htodw, dw2hex - in same manner as hex2bin, bin2hex,
floattostr, but failed.

I use for the write display the Iczelion's sample, paint.asm.
For example, with hex2bin I wrote:

.data
...
hexsrc dd 41H
bindest db 32 dup (?)

.code
...
invoke hex2bin, addr hexsrc, addr bindest

WndProc ...
invoke DrawText, hdc,ADDR bindest, -1, ADDR rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER
invoke EndPaint,hWnd, ADDR ps
...

I should wait for the contents of "bindest" buffer, or a text string of
binary numbers.


Thank for your explanation.

Jozsef

--------------------------------------------------------------------------------

ChrisLeslie

It could be that you are not refreshing the window display with InvalidateRect after you generate your bindest string .

MichaelW

For hex2bin the source must be a hex string in the correct format. The acceptable characters are 0 to 9, a to f, and A to F. There are two hex digits per byte so these characters must be paired. The ignored characters are space, minus, CR, LF, and the comment character ";".

Here is a quick demo of bin2hex and hex2bin. For bin2hex the length of the destination buffer must be at least 3 times the length of the source buffer, plus 3 bytes.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data

      bindata db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

      hexdata db 51 dup(0)

      bindata2 db 16 dup(0)

      hexdata2 db "000102030405060708090a0b0c0d0e0f",0
     
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
   
    invoke bin2hex,ADDR bindata,16,ADDR hexdata
    print ADDR hexdata,13,10

    invoke hex2bin,ADDR hexdata,ADDR bindata2
    xor ebx,ebx
    .WHILE ebx < 16
      movzx eax, BYTE PTR [bindata2+ebx]
      print ustr$(eax)," "
      inc ebx
    .ENDW
    print chr$(13,10)

    print ADDR hexdata2,13,10
   
    invoke hex2bin,ADDR hexdata2,ADDR bindata2
    xor ebx,ebx
    .WHILE ebx < 16
      movzx eax, BYTE PTR [bindata2+ebx]
      print ustr$(eax)," "
      inc ebx
    .ENDW
    print chr$(13,10)

    inkey "Press any key to exit..."
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


00 01 02 03 04 05 06 07 - 08 09 0A 0B 0C 0D 0E 0F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
000102030405060708090a0b0c0d0e0f
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


EDIT:

I failed to see "I should wait for the contents of "bindest" buffer, or a text string of
binary numbers." The procedures hex2bin and bin2hex have nothing to do with binary strings (strings of "0"s and "1"s). For that you can use the byt2bin_ex and bin2byte_ex procedures.
eschew obfuscation

sinsi

invoke DrawText, hdc,ADDR bindest, -1, ADDR rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER

Maybe -1 (FFFFFFFF) is the wrong string length? The SDK talks about a value of 1 but not -1
QuoteIf nCount is 1, then the lpString parameter is assumed to be a pointer to a null-terminated string and DrawText computes the character count automatically.
Light travels faster than sound, that's why some people seem bright until you hear them.

MichaelW

The value -1 should work OK for a null-terminated string. The first problem that I can see is the format of hexsrc, which is causing the

invoke hex2bin, addr hexsrc, addr bindest

To fail and return an error code of 1: invalid hex format, characters must be in pairs.
eschew obfuscation