How to open directories (similar to GetOpenFileName) ??

Started by
7 comments, last by BertVanSemmertier 20 years, 8 months ago
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 !
Advertisement
Try including Shlobj.h.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Look here:

Clickage

Be sure to read the remarks, you have to intialize COM.

EDIT: made clicky


[edited by - CodeMunkie on August 5, 2003 3:37:40 PM]
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
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 ??

It says you can just use CoIntialize since it automatically uses apartment threading. What error are you getting? Are you linking to ole32.dll?
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
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]
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* elseif(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]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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 !!



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...

This topic is closed to new replies.

Advertisement