LPMALLOC, IMalloc problems.

This is a discussion on LPMALLOC, IMalloc problems. within the Windows Programming forums, part of the Platform Specific Boards category; I am using SHBrowseForFolder (function), BROWSEINFO (structure), SHGetMalloc(function), and LPMALLOC(structure) to ask the user to select a folder. But when ...

  1. #1
    Climber spoon_'s Avatar
    Join Date
    Jun 2002
    Location
    ATL
    Posts
    182

    LPMALLOC, IMalloc problems.

    I am using SHBrowseForFolder (function), BROWSEINFO (structure), SHGetMalloc(function), and LPMALLOC(structure) to ask the user to select a folder. But when I try to free the memory allocated by SHGetMalloc, I get this error:

    Code:
    error C2039: 'Free' : is not a member of 'IMalloc'
            c:\program files\microsoft sdk\include\objidl.h(1103) : see declaration of 'IMalloc'
    Here is my code:

    Code:
    	case IDC_CLICK_OPENDIR:
    		{
    			char x[MAX_PATH];
    			BROWSEINFO binfo;
    			HRESULT HR;
    			LPITEMIDLIST idList = 0;
    			LPMALLOC pMalloc;
    
    			HR = SHGetMalloc(&pMalloc);
    
    			if(FAILED(HR))
    			{
    				MessageBox(hWnd, "shgetmalloc failed.", "error", MB_OK);
    				return;
    			}
    
    			binfo.hwndOwner = hWnd;
    			binfo.pszDisplayName = x;
    			binfo.ulFlags = BIF_USENEWUI;
    			binfo.lpfn = NULL;
    			binfo.pidlRoot = 0;
    			binfo.lpszTitle = "Title Here";
    			binfo.lParam = 0;
    
    			idList = SHBrowseForFolder(&binfo);
    
    			SHGetPathFromIDList(idList, x);
    
    			SetDlgItemText(hWnd, IDC_EDIT_FILETOSAVE, x);
    
    			pMalloc->Free(idList);//ERROR here.
    			break;
    		}
    lil help please, thanks
    {RTFM, KISS}

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Your code seems fine and compiles and runs ok with me (msvc6 aug2001psdk, win2k).

    Try:

    Deleting all temporary files and doing a complete rebuild -sometimes msvc can be a bit temperamental.

    Check objidl.h line 1103 referred to in the error msg to see what the header has to say for itself - is Free defined for IMalloc?

  3. #3
    Climber spoon_'s Avatar
    Join Date
    Jun 2002
    Location
    ATL
    Posts
    182
    Here is the some of the code for IMalloc in objidl.h:

    Code:
        typedef struct IMallocVtbl
        {
            BEGIN_INTERFACE
            
            HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
                IMalloc * This,
                /* [in] */ REFIID riid,
                /* [iid_is][out] */ void **ppvObject);
            
            ULONG ( STDMETHODCALLTYPE *AddRef )( 
                IMalloc * This);
            
            ULONG ( STDMETHODCALLTYPE *Release )( 
                IMalloc * This);
            
            void *( STDMETHODCALLTYPE *Alloc )( 
                IMalloc * This,
                /* [in] */ SIZE_T cb);
            
            void *( STDMETHODCALLTYPE *Realloc )( 
                IMalloc * This,
                /* [in] */ void *pv,
                /* [in] */ SIZE_T cb);
            
            void ( STDMETHODCALLTYPE *Free )( 
                IMalloc * This,
                /* [in] */ void *pv);
            
            SIZE_T ( STDMETHODCALLTYPE *GetSize )( 
                IMalloc * This,
                /* [in] */ void *pv);
            
            int ( STDMETHODCALLTYPE *DidAlloc )( 
                IMalloc * This,
                void *pv);
            
            void ( STDMETHODCALLTYPE *HeapMinimize )( 
                IMalloc * This);
            
            END_INTERFACE
        } IMallocVtbl;
    
        interface IMalloc
        {
            CONST_VTBL struct IMallocVtbl *lpVtbl; //ERROR POINTS HERE
        };

    line 1103 is where the interface starts.

    Free sure looks like a member of IMalloc to me.

    I deleted all the temp files, didn't work. Are you using a .c or .cpp file to check my code? I'm doing this all in C.

    Thanks for your help.
    {RTFM, KISS}

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Are you using a .c or .cpp file to check my code? I'm doing this all in C.<<

    Good point - cpp so i'm compiling as C++ while yours should compile as C. The calling convention for COM is different between the two, so you could try:
    Code:
    pMalloc->lpVtbl->Free(pMalloc,idList);
    instead of 'pMalloc->Free(idList);' and see if that works out.

  5. #5
    Climber spoon_'s Avatar
    Join Date
    Jun 2002
    Location
    ATL
    Posts
    182
    woot! BIG woot! problem solved. thanks Ken! = )
    Last edited by spoon_; 02-26-2003 at 03:20 PM.
    {RTFM, KISS}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 03:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 01:17 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21