News:

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

SHBrowseForFolder-freeing the returned item

Started by TNick, September 23, 2006, 09:14:21 AM

Previous topic - Next topic

TNick

Quick question: How do you free the returned identifier list after this function return?

PS: I didn't studied the com objects and this will be the first thing to do after I finish with the Blind Crypt project. But right now I need this to finalise it.
I found a post here from donkey, but I didn't achive the goal. A snippet will vbe HIGHLY appreciated.
Thanks in advance!!

sinsi

You need to pass the PIDL to IMalloc::Free, get the IMalloc interface from SHGetMalloc.
If you can figure this out, let all of us know eh?
Light travels faster than sound, that's why some people seem bright until you hear them.

TNick

In ..\masm32\m32lib I've found this file <free.asm>
Quote
; #########################################################################

    ; -------------------------------------------------------
    ; This procedure was written by Ernie Murphy    10/1/00
    ; -------------------------------------------------------

      .386
      .model flat, stdcall  ; 32 bit memory model
      option casemap :none  ; case sensitive
      PUBLIC Alloc_pIMalloc

      include     \masm32\include\ole32.inc
     
      includelib  \masm32\lib\ole32.lib

    .data

    externdef Alloc_pIMalloc:DWORD

    .code

; #########################################################################

Free proc public pv:DWORD
   
    ; -------------------------------------------------------------
    ; Free frees a block of memory previously allocated through a call to Alloc.
    ; The number of bytes freed equals the number of bytes that were allocated.
    ; After the call, the memory block pointed to by pv is invalid and can no
    ; longer be used.
    ;
    ; Note The pv parameter can be NULL. If so, this method has no effect.
    ;
    ;
    ; EXAMPLE:
    ; invoke Free, pMem         ; frees the memory pointer to by pMem
    ;
    ; Uses: eax, ecx, edx.
    ;
    ; -------------------------------------------------------------
   
    ; free the memory
    push pv
    push Alloc_pIMalloc
    mov ecx, Alloc_pIMalloc
    mov ecx, [ecx]
    ; call IMalloc::Free
    call DWORD PTR [ecx] + 20   ; and you thought COM was hard, huh?   ;-)
    xor eax, eax                ; OK, this is a (void) function, but let's be consistant
    ret

Free endp
; #########################################################################

end


So i use it like this
    ;my pointer is pToFree
    INVOKE   SHBrowseForFolder, ADDR SHB
    mov        pToFree,    eax
    .
    .
    .
    INVOKE   CoGetMalloc,1,ADDR SomeVar            ;I just saw somewhere (msdn?) that it's better to use this instead SHGetMalloc

    push  pToFree
    push SomeVar
    mov ecx, SomeVar
    mov ecx, [ecx]
    call DWORD PTR [ecx] + 20 




... eh?     :bg

sinsi

We live and learn - my copy of the SDK says:
Quote
SHGetMalloc Function

--------------------------------------------------------------------------------

Not currently supported.

Remarks

This function should no longer be used. Use the CoTaskMemFree and CoTaskMemAlloc functions in its place.



*sigh* don't you love standards...
Light travels faster than sound, that's why some people seem bright until you hear them.

TNick

I'm oficially lost :dazzled:.So, should we use  CoTaskMemFree  or what i've said in my early post? Or are equally good?  :snooty:
PS: I've tested the post and there were no errors.But was the memory freed? Don't kow...

sinsi

I would use CoTaskMemFree, simply because you don't need to get an interface etc. (COM is easy isn't it? :bdg)
It is supported by NT 3.1/95
Light travels faster than sound, that's why some people seem bright until you hear them.