The MASM Forum

General => The Campus => Topic started by: Fraile on April 19, 2014, 02:47:40 AM

Title: How free memory, CreateStreamOnHGlobal
Post by: Fraile on April 19, 2014, 02:47:40 AM
Hi,

I'm using the function "CreateStreamOnHGlobal":

"Invoke CreateStreamOnHGlobal, 0, TRUE, Offset GDIStream"

But not how to call  Release to free memory.

Anyone know how to release memory of the "CreateStreamOnHGlobal"?

Thank you very much.
Title: Re: How free memory, CreateStreamOnHGlobal
Post by: Vortex on April 19, 2014, 04:00:03 AM
WINOLEAPI CreateStreamOnHGlobal(
  _In_   HGLOBAL hGlobal,
  _In_   BOOL fDeleteOnRelease,
  _Out_  LPSTREAM *ppstm
);


QuoteDo not free the hGlobal memory handle during the lifetime of the stream object. IStream::Release must be called before freeing the memory handle.

QuoteIf the caller sets the fDeleteOnRelease parameter to FALSE, then the caller must also free the hGlobal after the final release. If the caller sets the fDeleteOnRelease parameter to TRUE, the final release will automatically free the hGlobal.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa378980%28v=vs.85%29.aspx
Title: Re: How free memory, CreateStreamOnHGlobal
Post by: Fraile on April 19, 2014, 05:03:19 AM
Hi Vortex,

I use to loop for capture images, but "Invoke CreateStreamOnHGlobal, 0, TRUE, Offset GDIStream" not release memory. I know the parameters of the function are to release automatically. But not release memory.
Title: Re: How free memory, CreateStreamOnHGlobal
Post by: dedndave on April 19, 2014, 10:43:43 AM
in the CreateStreamOnHGlobal documentation,
QuoteConsider using the SHCreateMemStream function, which produces better performance...

if you still choose to use CreateStreamOnHGlobal, you pass an HGLOBAL
that is a memory handle that has been created using GlobalAlloc
so, to free that memory when done, you would use GlobalFree

to free the memory used by the function, you would use IUnknown::Release
i imagine it would be desirable to Release before GlobalFree
Title: Re: How free memory, CreateStreamOnHGlobal
Post by: Fraile on April 19, 2014, 11:35:33 AM
Thank you,

How can I call "IUnknown :: Release". Might you  give an example please?

Thank you very much.
Title: Re: How free memory, CreateStreamOnHGlobal
Post by: Siekmanski on April 19, 2014, 03:05:06 PM
try this,

mov   ecx,GDIStream
push   ecx
mov   eax,[ecx]
call   DWORD PTR [eax + 8] ; IUnknown::Release
Title: Re: How free memory, CreateStreamOnHGlobal
Post by: Vortex on April 19, 2014, 06:29:55 PM
Hi AsmAlmeria12,

Here is an example for you. You can check the attached project.

ReleaseIStream  PROC

    push    eax
    mov     eax,DWORD PTR [eax]
    call    IStream.IUnknown.Release[eax]                               ; release the stream
    ret

ReleaseIStream ENDP
Title: Re: How free memory, CreateStreamOnHGlobal
Post by: Fraile on April 21, 2014, 03:55:13 AM
Thank you very much