Thread: SHSimpleIDListFromPath() and MinGW

  1. #1
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555

    SHSimpleIDListFromPath() and MinGW

    I want some way to convert a path into a PIDL so I can pass it when calling SHBrowseForFolder(). SHSimpleIDListFromPath() seemed to do this but I get both an implicit declaration warning and a linker error when compiling. shlobj.h in my MinGW installation (latest version) does not seem to contain any prototype for it. I guess it's not implemented but not sure why.
    http://msdn.microsoft.com/en-us/libr...54(VS.85).aspx says it's deprecated, but the alternative pointed out in the remarks section seems to be some C++ solution, but I'm writing C.

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    Maybe there is an official function that does what you need, but until you find it you can
    follow this link to the pdf of Dino Esposito's Windows Shell Programming in Visual C++
    and if you go to page 105 you'll find the code for SHPathToPidl() function and the story
    behind it. (Then look at page 115 for SHPathToPidlEx).

  3. #3
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    I tried to work something out of that and came up with this for anyone interested.
    Code:
    ITEMIDLIST* path_to_pidl (const TCHAR* path)
    {
    	ITEMIDLIST* pidl;
    	LPSHELLFOLDER desktop;
    	HANDLE hr;
    #ifndef _UNICODE
    	wchar_t wpath[MAX_PATH];
    #endif
    
    	if (SUCCEEDED(SHGetDesktopFolder(&desktop))) {
    #ifndef _UNICODE
    		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, wpath, sizeof(wpath)/sizeof(*wpath));
    		hr = (HANDLE) desktop->lpVtbl->ParseDisplayName(desktop, NULL, NULL, wpath, NULL, &pidl, NULL);
    #else
    		hr = (HANDLE) desktop->lpVtbl->ParseDisplayName(desktop, NULL, NULL, path, NULL, &pidl, NULL);
    #endif
    		/* desktop->lpVtbl->Release(); */
    
    		if (FAILED(hr))
    			return NULL;
    		return pidl;
    	}
    
    	return NULL;
    }
    The Release method seems to take an argument so I don't know what to pass. The SHGetMalloc() function for freeing the PIDL is also deprecated. I also notcied there is no SHELLFOLDER type, just LPSHELLFOLDER. Jesus, Microsoft.

    As it turns out though, this PIDL does not do what I want to do. It sets the root of the file browser dialog to be the folder represented by the PIDL so you can't go anywhere above it when I really just wanted that folder to be selected.

    I guess I'll just have to force the user to keep navigating from the root every time they want to select a folder.

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    The Release method seems to take an argument so I don't know what to pass.
    Just pass desktop. Hope you can think about this after the misfortune with Russia, but as you
    already know about lpVtbl, all you need to do is continue with this simple rule:

    comObj->method (p1,p2...) in c++, becomes comObj->lpVtbl->method (comObj ,p1,p2...) in pure C.

    And take a look at What's the difference between SHGetMalloc, SHAlloc, CoGetMalloc, and CoTaskMemAlloc

    But, as you've said above, all is in vain - SHBrowseForFolder() is one ugly beast, probably equally
    hated by the developers as well as end users. Have you tried changing current working dir
    before the call?

  5. #5
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    I tried changing it and that did no difference. It still opened the dialog with "My Computer" unfolded.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mingw and elcipse HELP
    By Rob4226 in forum Windows Programming
    Replies: 1
    Last Post: 03-04-2008, 01:35 AM
  2. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  3. compiling mingw to enable timeSetEvent
    By underthesun in forum Windows Programming
    Replies: 2
    Last Post: 02-02-2005, 06:00 PM
  4. SDL and MinGW Studio
    By Vicious in forum Tech Board
    Replies: 0
    Last Post: 07-30-2004, 09:59 PM
  5. Convert Microsoft LIB to MingW compatible lib
    By tigs in forum Windows Programming
    Replies: 0
    Last Post: 07-20-2004, 06:53 PM