Hello.
here is my code to read data from file:


.const
MAXSIZE equ 260
MEMSIZE equ 65535
.data
buffer db "index.txt",0
SizeRead DWORD 5

.data?
hFile HANDLE ?
hMemory HANDLE ?
pMemory DWORD ?

.code
start:
invoke CreateFile,ADDR buffer,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,CREATE_NEW,FILE_ATTRIBUTE_ARCHIVE,NULL
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov pMemory,eax
invoke ReadFile,hFile,pMemory,MEMSIZE-1,ADDR SizeRead,NULL
invoke MessageBox,0,pMemory,pMemory,MB_OK
invoke CloseHandle,hFile
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
mov hFile,eax

I get no erros, nothing but my MessageBox is empty....i knwo the file is tehre adn i got some text in the fiel....
what am i missiong?
btw the size of the data i want to read , how big go i need it to read one letter?
thx
Posted on 2005-02-01 12:54:15 by ReVeR
One letter needs one byte, though you'll maybe need a second zero byte for the null terminator.

As for you problem, the CREATE_NEW flag is porbably wiping the file clean before you can read from it.
Posted on 2005-02-01 13:08:28 by Eóin
got that working
but how can i compear stuff that i have loaded to a string?

what is the function and what links do i need to use it?
thx
Posted on 2005-02-01 13:31:00 by ReVeR
Hey.
I got a question.
i read the data from a file and now i am trying to pass the data into the FindWindow function...example:


.const
MAXSIZE equ 260
MEMSIZE equ 65535
.data
windowF db "[window]",0
dllF db "[dll]",0
SizeRead DWORD 256
.data?
hFile HANDLE ?
hMemory HANDLE ?
window LPCTSTR ?
dll LPCTSTR ?
.code
start:
invoke CreateFile,ADDR windowF,GENERIC_READ ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov window,eax
invoke ReadFile,hFile,window,MEMSIZE-1,ADDR SizeRead,NULL
invoke MessageBox,0,window,window,MB_OK
invoke CloseHandle,hFile
invoke GlobalUnlock,window
invoke GlobalFree,hMemory
invoke CreateFile,ADDR dllF,GENERIC_READ ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov dll,eax
invoke ReadFile,hFile,dll,MEMSIZE-1,ADDR SizeRead,NULL
invoke CloseHandle,hFile
invoke GlobalUnlock,window
invoke GlobalFree,hMemory
invoke FindWindow,addr window,0

teh data gets loaded and all, i can see it with the MessageBox function, but the find window function allways returns nothing for the handle....
any ideas on where i screwed up?
thx
Posted on 2005-02-01 14:56:27 by ReVeR
LPVOID is a C type it doesn't crop up much in asm. But its usually a 32bit pointer I suppose and since db is 8bits you'd need 4 of them to hold one.

Don't really mean to be so unclear with my answer but your question is equally unclear.

My guess would be that you want to pass a string to a function which take an LPVOID. If so then pass a point to that string.
Posted on 2005-02-01 15:09:27 by Eóin
what i want to do is load a string from a file (the code is above) and then pass that string to a function that takes LPCTSTR...what will need changing in my code below?
Hope that is a little bit more clear....
P.S. what do u mean a pointer, what am i passsing if it is not a pointer?
New code correctiong a few mistakes:


.const
MAXSIZE equ 260
MEMSIZE equ 65535
.data
windowF db "[window]",0
dllF db "[dll]",0
SizeRead DWORD 256
pid DWORD 0
.data?
hFile HANDLE ?
hMemory HANDLE ?
window LPCTSTR ?
dll LPCTSTR ?
.code
start:
invoke CreateFile,ADDR windowF,GENERIC_READ ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov window,eax
invoke ReadFile,hFile,window,MEMSIZE-1,ADDR SizeRead,NULL
invoke CloseHandle,hFile
;invoke GlobalUnlock,window
;invoke GlobalFree,hMemory
invoke CreateFile,ADDR dllF,GENERIC_READ ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
invoke GlobalLock,hMemory
mov dll,eax
invoke ReadFile,hFile,dll,MEMSIZE-1,ADDR SizeRead,NULL
invoke CloseHandle,hFile
;invoke GlobalUnlock,dll
;invoke GlobalFree,hMemory
lea ebx, pid
invoke MessageBox,0,window,window,MB_OK;
invoke FindWindow,addr window,0
invoke MessageBox,0,eax,eax,MB_OK
Posted on 2005-02-01 16:08:24 by ReVeR
This code is using GlobalAlloc. I can understand it if i get into it but f0dder don't believe in using this api. I'm hoping he will post an example of this code using HeapAlloc or what he consider as best api for doing what is after here. This is his stuff. Don't overlook it. Also read the thread below if you have not already.

"GlobalFree strange behaviour".

http://f0dder.schwump.net/memalloc.htm
Posted on 2005-02-02 05:08:55 by cmax
i will change that code, but that is not the error, i can get the correct window value passed to find window, but i get nothing in return....
any ideas y?
Posted on 2005-02-02 18:00:45 by ReVeR
I believe FindWindow returns a window handle, and not a string pointer.
Posted on 2005-02-02 18:12:21 by tenkey
For the first messagebox call use ADDRs before the windows.
Posted on 2005-02-02 18:31:56 by Eóin