Ok, my app is comming right along. Now I need to count the number of images in the file.
To do this I reserve the first three chars for the image counter.

IE the file might look like:

2 C:\a.jpg C:\b.jpb


ok now when I read the first three characters into my ImageCount DWORD it doesnt work.
I invoke MessageBox,NULL,ADDR ImageCount........
And it displays a box character.

Am I allowed to read a number from a file and perform arithmatic on the variable?

Heres a play by play:

invoke ReadFile, hFile, addr ImageCount, 3, OFFSET NumberOfBytesRead,NULL
;i've read the first three digits

inc ImageCount
;now i must incriment the number by one because this code is in the 'Add A Picture' section
invoke MessageBox, NULL,addr ImageCount, addr AppName,MB_OK

;check to see what has been read into the variable [not what i want]

mov eax, ImageCount
mov ImageCountMul, eax
mul ImageCountMul
;ImageCountMul will be used to set the FilePointer (128 chars per image)
invoke MessageBox, NULL,addr ImageCountMul, addr AppName,MB_OK
;check displays nothing.
mov eax, ImageCountMul
add FilePointer, eax
;New file pointer is set. ie if ImageCount was 2 it was eventually multiplied by 128 = 256
;which is where the next WriteFile should be pointed to.

invoke MessageBox, NULL,addr FilePointer, addr AppName,MB_OK
;Another box char is diplayed

invoke SetFilePointer, hFile, FilePointer, 0,FILE_BEGIN
;Should mov the pointer to the next logical space for a picture location in the file
invoke WriteFile,hFile, ADDR buffer,128,OFFSET NumberOfBytesRead,NULL
invoke CloseHandle,hFile
;But it does not write a new location to the file.
Posted on 2003-03-16 16:10:10 by Homer
Hi Homer,

You know that characters and numbers are stored differently right. If you have a number stored in a file they are stored as follows (BIGENDIAN)

Your data : 00 00 00 01

stored as charaters : 00 00 00 01

stored as number : 01 00 00 00

BTW the BSWAP mnemonic will take care of this (486+)

The characters are reversed when they are stored as a number. Also if you store the data as Character "2" then you have to perform an ascii to numeric conversion before you use it, if you store it as a ascii 02 then no conversion is necessary. From what you have shown it is stored as a character so "2" is acutally 032h and not 02h. You would be better off if you stored the full DWORD value instead of just 3 bytes, that is a weird kind of data length to choose as it doesn't match any standard type.These are just some ideas for you to check.

Posted on 2003-03-16 16:23:17 by donkey
How do I store it as ascii 02?

I don't understand what you mean by that and I don't want to do any conversion.

What lenght should I use for my DWORD?

And what's the BSWAP nmemonic?
Posted on 2003-03-16 16:27:37 by Homer
I suppose I need to write my own conversion code :mad:

So much work for a little task! ARGHGHGHHGHG

oOk time to break out the text book.
Posted on 2003-03-16 16:47:00 by Homer
If you're using MASM32 use atodw, it'll do the conversion for you.

To write a number (an acutal number) to a file use the WriteFile function but a pointer to a DWORD variable instead of your text version and 4 as the buffer size. Do the same when you read and the BSWAP won't be necessary. BSWAP reverses the byte order of a WORD or DWORD ie 01020304 becomes 04030201, if you read a number byte by byte into a text buffer you will get it in reverse order BSWAP will correct it to Intel format. Just use pointers to DWORDs instead of text buffers (ie BYTE) pointers and you won't have a problem. The fact that you used 3 characters made this impossible, bump it up to 4 and use a DWORD instead.

mov MyCounter,eax
invoke WriteFile,hFile, ADDR MyCounter,4,OFFSET NumberOfBytesRead,NULL
;move your file pointer ahead by 4
invoke WriteFile,hFile, ADDR buffer,124,OFFSET NumberOfBytesRead,NULL

Posted on 2003-03-16 17:06:14 by donkey
Hey that doesn't work Donkey.
I've been using a DWORD and now I read in 4 chars from the file "0008" to the DWORD

I tried using that DWORD to set the file pointer, but it winds up not moving the pointer at all.
Posted on 2003-03-17 02:21:20 by Homer

If you're using MASM32 use atodw, it'll do the conversion for you.

invoke atodw, addr MyDWORD

is this correct?

Do you think i could use StrToFloat ?

I've been playing around with it but nothing so far

I've been playing around with atodw (ascii to doubleword?) too trying to use it as my filepointer
but it only results in HUGE disk writes, (i'm talking 800-20,000 MB's). :confused:

I'm assuming atodw is not properly converting the 4 character string into a DWORD integer.
I can't image what it's doing.
Any ideas out there?
Posted on 2003-03-18 02:35:09 by Homer

atodw puts the value in eax
after the invoke of atodw you must

mov MyDWORD, eax


FINALLY ! :grin:

why did you guys not tell me this?
Posted on 2003-03-18 03:30:01 by Homer
homer, you really ought to play around with a debugger. makes it easier to see what is going on.
Posted on 2003-03-18 11:52:34 by f0dder
where can I find a debugger?
Posted on 2003-03-18 15:05:36 by Homer
dbgwin.exe in the BIN folder of MASM32


EDIT : Sorry homer it's in the VKDEBUG folder of MASM32, I don't use that one but I thought it was in BIN, check the VKDEBUG folder instead.
Posted on 2003-03-18 15:06:59 by donkey
Posted on 2003-03-18 15:13:40 by Homer
Posted on 2003-03-19 02:07:28 by roticv

Ollydbg is the best tool for debugging applications.:alright:


Posted on 2003-03-19 02:39:05 by Vortex
ollydbug is kinda intimidating!

it's cool though =]
Posted on 2003-03-19 15:54:45 by Homer
Hi homer,

I use RadASM which has built in breakpoints, you just add a breakpoint with the mouse or ALT-F8 and when your program gets to that line it pauses and a little window pops open with information on various registers. The nice thing about this is you just select "Clear Break Points" when your ready for release code. What IDE do you use to write your programs ? Maybe it already has a simple debugging tool, it probably won't be as good as Ollydbg (I use that one for tough problems) but sometimes it is convienient if you just want to inspect the registers at a given line.

Posted on 2003-03-19 16:37:22 by donkey
I'm using QEDITOR.exe.
It needs revision though... especially the Keword Search.
Posted on 2003-03-19 21:03:34 by Homer
You can post wish-list items for it in the MASM32 forum. Hutch runs that forum and he is pretty quick to respond to the needs of the users of his stuff.

Posted on 2003-03-19 21:08:37 by donkey
I use RadAsm as editor and Ollydbg as debugger.
Nothing beat Ollydbg as a debugger (except SoftIce, which is too expensive for me to afford), just learn it well. It could be used for coding on the spot (ie to see your code in hex) and to see the values of the different registers.
Posted on 2003-03-19 22:02:49 by roticv
my code in hex is how the CPU sees my code right?

well that's a bit beyond my capabilities... the breakpoints is interesting though. I can use that and i'll prolly learn that feature first. Because as my program grows it becomes very unstable, causing my system to become unstable. And I thought Win2k doesn't crash! Well it doesn't... but sometimes when my program doesn't terminate properly, some instructions are left executing... Last night my program had to be force terminated and about 2 minutes later my computer wouldn't stop beeping! I tried to restart... which it did after about 3 minutes of beeping ... lol

So if I could throw a breakpoint in there... somewhere in there... that would be neat.

Anyway... I fixed that bug. =]

Now I'm looking for a resource editor, to change the look of my program a little, starting with an Icon. Then I want to give the menu a makeover if possible.

Do you guys know of a free one?
My friend has the Visual Studio 6 CD, is there one on there?
Posted on 2003-03-19 22:24:13 by Homer