News:

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

RichEdit streaming

Started by AsmER, April 08, 2006, 03:27:24 PM

Previous topic - Next topic

AsmER

Hi everybody,

I've small problem with my procedure, which reading files to richedit control. I used streaming callback function, because I heard that this method is faster. Infortunately I can't see it. Can somebody check my code and tell me what goes wrong?

StreamProcIn proc dwCookie, lpBuffer, lSize, lpRead
; cmp lSize, 0h                ;I commented it because I'm not sure if it is realy important.
; jnz @F
; mov eax, 1h
; jmp @End
; @@:
; mov eax, lpRead
; mov dword ptr[eax], 0h
invoke ReadFile, dwCookie, lpBuffer, lSize, lpRead, 0h
xor eax, 1h
;@End:
ret
StreamProcIn endp

OpenFileEx proc hEdit, pFileName
LOCAL hFile:DWORD
LOCAL EdtS:EDITSTREAM
invoke CreateFile, pFileName, GENERIC_READ, 0h, 0h, OPEN_EXISTING, 0h, 0h
mov hFile, eax

cmp eax, INVALID_HANDLE_VALUE
jnz @F
mov eax, 0
jmp @End
@@:
push hFile
pop EdtS.dwCookie
mov EdtS.dwError, 0h
mov EdtS.pfnCallback, offset StreamProcIn
invoke SendMessage, REWin, EM_STREAMIN, SF_TEXT, addr EdtS
invoke CloseHandle, hFile
@End:
ret
OpenFileEx endp

I don't know what method of reading using Notepad, but it reading files faster than my program.
(My friend's c++ program using this procedure to read files and on my machine, his program can read ~5MB of text in 12seconds. My program have problem to read 2.4MB in ~4 minutes ???!)

PS
My program using RICHED32.DLL

farrier

AsmER,

The following code works very quickly in a few of my programs.  The only big difference is my files are in RTF format.  And I use the EM_LIMITTEXT message.


invoke CreateFile, RTFHandle, \
GENERIC_READ, FILE_SHARE_READ, NULL,\
OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL
mov hFile, eax
mov editstream.dwCookie, eax
mov editstream.pfnCallback, offset StreamInProc
invoke GetFileSize, hFile, NULL
shl eax, 1
mov FSize, eax
invoke SendMessage, hWndEdit, EM_LIMITTEXT, FSize, 0
invoke SendMessage, hWndEdit, EM_STREAMIN, SF_RTF, addr editstream
invoke SendMessage, hWndEdit, EM_SETMODIFY, FALSE, 0
invoke CloseHandle, hFile

StreamInProc PROC uses edi HFile:DWORD,pBuffer:DWORD, NumBytes:DWORD, pBytesRead:DWORD
invoke ReadFile,HFile,pBuffer,NumBytes,pBytesRead,0
xor eax,1
ret
StreamInProc ENDP



hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

AsmER

My program sending EM_EXLIMITTEXT, 0h, 0A00000h to rich edit control (It is enought, I think :toothy), but my program still work like it worked before (file 369kb is opening in 61 seconds, when Notepad opening same file in 2seconds - my program looks funny :( )

;exe file in attachement

[attachment deleted by admin]