Author Topic: Saving the content of a richedit in memory  (Read 285 times)

TouEnMasm

  • Member
  • *****
  • Posts: 1395
    • EditMasm
Saving the content of a richedit in memory
« on: September 11, 2020, 07:04:32 PM »
Hello,
Is there any of you,who have  tried to do this?.
I use similar proc used for a file,but the callback is called only once instead of repeatedly.
I have tried the heap memory,the global memory with the same result.
That is only 800h writed in memory.
Any help ?

Quote
SaveInMemHeap PROC  pblocheap:DWORD
         LOCAL      EditS:EDITSTREAM
         LOCAL    hFile:DWORD   
         LOCAL   HandleEdit:DWORD
         Local  retour:DWORD
         ZEROLOCALES retour

               
   mov retour,0
   mov eax,pblocheap
   mov     EditS.dwCookie, eax      ;le fichier ouvert
   mov     EditS.dwError, 0
   mov     EditS.pfnCallback, offset EditStreamMemWrite  ;le progrramme callback
   mov TotaliseEcriture,0
   
   INVOKE     SendMessage,Hredit, EM_STREAMOUT,SF_TEXT,addr EditS      
   
   .if TotaliseEcriture == 0
      invoke MessageBox,NULL,TXT("Failed Writing in MemHeap ? "),
                  TXT("Nothing write by EditStreamWrite"),MB_OK
      mov retour,0
   .else
      PuPo retour,TotaliseEcriture
   .endif

FindeSaveInMemHeap:
   mov eax,retour
   ret
SaveInMemHeap endp

;################################################################
EditStreamMemWrite PROC dwCookie:DWORD, pbBuff, nNumberOfBytesToWrite:DWORD, lpNumberOfBytesWritten:DWORD
;HANDLE       hFile,LPCVOID  lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten, lpOverlapped    
   ;enregistrement par petit paquet
   ;invoke WriteToBlocHeap,addr TransCode,  pbBuff, nNumberOfBytesToWrite
   invoke WriteGlobal,addr global,pbBuff, nNumberOfBytesToWrite
   .if eax != 0
      ;invoke DebugBreak
      mov eax,nNumberOfBytesToWrite
      mov [lpNumberOfBytesWritten],eax
      add TotaliseEcriture,eax
   .else
      invoke MessageBox,NULL,TXT("Failed Writing in MemHeap ? "),
                  TXT("EditStreamMemWrite"),MB_OK      
   .endif
   
   mov eax,0 ;TotaliseEcriture
   ret
EditStreamMemWrite ENDP
;-----------------------------------------------------------------------------------------------------------

Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 10644
  • Assembler is fun ;-)
    • MasmBasic
Re: Saving the content of a richedit in memory
« Reply #1 on: September 11, 2020, 08:29:41 PM »
Code: [Select]
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
StreamToXXL proc cookie, pBuffer, NumBytes, pBytesWritten
invoke RtlMoveMemory, [esp+12], [esp+12], [esp+12] ; dest, source, count
mov edx, [esp+16]
or eax, -1
mov [edx], eax ; return non-zero to pBytesWritten
retn 4*4
StreamToXXL endp
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

TouEnMasm

  • Member
  • *****
  • Posts: 1395
    • EditMasm
Re: Saving the content of a richedit in memory
« Reply #2 on: September 11, 2020, 11:27:11 PM »

After a little search,memcpy (crt) is used by RtlMoveMemory.
Result = 800H and no recall of The stream  Write
Thanks for answer
Fa is a musical note to play with CL

TouEnMasm

  • Member
  • *****
  • Posts: 1395
    • EditMasm
Re: Saving the content of a richedit in memory
« Reply #3 on: September 12, 2020, 03:09:26 AM »
More and more,
The richedit gratify me of an error message,extracts from winerror.sdk and msdn,
Quote
STG_E_MEDIUMFULL   equ   < 080030070h>
;
; MessageId: STG_E_PROPSETMISMATCHED
;
; MessageText:
;
; Illegal write of non-simple property to simple property set.
You know what,I am Happy with that.
msdnsay
Quote
Illegal write of non-simple property to simple property set.


Fa is a musical note to play with CL

HSE

  • Member
  • *****
  • Posts: 1404
  • <AMD>< 7-32>
Re: Saving the content of a richedit in memory
« Reply #4 on: September 12, 2020, 03:49:08 AM »
More and more,

Congratulations  :thumbsup:

We can see You are are having a lot of fun  :biggrin:

Because I don't enjoy too much that, I maked simple:
Code: [Select]
  invoke SysAllocStringByteLen, NULL, 25000000
  mov hRes$, eax

  invoke SendMessage, hEdit, WM_GETTEXTLENGTH, 0, 0
  inc eax
  invoke SendMessage, hEdit, WM_GETTEXT, eax, hRe$

jj2007

  • Member
  • *****
  • Posts: 10644
  • Assembler is fun ;-)
    • MasmBasic
Re: Saving the content of a richedit in memory
« Reply #5 on: September 12, 2020, 05:21:20 AM »
Because I don't enjoy too much that, I maked simple:
Code: [Select]
  invoke SysAllocStringByteLen, NULL, 25000000
  mov hRes$, eax

  invoke SendMessage, hEdit, WM_GETTEXTLENGTH, 0, 0
  inc eax
  invoke SendMessage, hEdit, WM_GETTEXT, eax, hRe$

Wouldn't it be more logical to inquire the length before allocating the buffer? Besides, there are reasons to use EM_STREAMOUT, but right now I've forgotten why I use the complicated stuff :cool:

(there are also reasons not to use EM_STREAMOUT). In RichMasm I use EM_GETTEXTEX for creating the plain text temp asm files.

HSE

  • Member
  • *****
  • Posts: 1404
  • <AMD>< 7-32>
Re: Saving the content of a richedit in memory
« Reply #6 on: September 12, 2020, 05:46:21 AM »
Wouldn't it be more logical to inquire the length before allocating the buffer?
Could be. Usually I allocate a buffer at program beginning by default, always named hRes$ that is used by several procs and macros.

Besides, there are reasons to use EM_STREAMOUT, but right now I've forgotten why I use the complicated stuff :cool:
:biggrin: :biggrin: :biggrin:


I think EM_STREAMOUT can make automatic conversion between RTF and text, or something like that  :cool:

TouEnMasm

  • Member
  • *****
  • Posts: 1395
    • EditMasm
Re: Saving the content of a richedit in memory
« Reply #7 on: September 12, 2020, 05:59:28 AM »
 :thumbsup: :thumbsup:
Many thanks for that,
I have put it in heap because I have a lot of code who use it.

Quote
           invoke SendMessage, Hredit, WM_GETTEXTLENGTH, 0, 0
           inc eax
         mov textelen,eax
         add eax,20h
         and eax,0FFFFFFF0h
         mov edx,eax
         invoke SysAllocStringByteLen, NULL,edx
           mov hRes, eax         
           invoke SendMessage, Hredit, WM_GETTEXT,textelen, hRes
         invoke WriteToBlocHeap,addr TransCode, hRes, textelen
         mov edx,hRes
         invoke SysFreeString,hRes
                    
         invoke PostMessage,hwnd,WM_COMMAND,1001,0
Fa is a musical note to play with CL

TouEnMasm

  • Member
  • *****
  • Posts: 1395
    • EditMasm
Re: Saving the content of a richedit in memory
« Reply #8 on: September 12, 2020, 06:29:57 AM »

And here the application who need this:
It's a draft of a precompiler for masm.
He use the ² as an escape code.
The texte is saved in memory and re translated in academic masm.
No more invoke,"   " and L" " allowed,Further segment in the same line,enumeration,next assume( need to be added...
Load the file testeur.txt,play a little with it and use "Fichier" >> "save memory heap",
He write sortie.txt who is in normal syntax
Fa is a musical note to play with CL