This works only if the text file is on C:\ Drive
But when you move the file to D:\ or any other is will not work.
Do some on have an full ASM file that can do the job completely
And also could someone tell me why this good piece of code don't complete the job.

.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:SWORD


include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\gdi32.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc

includelib \MASM32\LIB\gdi32.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib


MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD

wsprintfA PROTO C :DWORD,:VARARG
wsprintf equ <wsprintfA>

.data

Buffer db 56 dup (0)

MyText db "C:\1.txt",0

BoxCaption db 'Text Show up from C:\ but Do not show when on D:\',0

.data?

hFile dd ?
NumBytesWritten dd ?
Bytes dd ?


.code
Main:
; ..................................................................................................

invoke CreateFile, ADDR MyText, GENERIC_READ, 0, 0,OPEN_EXISTING, 0, 0
mov hFile, eax

invoke GetFileSize,hFile,NULL
mov Bytes,eax

invoke ReadFile, hFile, ADDR Buffer,Bytes, ADDR NumBytesWritten, 0
invoke CloseHandle,hFile

invoke MessageBoxA, NULL, ADDR Buffer, offset BoxCaption, NULL
invoke ExitProcess,0
; ..................................................................................


end Main
Posted on 2002-01-03 01:49:38 by cmax
Hossa

try out the example from Thomas = read text to listbox ,ehrm i dont know his homepage actual but i take a look on my coding pc and post later this day the source...

sorry i dont know enough about file functions,but i think your error his here : OPEN_EXISTING
i mean there must be more.....but before i say something wrong i better take a look at the sample.
Posted on 2002-01-03 03:08:58 by Max
It worked for me -- did you move the file and change MyText?

Here's my FAsm equivilent:
Posted on 2002-01-03 03:34:15 by eet_1024
I don't understand why it did not work for me. I been at it for two days now. But your is working on my machine. I'm going to combine your code with it right now. I never seen that style of coding before.

Thanks Guys
Posted on 2002-01-03 03:52:41 by cmax
Was your code written in masm or tasm.
Mabe it time for me to learn something new???
Posted on 2002-01-03 04:21:18 by cmax
What error codes did you recieve? You did check for errors didn't you?
Posted on 2002-01-03 05:39:24 by Boggy
I got that test piece working....eet_1024 guested it.
The reason why is because I put it in my main project first and the project is so big (only one big A file) that i got confussed than i finally went to check the test piece to make sure it work....I got loss...The test piece work but it still WILL NOT work in the app so i am going to have to move stuff around AGAIN untill i find the right point. I got a read file in the app but i just want a smaller one with less API that use StrLen. I ALMOST JUMP THE SHIP...

Thanks for putting up with me....

Sincerly
Posted on 2002-01-03 07:03:52 by cmax
I really find it hard to believe that you wasted two days chasing up this bug becuase you didn't put in place some simple error handling logic. The moral of this story is CHECK FOR ERRORS!

Anyway at least you didn't jump ship, all's well that ends well I suppose ;)
Posted on 2002-01-03 08:50:30 by Boggy
Boggy, My problem is ...I am from the Delphi World and there i did not have to lerarn nothing. I been in ASM for well over a good year now but before i found the Board i only played by key strokes, no true learning. Still telling myself to go back to the Big D ....I don't even know how to do error stuff. But i did managege to put together a file with well over 10,000 lines in it.....It Don't mean jack...but it is fun to do in my spare time. I am just happy i can get some spare time to do it....Now I am really intrested in ASM for life....

All of you guys willl get it soon......I owe all of them at lease that much. They brought me so far in so little time. ..... Unbeliable for a slow guy like me....

Thanks

PS: What's up with that ERROR thing.... Is there some notes about it somewhere....
Posted on 2002-01-03 12:00:59 by cmax
Hi all,

cmax,

i've lokked at your code.
It seems perfect, without errors. So i've cutted and pasetd and translated in Tasm5.0 syntax. It works without any problem, at the same way in C:\ & in D:\ ! I've attached the working code.

As Boggy already sayd, the only way is to check where is the error:

i suggest to lear to use a good debugger as for example OllyDbg, the one i use (is free).
With this you can look at the data segment, and chek if the string is read or not. Looking eax value after every invoke (call) performed you can see what's the function that fail:

in D,
1) CrateFile fail or not ?
2) ReadFile fail or not ?
3) String is read in data segment @buffer position ?
4) MessageBox Fail ?

Hope you'll resolve.. cause it's very courios :) good luck :alright: ,
B7
Posted on 2002-01-03 13:04:31 by Bit7
I plan to rewrite everything from top to bottom and squrid in the Good Codes. I don't care what no body say, Windows proved to me that if you don't do it his way he got a bit waiting for YOU to make you conform......Have you ever heard other Coders post saying "IT WAS WORKING YESTERDAY BUT IT'S NOT WORKING TODAY"

Maybe it just me....Now i think i know why, it's all in M$ API.

Thank Bit7

Now i know what to do......Read...Read....Read...and read-CODE





GOING DEEPER...ASM Forever

Posted on 2002-01-03 16:04:27 by cmax
cmax wrote:

PS: What's up with that ERROR thing.... Is there some notes about it
somewhere....



Well error checking and handling is probably one of the first rules you learn
when you begin programming--but you came for Delphi so you can of course be
forgiven ;)

The theory is that if you always validate your input you'll always get
valid output. It's really all about being defensive and making sure that
anything that can go wrong is checked thoroughly and dealt with if
something does go wrong. It's a little bit more work but it pays of
in spades--would have saved you two nights of late night hacking :)

Sometimes it can become overkill and but if you set yourself standards and
stick to them your programs will benifit. For example I always check the
allocation and release of memory--regarless of whether I (think I) know that
the call with definitely succeed--this includes file handles, device contexts
etc. I also like to check the success of GDI functions, most people don't
because it's either too much work or they think they'll be able to see if
anything errnoeous occurs. My experience is that subtle bugs can start
creep up in your code that won't bite for weeks.

Anyway here's my version of your code. I've snipped the irrelevant parts but
the full source is attached if you need it. Have a look at error_msg() I've
found it to be quite useful. Some people might think that the extra
MessageBox calls are overkill but it's up to you to decide what you think is
appropriate. This is just how I believe the errors should be handled, take it
with a grain of salt.




invoke CreateFile, addr filename, GENERIC_READ, 0, 0, OPEN_EXISTING, \
FILE_ATTRIBUTE_NORMAL, NULL

.if (eax == INVALID_HANDLE_VALUE)
invoke error_msg

invoke MessageBox, NULL, SADD ("Unable to retrieve file handle."), \
NULL, MB_ICONERROR
.else
mov file, eax

invoke GetFileSize, file, NULL

.if (eax == 0ffffffffh)
invoke error_msg

invoke MessageBox, NULL, SADD ("Unable to retrieve file size."), \
NULL, MB_ICONERROR
.else
mov file_size, eax
invoke ReadFile, file, addr buffer, file_size,
addr bytes_written, NULL

.if (eax == 0)
invoke error_msg

invoke MessageBox, NULL, SADD ("Unable to retrieve file contents."), \
NULL, MB_ICONERROR
.else
invoke MessageBox, NULL, addr buffer, SADD ("File Buffer:"), \
MB_ICONINFORMATION
.endif
.endif

invoke CloseHandle, file

.if (eax == 0)
invoke error_msg
invoke MessageBox, NULL, SADD ("Unable to retrieve file size."), \
NULL, MB_ICONERROR
.endif
.endif

invoke ExitProcess, 0



Check out some of the messages I caught during testing. It makes for great
wall paper :D

Cheers,
Boggy
Posted on 2002-01-03 23:31:07 by Boggy
I almost forget the code! My build environment is a bit different but you should have no problems modifying my batch file if needs be. I pilferred some macros from the masm package so there shouldn't be any dependency issues.
Posted on 2002-01-03 23:36:50 by Boggy
That makes a lot of sense to me now Boggy....Back when i was working with Icz Tutes I came in avoiding the Messgage box stuff. You made the impotants of using Message Box for ERROR CHECKING Loud & Clear...I will never again write or use a single piece of code without ERROR CHECKING again..........

By the way I that sequence of code was posted here on the board by someone else. Search the Strings or Buffer section to find it I can't think of his name right now....It feel good to hear someone say the word My Code, but I am only the Brick Layer and do not deserve to be called a true Coder. At lease not just yet....

Thanks
Posted on 2002-01-04 03:39:50 by cmax
Yes I believe I posted it to someone earlier this week .

See Here:
http://www.asmcommunity.net/board/index.php?topic=2637
Posted on 2002-01-04 05:26:10 by Boggy
No Boggie, I got that two or three months ago, I find the name latter and fill it in in the above post...

Boggie, it may see simple for a man of your caliber but it be nice to see your format listed in Icz. source code files.

You are the answer to my prayer. Over ? of my post was about How do you Know if Context is in the Buffer or not. I am sure i miss leaded a lot of people because they figured i have at lease been through Iczelion Tutes so many did not know what i was taking about.

With your Explanation i even did this and from this I will solved ALL of my problems....
............................................................
invoke GetFileSize, hFile, NULL
.if eax < 10........... ; or whatever
invoke MessageBoxA, NULL, ADDR hFile, offset BoxCaption, NULL
.else

Now i am a True Coder....
...............................................................
For all of you NewBeeee out there, It's all in Iczelion's Tutes and don't overlook a single step LIKE I DID or you will Pay for it down the line...

Just like Angelo told me a while back
This is the GREATEST Message Board in the WORLD....

Now it's time to me to be a f0dder and move on to the Heavy stuff, (like Indexing, Exception, Arrays, and so forth)

By the way f0dder, you are a Great man for the job so don't crack under pressure... You know you are going to have to deal with a lot of D____ S____ sometime.

Thanks Again EveryBody

Posted on 2002-01-04 07:47:56 by cmax
Now i am a True Coder....
...............................................................


Are you ready for the initiation rights and the
Blood oath?:grin:
Posted on 2002-01-04 14:57:57 by farrier