Archived

This topic is now archived and is closed to further replies.

How to open directories (similar to GetOpenFileName) ??

This topic is 5242 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I''m looking for something similar to GetOpenFileName(), but instead of choosing a file I want to choose a directory. While browsing msdn I found this function : SHBrowseForFolder(). But this doesn''t work (Probably it has something to do with the "SH" in front of it...i guess I have to include something, but I don''t know what though.) Thanks !

Share this post


Link to post
Share on other sites
Thanks !! But I still have a problem initializing the COM library.
They say I have to use the function CoInitializeEx() to do this. I''ve included the necessary header(objbase.h) but I get the error : "undeclared identifier". :s

This is what I found in msdn :

Header: Declared in objbase.h.
Import Library: Included as a resource in ole32.dll.

I have checked the files and they are all included...

Anything else i''m forgetting ??

Share this post


Link to post
Share on other sites
I double checked it : the program is linked to Ole32.lib

This is the error I get : e:\programmeren\filesync\filesync.cpp(305) : error C2065: 'CoInitializeEx' : undeclared identifier

[edited by - BertVanSemmertier on August 6, 2003 1:20:39 PM]

edit : I tried CoInitialize() and this works !!
But at msdn they say you really should use CoInitializeEx() in new applications. Besides I HAVE to use CoInitializeEx() before I can use SHBrowseForFolder().

[edited by - BertVanSemmertier on August 6, 2003 1:24:43 PM]

Share this post


Link to post
Share on other sites
You have to define something before you include your headers - let me dig up my code...

Here it is:

#include <ObjBase.h>
#include <COMDef.h>
#include <COMUtil.h>

//...

//If this is undefined, put "#define _WIN32_WINNT 0x0500" before the include ObjBase
//alternatively, you can use #define _WIN32_WINNT 0x0501 for XP
// at the top of your StdAfx.h file - before *anything* else
if(FAILED(hr=CoInitializeEx(NULL, COINIT_MULTITHREADED)))
_com_issue_error(hr);


You might not want the MTA though - you probably want the STA (the default).


PS You can most likley use Coinitialize with SHBrowseForFolder and it'll work just fine.

[edited by - Magmai Kai Holmlor on August 6, 2003 8:59:26 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor

//If this is undefined, put "#define _WIN32_WINNT 0x0500"

You might not want the MTA though - you probably want the STA (the default).



Great !! This did the trick !! Where did you find this info ?? It isn''t mentioned in the msdn library

quote:
Original post by Magmai Kai Holmlor
You might not want the MTA though - you probably want the STA (the default).



What do you mean ??


Thanks again !!



Share this post


Link to post
Share on other sites
Ok, one last problem (i hope )

Everything works fine now !! But I''d like to get the full path of the selected folder. The only thing that is saved in "pszDisplayName" is the name of the selected folder (without the path).
I tried to use GetFullPathName() but that doesn''t work...

Any ideas ??

thanks again...

Share this post


Link to post
Share on other sites