News:

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

question about some of the HLL functions

Started by Rainstorm, December 14, 2006, 03:39:50 AM

Previous topic - Next topic

Rainstorm

Hi.

In some of the HLL functions, do they automatically zero-terminate the text ?
like in the following.. (since they work fine without adding a truncating '0')

mov ebx, offset chr$("Its getting Late...")

or,  in the file open function - in the example given there..since just "existingfile.ext" is given as the parameter & not "existingfile.ext",0
mov hFile, fopen("existingfile.ext")

thanks!

hutch--

Rainstorm,

The trick is to have a look at the actual macro in the macros.asm file. The pseudo high level functions are reasonably well documented so its worth having a look at it as well.

Any of the macros that handle quoted text insert the trailing zero to make the macro more like a high level language.

The "chr$" macro is so you can insert mixed quoted text and direct ascii numbers. You can either point its return value at a memory operand,

Quote
mov pString, chr$("Howdy",13,10)

or you can use it directly in a function as long as you are aware of how it works.

Quote
invoke MessageBox,hWnd,chr$("My 1st line",13,10,"My second line"),chr$("Title"),MB_OK
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Rainstorm

Thanks for the confirmation hutch,.. i looked at the chr$ macro & this is the line that does that i suppose...
.data
  txtname db any_text,0


just another related question...
in the fread & fwrite functions..numbers retain their value, meaning they are not read as values that represent the ascii character, like in the case of the MessafeBox function. - i looked
at the fread macro & there doesn't seem to be anything that adjusts this, So i suppose its the
way that the WinAPI handles it (differently) that causes the diff..?

like for the message box function if the text was 5 it would output some other contol (ascii)
character...& it would have to be converted to the relevant ascii value (53) to pe outputted as 5
but with fread/fwrite this doesn't happen.

ty


hutch--

the two file IO macros below are basically straight wrappers for the Windows API calls. Tjhey differ in that the DWORD sized value they write to is returned as a return value if you need to use them.


  ; ------------------------------------------------
  ; read data from an open file into a memory buffer
  ; ------------------------------------------------
    fread MACRO hFile,buffer,bcnt
      LOCAL var
      .data?
        var dd ?
      .code
      invoke ReadFile,hFile,buffer,bcnt,ADDR var,NULL
      mov eax, var
      EXITM <eax>       ;; return bytes read
    ENDM

  ; ----------------------------------------
  ; write data from a buffer to an open file
  ; ----------------------------------------
    fwrite MACRO hFile,buffer,bcnt
      LOCAL var
      .data?
        var dd ?
      .code
      invoke WriteFile,hFile,buffer,bcnt,ADDR var,NULL
      mov eax, var
      EXITM <eax>       ;; return bytes written
    ENDM


I am not sure what you are after here.

Quote
like for the message box function if the text was 5 it would output some other contol (ascii) character...& it would have to be converted to the relevant ascii value (53) to pe outputted as 5 but with fread/fwrite this doesn't happen.

Text based arguments always require an address of text, the macros that are designed for it place the quoted text in the .DATA section and return the address of that text. If you look at the two macros above, the both require  buffer address, on for input data and the other for output data.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Rainstorm

thanks hutch..

kind of a trivial question :)
i meant  like whatever data the fread API for example is reading from the file & then putting in the
buffer; suppose for example part of that text is numbers..it seems to get read correctly. - unlike in the messagebox function where if you input say the value 54 the display will show 6,(the number that corresponds to that ascii code) & not the number '54' itself. & you'd need to
convert it to an ascii string if you wanted to show the number 54 in thee MessageBox.
- But in fread , the function seems to take care of that while reading numbers from the file into the buffer.

hutch--

Rainstorm,

I think you have mixed up a couple of things here, data read from a file is just that, data and it gets loaded into a buffer. With a text based API like MessageBox it expects the address of a zero terminated string and a bare ascii character does not do that.

There are a number of ways to display text from API calls that expect an address.


.data
  mytext db "my text",0
  mytitle db "my title",0

.code
.......
; direct manual code specifying the address
invoke MessageBox,hWnd,ADDR mytext,ADDR mytitle,MB_OK

; using a macro within the API call
invoke MessageBox,hWnd,chr$("my text"),chr$("my title"),MB_OK

; using the "fn" macro that allows direct quoted text
fn MessageBox,hWnd,"my text","my title",MB_OK


If for example you need to display a number as in your posting, you must convert it to a string using one of the macros or one of the conversion procedures in the masm32 library. Once the numeric data is converted to a string, then you display it by using its address.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Rainstorm

hutch..,
Thankyou for the explanation.
I keep having a problem knowing whether the data will be outputed/interpreted as the value or the
Ascii character.
That cleared things up a bit

Rainstorm.
-