0 terminated?

Posted on 2011-10-10
Last Modified: 2012-05-12
The following code outputs the first two letters of a file called test.txt.
test.txt has the letters abcd and nothing else in it.
When I display the ab with StdOut there is no error message but I have cause to wonder... shouldn't that string be null terminated?
Should I be manually placing a 0 at the end of it?

  .model flat, stdcall
  option casemap :none

  include \masm32\include\
  include \masm32\macros\macros.asm

  include \masm32\include\
  include \masm32\include\
  include \masm32\include\
  include \masm32\include\

  includelib \masm32\lib\masm32.lib
  includelib \masm32\lib\gdi32.lib
  includelib \masm32\lib\user32.lib
  includelib \masm32\lib\kernel32.lib

    filename db "c:\masm32\assembly projects\fopen\test.txt",0    
    file_handle HANDLE ?
    file_buffer DWORD 256 dup (?)
    readC DW ?

  invoke CreateFile,ADDR filename,GENERIC_READ,FILE_SHARE_READ,
  mov file_handle,eax
  invoke ReadFile,file_handle,ADDR file_buffer,sizeof(BYTE)*2,ADDR readC,NULL
  invoke StdOut,ADDR file_buffer
  invoke CloseHandle,file_handle

end start

Open in new window

Question by:aiakonai
    LVL 53

    Accepted Solution

    You read two bytes from the file, and place them in the buffer.

    Nothing else is placed in the buffer, so it will contain those two bytes, and whatever happened to be in the buffer before the ReadFile call.

    If you want it to be null terminated, then you have to add the '\0' byte yourself, as you correctly assume.

    Author Closing Comment

    Thanks. I'm still new to 32 bit assembly ... just making sure I know is what I know.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
    When we have a dead host and we lose all connections to the ESXi, and we need to find a way to move all VMs from that dead ESXi host.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now