Hello!
The problem is that i am using EnumWindows to get the list of all currently active windows
But i also want to write it to a log file cureated in the same directory.

EnumWindows works out successfully, even the log file is created but i cant seem to write into the file :(

the size of the log file remains 0Kb only i dont know why :(

I use createfile to make the file and writefile to write to it.

The window name is stored in : szTemp db 200 dup(0) and the window name

is retrived using getwindowtext. Can anyone help me please :confused:

If possible Please post the writefile code coz i can already enumwindow's successfully :grin:

Thankyou for reading:)
Posted on 2004-05-26 14:23:58 by telophase



NumberOfBytesWritten dd ?
FileName db "C:\test" 0
szTemp db 128 dup (?)

invoke WriteMemIntoFile, OFFSET FileName, OFFSET szTemp, 128

WriteMemIntoFile proc szFileName:DWORD, MemoryADDR:DWORD, Size2Write:DWORD

invoke CreateFile, szFileName, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
push eax ; for CloseHandle
invoke WriteFile, eax, MemoryADDR, Size2Write, OFFSET NumberOfBytesWritten, 0

call CloseHandle
ret
endp


Should work. Of course if you want to append to a file, you need to set the file pointer to the end using SetFilePointer
Posted on 2004-05-26 14:45:20 by JimmyClif
telophase,
see "Tiny window informers":

http://www.asmcommunity.net/board/showthread.php?threadid=18195&highlight=kero

Source of WinTreeSnap contains code you need
(EnumWindows + output list via Create/WriteFile).
Posted on 2004-05-26 18:28:01 by kero
Thanks for the link kero :alright:

Jimmy,

I could get your code but the problem is that in the text file to which i am appending each

window name should be on a new line so that the user can read comforatbily.

Isn't there any function like "WriteLine" which we have in Visual Basic or atleast we could emulate it

in assembly? could that be done ? :confused:

:stupid:
Posted on 2004-05-26 22:28:18 by telophase
Yes, just add crlf with WriteFile.
Posted on 2004-05-27 00:17:40 by roticv
I know CrLF db 0ah,0dh but how to add to write file ?? :confused:
Posted on 2004-05-27 00:24:29 by telophase


.data
hLogFile dd 0
DidWriteLog dd 0
.data?
LogBuf db 256 dup (?)
.code
CreateLog macro pName:REQ
mov hLogFile,$invoke (CreateFile,pName,GENERIC_READ or GENERIC_WRITE,0, 0, CREATE_ALWAYS,0,0)
endm

WriteLog proc pText:DWORD
invoke lstrlen,pText
@@: push eax
invoke WriteFile,hLogFile,pText,eax, addr DidWriteLog,0
pop eax
sub eax,DidWriteLog
.if eax>0
jmp @B
.endif
ret
WriteLog endp

Log macro pText:REQ
push esi
push edi
pushad
invoke WriteLog, pText
popad
pop edi
pop esi
endm


LogDWORD macro pText:REQ,Val:REQ
push esi
push edi
pushad
invoke wsprintf,addr LogBuf,pText,Val
invoke WriteLog,addr LogBuf
popad
pop edi
pop esi
endm

CloseLog macro
invoke CloseHandle,hLogFile
endm

CTEXT macro Text:VARARG
local szText
.data
szText byte Text, 0
.code
exitm <offset szText>
endm



OK now - instructions to use this stuff.
Add a line early in your program
CreateLog CTEXT ("MYLOGFILE.TXT")

and somewhere at the end of the program
CloseLog


Now anywhere in your program, add plaintext lines to the logfile with the command:
Log CTEXT("This line will be logged",13,10)

Note that the CRLF (13,10) is optional, sometimes its desirable write a few things to the log on a single line.
The final Logging macro I've supplied u with is to be used as if you were using wsprintf:
LogDWORD CTEXT("The Value is %lu",13,10), MyValue

or possibly
LogDWORD CTEXT( "Today is %s"),addr szDay

LogDWORD is a generic wsprintf-driven Log macro, don't misinterpret it because of its name, it'll do anything wsprintf will, and output it to your file, with the one drawback that the version supplied is limited to a single argument.

Feel free to modify as required, personally what I do is something like this:
if __DEBUG__
Log CTEXT("Logging Enabled,",13,10)
endif

then add a switch at the start of the program
__DEBUG__ equ 0 (or 1)
allows me to build my application with or without any logging code, so I can make a debugging version or a final version using the same source, and without having to remove all my debug lines later, or have any of that code appear in my final product.


Have fun :)
Posted on 2004-05-27 01:11:10 by Homer
Thanks for the code :grin:
Posted on 2004-05-27 01:33:24 by telophase