i need to accsess a file on disk and put its entire contents in a string.
how can i do this?
Posted on 2002-03-17 20:53:29 by Qages
CreateFile to open the file, GetFileSize to get file size, ReadFile to
read file contents, CloseHandle to close file.

If you read into a static buffer, make sure that you don't overflow
the buffer, if you want it dynamic, use HeapAlloc or VirtualAlloc or
one of the other memory allocation functions.
Posted on 2002-03-17 21:02:49 by f0dder
i dont know how to use those, i keep gettin errors if i try

heres my code


Include c:\asm\first\Include\main.inc
Include c:\asm\first\Include\DCDLL.inc
.Data?
crctab dd ?
hFile HANDLE ? ; File handle
hMemory HANDLE ? ;handle to the allocated memory block
pMemory DWORD ? ;pointer to the allocated memory block
SizeReadWrite DWORD ? ; number of bytes actually read or write
.Data
buf_P db "C:\asm\first\Qages\Qages.exe",0

.Const
IDM_OPEN Equ 1
IDM_SAVE Equ 2
IDM_EXIT Equ 3
MAXSIZE Equ 260
MEMSIZE Equ 65535
.Code
LIBMAIN Proc px:DWORD, py:DWORD, pz:DWORD
return TRUE
ret
LIBMAIN EndP
;*-------------------------------------------*
; void InitCRC(void);
; Precomputes a 256*4 CRC array for use with
; Crc32()
;*-------------------------------------------*

InitCrc32Tbl Proc Uses esi edi ebx

lea edi,crctab + (255*4)
xor edx,edx
dec dl
std
CalcTblValues:
mov eax,edx
mov ebx,0edb88320h ; winzip polynominal
push 8 ;mov ecx,8
pop ecx
ReflectBitsCompute_Loop:
shr eax,1
sbb esi,esi
and esi,ebx
xor eax,esi
dec ecx
jz ReflectBitsCompute_Loop
stosd
dec edx
jns CalcTblValues
cld
ret
InitCrc32Tbl EndP
;*-------------------------------------------*
; int FastCRC(*buffer, sizeof(buffer);
; Calculates a 32 Bit Cyclic Redundancy Code
; over a buffer with length sizeof(buffer),
; using a precomputed CRC table. InitCRC()
; must be called *once* before.
; Speed: ~7 MB/s on a Intel PII 300
;*-------------------------------------------*
Crc32 Proc Uses esi edi lpData:DWORD,bLen:DWORD

mov esi,lpData
lea edi,crctab
mov ecx,bLen

xor eax,eax
dec eax
xor edx,edx
@@:
mov dl,byte ptr [esi]
inc esi
xor dl,al

shr eax,8
xor eax,dword ptr [edi+(edx*4)]

dec ecx
jnz @B

not eax
ret
Crc32 EndP

CHECKDCFAKER Proc pDAT:DWORD
Local pCRCD :DWORD
Invoke CreateFile,Addr buf_P,GENERIC_READ or GENERIC_WRITE ,FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile,eax
Invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
Invoke GlobalLock,hMemory
mov pMemory,eax
Invoke ReadFile,hFile,pMemory,MEMSIZE-1,Addr SizeReadWrite,NULL

Invoke InitCrc32Tbl ;int crc
Invoke Crc32,Addr pMemory,Addr SizeReadWrite ;call it
mov DWORD PTR [pDAT] ,eax
Invoke CloseHandle,hFile
Invoke GlobalUnlock,pMemory
Invoke GlobalFree,hMemory

ret
CHECKDCFAKER EndP
End LIBMAIN




Posted on 2002-03-17 22:01:19 by Qages
Well, looks like you been coded on high level language. There you can write your proc in the start of your code and then write main function (winmain for example) from where you call your proc, in asm it is dont work.

Your code start with return TRUE and ret - theese instruction will execute first.

And you need to write on the begining something like:


.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib
Posted on 2002-03-18 01:23:05 by masquer
i do have all the include stuff its in
Include c:\asm\first\Include\main.inc

the main stuff .386.modle etc is all in there because that what i regularly use
this is for a dll, CHECKDCFAKER is being called from any other app

the code i use has error some where but i dont know where.
Posted on 2002-03-18 16:39:08 by Qages