The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: timertik on March 20, 2007, 07:52:25 AM

Title: Clearing buffers (Masm32)
Post by: timertik on March 20, 2007, 07:52:25 AM
Today I was working on an application and added it to the tray on minimize
and I noticed when I run a function that requires me to clear the buffer
it will xor eax and when minimized to the tray it has no icon  :(
I tried all I could to no avail  here is the line of code I run to clear a buffer
     push eax
push ecx
push edi
xor eax, eax
mov ecx, 512/4
mov edi, offset buffer
rep stosd
pop edi
pop ecx
pop eax

Is there any way to clear the buffer without messing with the registers maybe an api can do it??
how do you guys do this?
I cannot release this the way it is if the icon disapeers after pressing a button  :snooty:
I hope you guys can help from what I have read there are some masm gurus here
Title: Re: Clearing buffers (Masm32)
Post by: hutch-- on March 20, 2007, 07:57:51 AM
Hi timertik,

welcome on board. You can reduce the code to using 1 register but I don't think there is an easy way to do it with none.
Title: Re: Clearing buffers (Masm32)
Post by: timertik on March 20, 2007, 09:26:04 AM
then maybe I can make the icon load into another register? I couldnt  figure out how to modify this because I used an api for it
and If I modify the string of code that clears the buffers it doesnt work maybe im doing something wrong I need to avoid using eax when
clearing buffers I tried replacing eax with ebx and it didnt work.
this single line of code seems to be the culprit I took off piece by piece and tested the icon status and if I add this code Icon is gone take it off Icon is back  :eek
The Culprit:
mov ecx, 512/4
So i modified the code:
push esi
push ebx
push edi
xor esi, esi
mov ebx, 512/4
mov edi, offset buffer
rep stosd
pop edi
pop ecx
pop esi


and now the icon works but the buffer doesnt get cleared  :dazzled:
Title: Re: Clearing buffers (Masm32)
Post by: MichaelW on March 20, 2007, 11:10:45 AM
You could try preserving EAX around the code that clears the buffer, just a you are preserving EBX, ESI, and EDI.

Title: Re: Clearing buffers (Masm32)
Post by: u on March 20, 2007, 11:13:38 AM
Your first code-snippet should work - the problem must be that your buffer is not 512 bytes, but less. Or maybe somewhere you've used the instruction "std". Try putting a "cld" before the "rep stosd"
Title: Re: Clearing buffers (Masm32)
Post by: PBrennick on March 20, 2007, 01:33:13 PM
timertik,

invoke  RtlZeroMemory, addr buffer, sizeof buffer

Paul
Title: Re: Clearing buffers (Masm32)
Post by: Mark_Larson on March 20, 2007, 05:40:35 PM

  you can also call memset from the CRT functions.  It will let you pick what character to write so you just say a 0.

Title: Re: Clearing buffers (Masm32)
Post by: timertik on March 20, 2007, 08:41:16 PM
Thanks for all your input I Learned some new stuff and found two working methods but I landed on PBrennick's method.
@PBrennick
This method is what I was looking for in the beggining and thought I would never find it works perfect and my Icon shows up also it solved another error that was produced from such lengthy code I was using before
Title: Re: Clearing buffers (Masm32)
Post by: PBrennick on March 20, 2007, 10:16:49 PM
 :U