News:

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

WriteFile

Started by 5k3l3t0r, February 03, 2007, 08:22:43 PM

Previous topic - Next topic

5k3l3t0r

hi all,
i have a prob...
i need to write a text line to an existing .txt
i try WriteFile but nothing...
i think my prob is geting the handle of the .txt file
can someone help me?
by all
5k3l3t0r

gabor

Hi!

The Win32Api and other documents contain excellent explanations and guides to manage files. The API calls you need here are OpenFile, WriteFile, CloseHandle.
When you successfully open the file the handle is returned. Good luck!  :U

Greets, Gábor

ic2

This is what i use for fun.  You control the speed with sleep if you want to watch the text print... Other than this  use OPEN_EXISTING or OPEN_ALWAYS with CreateFile than use SetFilePointer for where you want to begin writng, than WriteFile, CloseHandle....


386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; ###############################

      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

; ################################


    .data
        Notepad         db "c:\windows\notepad.exe",0
        NotePad_Class db "Notepad",0
        EditClassName db "edit",0

        text_to_write         db "AAAAAAAAAAABBBBBBBBBB1234567890CCCCCCCCCC",0

    .data?

handle      dd ?
temp        dd ?
    .code

start:

invoke WinExec, offset Notepad,SW_SHOW
call c_findhandle
mov edx,offset text_to_write

restart:
xor eax,eax
mov al,byte ptr [edx]
or al,al
jz finish

push edx
invoke SendMessage,handle,WM_CHAR,eax,0
;;;    invoke Sleep,0
pop edx
inc edx
jmp restart
finish:


invoke ExitProcess, 0
; ........................................................

c_findhandle PROC

invoke  FindWindow, offset NotePad_Class,0
mov temp,eax


invoke SetWindowPos, temp, HWND_TOPMOST,NULL,NULL,NULL,NULL,SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE

invoke SetForegroundWindow,eax
invoke FindWindowEx,temp,0,addr EditClassName,0
mov handle,eax

RET

c_findhandle ENDP





end start


Tedd

CreateFile ...GENERIC_WRITE.....OPEN_EXISTING.......
SetFilePointer .......FILE_END
WriteFile .......
CloseHandle ...

No snowflake in an avalanche feels responsible.