Im writing this editor for my brainfck interperter that I finished, And I noticed there is some bugs in the editor when saving. And I am having some trouble tracking it down... Ive checked the stream in and stream out procs aswell as the save bits to make sure they are being changed right, and then only on some files does it mess up and not save but then on some it does... Ive included the source if anyone would like to help..
[attachment deleted by admin]
Would like to but your project seems to rely on environment variables:
*** Assemble, link and run BrainFckw ***
Res/SettingsDlg.rc(2) : warning RC4005: 'IDC_STC1' : redefinition
Res/mainMnu.rc(7) : warning RC4005: 'IDM_LINE' : redefinition
Res/mainMnu.rc(12) : warning RC4005: 'IDM_LINE' : redefinition
Res/mainMnu.rc(17) : warning RC4005: 'IDM_LINE' : redefinition
Res/mainMnu.rc(24) : warning RC4005: 'IDM_RUN' : redefinition
Res/mainMnu.rc(25) : warning RC4005: 'IDM_LINE' : redefinition
Res/mainMnu.rc(29) : warning RC4005: 'IDM_LINE' : redefinition
Res/FindTextDlg.rc (21): warning RC2182 : duplicate dialog control ID 4006
*** Assemble using \Masm32\bin\ml /nologo /c /coff /Fl /Sn /Fo "BrainFckw" ***
Assembling: tmp_file.asm
BrainFckw.inc(2) : fatal error A1000:cannot open file : windows.inc
Interesting, I haven't set any... it assembles fine for me :\
Quote from: travism on July 09, 2009, 06:01:29 PM
Interesting, I haven't set any... it assembles fine for me :\
BrainFckw.Inc:
include windows.inc
...
include C:\masm32\macros\macros.asm
My Masm32 installation is on D:
Use this, and it will assemble for everybody:
include \masm32\include\windows.inc
...
include \masm32\macros\macros.asm
Hey thanks I will change that!
Hi travism,
Will you please post an example of a file which will not save?
I have tested the editor and have tried several combinations of content and have no saving issues.
Seems there is a problem with writefile
Quote
StreamOutProc proc readFile:DWORD,rBuffer:DWORD, nBytes:DWORD, nBytesWritten:DWORD
invoke WriteFile,readFile,rBuffer,nBytes,nBytesWritten,0
xor eax,1
ret
StreamOutProc endp
nBytesWritten must be the address of a dword where the function put the result of is writing
Quote
lpNumberOfBytesWritten
[out] Pointer to the variable that receives the number of bytes written. WriteFile sets this value to zero before doing any work or error checking.
If lpOverlapped is NULL, lpNumberOfBytesWritten cannot be NULL. If lpOverlapped is not NULL, lpNumberOfBytesWritten can be NULL. If this is an overlapped write operation, you can get the number of bytes written by calling GetOverlappedResult. If hFile is associated with an I/O completion port, you can get the number of bytes written by calling GetQueuedCompletionStatus.
If I/O completion ports are used and you are using a callback routine to free the memory allocated to the OVERLAPPED structure pointed to by the lpOverlapped parameter, specify NULL as the value of this parameter to avoid a memory corruption problem during the deallocation. This memory corruption problem will cause an invalid number of bytes to be returned in this parameter
Quote from: ToutEnMasm on July 10, 2009, 07:59:27 AM
Seems there is a problem with writefile
..
nBytesWritten must be the address of a dword where the function put the result of is writing
nBytesWritten is supplied by the OS. Travism's code looks correct to me. I use the same in RichMasm.
provided or not by the system,must be passed as an address.
But the callback pass it as an adress,so it's good.
To be more clear,here is a sample showing how to write data from the richedit.
Quote
;################################################################
o_save PROC pfile:DWORD
Local retour:DWORD
LOCAL EditS:EDITSTREAM
LOCAL hFile:DWORD
LOCAL HandleEdit:DWORD
mov retour,0
;create an empty file
INVOKE CreateFile,pfile,GENERIC_READ or GENERIC_WRITE ,FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL, CREATE_ALWAYS , FILE_ATTRIBUTE_NORMAL, NULL
.if eax == INVALID_HANDLE_VALUE
mov edx,eax
invoke MessageBox,NULL,edx,SADR("CreateFile failed"),MB_OK
jmp Findeo_save
.endif
mov hFile, eax
mov EditS.dwCookie, eax ;
mov EditS.dwError, 0
mov EditS.pfnCallback, offset EditStreamWrite ;l
mov TotaliseEcriture,0
INVOKE SendMessage,Hredit, EM_STREAMOUT,SF_TEXT,addr EditS
INVOKE CloseHandle, hFile
.if TotaliseEcriture == 0
invoke MessageBox,NULL,SADR("Failed Writing in an open file ? "),
SADR("Nothing write by EditStreamWrite"),MB_OK
mov retour,0
.else
PuPo retour,TotaliseEcriture
.endif
Findeo_save:
mov eax,retour
ret
o_save endp
;################################################################
EditStreamWrite PROC PRIVATE dwCookie:DWORD, pbBuff, cb, pcb
;enregistrement par petit paquet
INVOKE WriteFile, dwCookie, pbBuff, cb, pcb, 0
mov edx,[pcb]
add TotaliseEcriture,edx
mov eax,0
ret
EditStreamWrite ENDP