Hi, there

by some reason i need to find all the files in subdirectories and then index them. But so far i programmed the part of finding all files in subdirectories. here below it is. BUT i never read somewhere that you have to preserve the esi register in your winprocedure. I don't now why but somehow user32 is putting the dword value 00000001 in where ever esi points at, look below if you don't push and pop the esi you CRASH, this was an afternoon of searching the bug i can't get it, if someone can explain i like to know but here it is you can use this algo and make it better, BTW i need expertise on sorting lists of strings please reply if you know it well:

.386

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

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\ole32.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib

.const
IDM_OPEN equ 1
IDM_EXIT equ 2

.data
ClassName db "SimpleWinClass",0
AppName db "Our Main Window",0
MenuName db "FirstMenu",0
OurTitle db "kies data:",0
wCard db "*.*",0
buffer2 db "files.txt",0
text db " files found.",0

.data?
WorkDir byte MAX_PATH dup(?)
buffer byte MAX_PATH dup(?)
bufferhtm byte MAX_PATH dup(?)
OutputDir byte MAX_PATH dup(?)
text1 byte 10 dup(?)
text2 byte 20 dup(?)
hInstance HINSTANCE ?
CommandLine LPSTR ?
filegrootte DWORD ?
BInfo BROWSEINFO <>
wfd WIN32_FIND_DATA <>
hSearch DWORD ?
pMem DWORD ?
pMemory DWORD ?
pMemoryhtm DWORD ?
mijnMem DWORD ?
hMem HANDLE ?
hFileWrite HANDLE ?
hFileRead HANDLE ?
hFileReadhtm HANDLE ?
hMapFile HANDLE ?
hMapFilehtm HANDLE ?
SizeWritten DWORD ?
diep DWORD ?
einde DWORD ?
aantalfiles DWORD ?
.code
start:

invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,300,200,NULL,NULL,\
hInst,NULL
mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.if ax==IDM_OPEN
push esi ; <------this is what i mean
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,10485759
mov hMem,eax
invoke GlobalLock,hMem
mov pMem,eax
mov mijnMem,eax







mov eax,hWnd
mov BInfo.hwndOwner,eax
mov BInfo.pidlRoot,0
mov BInfo.lpszTitle,OFFSET OurTitle
mov BInfo.ulFlags,BIF_RETURNONLYFSDIRS
mov BInfo.lpfn,0
mov BInfo.lParam,0
mov BInfo.iImage,0
invoke SHBrowseForFolder,ADDR BInfo
.if eax != 0
push eax
invoke SHGetPathFromIDList,eax,ADDR WorkDir
call CoTaskMemFree
.endif
lea esi,WorkDir
lea edi,OutputDir
@@: lodsb
stosb
cmp al, 0
jne @B

mov [aantalfiles],0
mov [diep],1
opnieuw: invoke SetCurrentDirectory,ADDR WorkDir
invoke FindFirstFile,ADDR wCard,ADDR wfd
mov hSearch,eax
push eax
invoke FindNextFile,hSearch,ADDR wfd
volgende: invoke FindNextFile,hSearch,ADDR wfd
.IF eax!=0
mov eax,[wfd.dwFileAttributes]
and eax,FILE_ATTRIBUTE_DIRECTORY
.if eax==FILE_ATTRIBUTE_DIRECTORY
inc [diep]
cld
lea edi,WorkDir
mov ecx,-1
mov al,0
repnz scasb
not ecx
dec ecx
lea edi, WorkDir
add edi,ecx
mov byte ptr [edi],'\'
inc edi
lea esi, wfd.cFileName
@@: lodsb
stosb
cmp al, 0
jne @B
mov [einde],edi
jmp opnieuw
.else
mov edi,mijnMem
lea esi,WorkDir
@@: lodsb
stosb
cmp al,0
jne @B
dec edi
mov byte ptr [edi],'\'
inc edi
lea esi,wfd.cFileName
@@: lodsb
stosb
cmp al,0
jne @B
dec edi
mov byte ptr [edi],13
inc edi
mov byte ptr [edi],10
inc edi
mov mijnMem,edi
inc [aantalfiles]
jmp volgende
.endif
.else
dec [diep]
pop hSearch
invoke FindClose,hSearch
.IF [diep]==0
jmp klaar
.ELSE
pop hSearch
push hSearch
std
mov al,'\'
mov edi,[einde]
repnz scasb
inc edi
mov byte ptr [edi],0
cld
jmp volgende
.ENDIF
.endif
klaar: mov eax,mijnMem
sub eax,pMem
mov filegrootte,eax
invoke InvalidateRect, hWnd,NULL,TRUE

invoke SetCurrentDirectory,ADDR OutputDir
invoke CreateFile,ADDR buffer2,GENERIC_WRITE ,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFileWrite,eax

invoke WriteFile,hFileWrite,pMem,filegrootte,ADDR SizeWritten,NULL

invoke CloseHandle,hFileWrite
; #######################indexeren####################################################
lea esi,OutputDir
lea edi,buffer
@@: lodsb
stosb
cmp al,0
jne @B
dec edi
mov byte ptr [edi],'\'
inc edi
lea esi,buffer2
@@: lodsb
stosb
cmp al,0
jne @B

invoke CreateFile,ADDR buffer,GENERIC_READ ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFileRead,eax
invoke CreateFileMapping,hFileRead,NULL,PAGE_READONLY,0,0,NULL
mov hMapFile,eax
invoke MapViewOfFile,hMapFile,FILE_MAP_READ,0,0,0
mov pMemory,eax

mov esi,pMemory
lea edi,bufferhtm
@@: lodsb
stosb
cmp al,10
jne @B
dec edi
dec edi
mov byte ptr [edi],0
invoke CreateFile,ADDR bufferhtm,GENERIC_READ ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFileReadhtm,eax
invoke CreateFileMapping,hFileReadhtm,NULL,PAGE_READONLY,0,0,NULL
mov hMapFilehtm,eax
invoke MapViewOfFile,hMapFilehtm,FILE_MAP_READ,0,0,0
mov pMemoryhtm,eax

mov eax,pMem
mov mijnMem,eax

mov esi,pMemoryhtm
mov edi,mijnMem

luss: lodsb
.if al=='<'
@@: lodsb
cmp al,'>'
jne @B
jmp luss
.elseif al==13
inc esi
jmp luss
.endif
invoke UnmapViewOfFile,pMemoryhtm
invoke CloseHandle,hMapFilehtm
mov hMapFilehtm,0
invoke CloseHandle,hFileReadhtm

invoke UnmapViewOfFile,pMemory
invoke CloseHandle,hMapFile
mov hMapFile,0
invoke CloseHandle,hFileRead

invoke GlobalUnlock,pMem
invoke GlobalFree,hMem
pop esi ; <------this is what i mean

.else
invoke DestroyWindow, hWnd
.endif
.ELSEIF uMsg==WM_PAINT

invoke BeginPaint,hWnd, ADDR ps
mov hdc,eax


invoke dwtoa,aantalfiles,addr text1
lea edi,text2
lea esi,text1
@@: lodsb
stosb
cmp al,0
jne @B
dec edi
lea esi,text
@@: lodsb
stosb
cmp al,0
jne @B
dec edi
lea eax,text2
sub edi,eax
invoke TextOut,hdc,0,0,ADDR text2,edi

invoke EndPaint,hWnd, ADDR ps

.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp

end start



// Constants for menu rsrc.rc
#define IDM_OPEN 1
#define IDM_EXIT 2

FirstMenu MENU
{
POPUP "&File"
{
MENUITEM "&Open",IDM_OPEN
MENUITEM SEPARATOR
MENUITEM "E&xit",IDM_EXIT
}
}



I think it's a bug in module user....

See ya:)

Posted on 2002-05-24 09:50:27 by eisodur
Yes, you do need to preserve ESI (and EDI and EBX) in a window procedure. If you search for "calling conventions" or "register conventions", you'll find a number of articles, some of which will explain the register saving convention.
Posted on 2002-05-25 03:03:32 by tenkey
There is a piece of folklore with the previous suggestion that it only applies to WndProc style procedures where in fact the Windows convention is that you must preserve EBX ESI and EDI in ANY procedure that uses them.

If a WndProc does NOT use these 3 registers, it does NOT need to preserve them. The only place where you can bypass this convention is if you make a call from within a proc that has already preserved EBX ESI and EDI and the call that can be made under these conditions cannot interact with any OS functions while executing code.

Regards,

hutch@movsd.com
Posted on 2002-05-25 05:21:06 by hutch--
I had the same prob some time ago and i found a very simple method u could use (but i still think u should use a WIN32_FIND).

szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM

ListBox proc a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,hParent:DWORD,ID:DWORD

szText lstBox,"LISTBOX"

invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR lstBox,0,
WS_VSCROLL or WS_VISIBLE or \
WS_BORDER or WS_CHILD or \
LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or \
LBS_DISABLENOSCROLL,
a,b,wd,ht,hParent,ID,hInstance,NULL

ret

ListBox endp

...................

invoke ListBox,20,40,420,200,hWin,500
mov hList1, eax
szText Patn,"c:\*.*"
invoke SendMessage,hList1,LB_DIR,DDL_ARCHIVE or DDL_DRIVES or \
DDL_DIRECTORY or DDL_HIDDEN or DDL_READONLY or \
DDL_READWRITE or DDL_SYSTEM,ADDR Patn

Hope u realised that <Patn> is the path ( \*.* required) & <hList1> is a listbox.
Posted on 2002-05-25 09:28:33 by ViperV`
First of all thank you all for helping me out!!

The result you can download from the attached file.

The prog expects taht the data dir is containing .htm files and puts all words on the stack and then move's to the nextone.

I have to find some way to sort this stack or perhaps use a linked list, what do you suggest? But here are some problems to.

Anyway here's the code for the subdirectory search and index htm
Posted on 2002-05-27 10:28:36 by eisodur
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT

i think there is something wrong here.. you invoke GetCommandLine sure but you don't move it no where for storage and in invoke WinMain you use CommandLine... mov the data into CommandLine before you invoke something that is not there.. im not sure if thats the problem but i hope i helped..
Posted on 2002-07-17 01:26:24 by SpawNRuleR