News:

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

Write text to file causes extra bytes?

Started by hfheatherfox07, May 03, 2011, 12:17:09 AM

Previous topic - Next topic

hfheatherfox07

I seem to be a sucker for punishment I keep giving my self new ways to aggravate my self.... :bdg

I am nut sure how to write text file with out those extra bytes at the end ( I get these little square NULL's at the end) when I add variants to the text Like edit box input...


I know how to write text to file without those extra bytes with out user input ( see "Write into text file Example.zip" )

How do I correct this problem?

This indicates to me that my text file comes out as my buffer size ...
So If my buffer is db 100 dup (?) and did not input 100 bytes worth  ( little bytes are added in the shape of those annoying Null's)

I tried adding my buffer Locally instead in the data section , I tried a whole bunch of things and no luck ?

any ideas?


dedndave

which download has the write file code ?

i would guess the "bytes to write" are not calculated correctly

ragdog

You can fill %s with wsprintf

And better is Allcoate Mem for get the Text

hfheatherfox07

Quote from: ragdog on May 03, 2011, 12:31:04 AM
You can fill %s with wsprintf

And what mean you with extra bytes?


If you open the text file that" EditBox Example-Using '%S' to set word and print text_1.zip" and  "EditBox Example-Using '%S' to set word and print text_3.zip" have created
you will notice extra "NULL" printed ....
that is extra bytes so the file comes out to the specified buffer size which I do not want

hfheatherfox07

Please look at the text file created by : "Write into text file Example.zip" and you will see no "NULL"s -It  works great but as soon as I add that edit box user input .....

dedndave

no need to look at the file - i believe ya   :bg

right here....
invoke WriteFile,hFile,addr FinalszString ,sizeof FinalszString ,offset SizeReadWrite ,0
the number of bytes to write is the size in bytes of the buffer
that is not what you want
i am not sure what the szRep function does - lol
but, i bet it returns a length in EAX

also
the reason you need 2 attachments
that icon file is huge - 41 kB
each attachment has the icon twice - once as an icon and once inside the EXE
that icon file has a big image in it that Hutch uses for the installer
if you go back to the caps lock thread, i posted a modified version of that icon with the big image removed
it's about 10 kB

hfheatherfox07

Yes I admit I am one of the bright once  :lol

I made that Icon from a screen capture ... I must of added all 256 colors , 16x16, 32x32, etc

Thanks for pointing that out  ... It will save me some space on my PC ... my MASM work folder is getting quite big...

dedndave

i use an icon file that has a single icon, 16x16, 16 colors
it is 278 bytes   :P

hfheatherfox07

Quote from: dedndave on May 03, 2011, 12:41:56 AM
no need to look at the file - i believe ya   :bg

right here....
invoke WriteFile,hFile,addr FinalszString ,sizeof FinalszString ,offset SizeReadWrite ,0
the number of bytes to write is the size in bytes of the buffer
that is not what you want


So how do I transfer the "sizeof FinalszString" to a "sizeof DWORD ?"

In my example that works fine (without an edit box input) there is quite a clever way to fix that:

szText            db "your text here" ,10,13
                       db "your text here" ,10,13
                       db "your text here" ,0
szText_length         equ         $ -szText   <- This fixes that!!!

So :

invoke WriteFile,hFile,addr szText ,sizeof szText_length ,offset SizeReadWrite ,0

How do I add that to these examples ??

P.S
I got that "szText_length         equ         $ -szText "  From a scrolling text ASM



Gunner


invoke szLen, offset szText
invoke WriteFile,hFile,offset szText ,eax ,offset SizeReadWrite ,0 
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

szText            db "your text here" ,10,13
                        db "your text here" ,10,13
                        db "your text here" ,0
szText_length         equ         $ -szText   <- This fixes that!!!


actually, that includes the null terminator
so...
szText_length         equ         $-szText-1

Rob has a way to fix the current issue
but, that length may already be a known value - i was trying to figure out how to get it from already existing info
StrLen can take some time for long strings

hfheatherfox07

Quote from: Gunner on May 03, 2011, 01:03:57 AM

invoke szLen, offset szText
invoke WriteFile,hFile,offset szText ,eax ,offset SizeReadWrite ,0 


That gives me some wired characters at the ens of the file?

   @  ž "                                                                                                 

Gunner

No it doesn't....
Where do you have szLen in your source?


;invoke szLen, offset FinalszString <<<<<<<<<<<<<<<<<<<<<<<<<  NOOOOOOO
; Create a new file, overwrite any existing file.

invoke CreateFile,addr szFile ,\
GENERIC_READ or GENERIC_WRITE ,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,\ ; "CREATE_ALWAYS" will over write exixting file -> "CREATE_NEW" will NOT over write exixting file!
NULL

      .if eax!=INVALID_HANDLE_VALUE ;if file exists ... then                           
      mov hFile,eax
; Write our string the the file
invoke szLen, offset FinalszString ; <<<<<<<<<<<<<<< this should be here
invoke WriteFile,hFile,addr FinalszString ,eax ,offset SizeReadWrite ,0


and why do you have your wParam compares OUTSIDE of your WM_COMMAND handler?
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

hfheatherfox07

Thanks Gunner...

It works great now

By the way-
I am assembling off a USB stick ... using NOTEPAD2 as my editor ( I am not at my home computer so no MASM here)

I love this note pad it recognizes .asm files as others as well...

If any body is interested:

http://www.flos-freeware.ch/notepad2.html

There is Documentation on Replacing Windows Notepad too if you wish.

Try to open an asm file with it  :U



Thanks again Thanks Gunner...

Here is a copy if anybody wants it