Hi,
I am trying to develop a windows explorer type shell, using a treeview and a listview control, on a Windows Forms Application type project of Visual C++ Express.
In Microsoft Platform SDK for Windows Server 2003 R2, there is a sample in the directory below:
\\Microsoft Platform SDK for Windows Server 2003 R2\Samples\WinUI\Shell\EnumDesk
This sample is a makefile type project and using Windows Shell API functions adding related header files to the project.
I want to use these API functions in Windows Forms Application type Project. Is there any solution to manage this
Thanks in advance!

Windows Explorer type shell
CE
Seeing how you're using C++ Express, you have an advantage in that you won't need to use pinvoke to get at the shell APIs (adding the related header files will just work).
There is one more very important trick that you'll need to know to be able to use these functions reliably.
#include <comdefsp.h>
This header defines COM smart pointers for IShellFolder and friends (IEnumIDListPtr, IShellFolder2Ptr, IShellViewPtr, IBindCtxPtr). These smart pointers allow you to access the underlying interfaces without having to worry about managing reference counts.
I assume you already know how useful COM smart pointers can be. If not, I strongly suggest you read up on COM smart pointers before continuing.
Rik Dodsworth
Dear OShah,
I have added the lines below to the main project file of my CLR- Windows Forms Application type project:
#include
<shlobj.h>#include <comdefsp.h>
The source file of the form includes two lines of code:
IShellFolder *psfFolder;
SHGetDesktopFolder(&psfFolder);
But, when I tried to build the project it generated too many errors and stopped building. Here are the first 10 error messages of BuildLog.htm:
d:\myvcprogs\udp\udp\Form1.h(95) : error C2065: 'IShellFolder' : undeclared identifier
d:\myvcprogs\udp\udp\Form1.h(95) : error C2065: 'psfFolder' : undeclared identifier
d:\myvcprogs\udp\udp\Form1.h(97) : error C3861: 'SHGetDesktopFolder': identifier not found
D:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\shobjidl.h(72) : error C2378: 'IShellFolder' : redefinition; symbol cannot be overloaded with a typedef
D:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\shobjidl.h(1608) : error C2065: 'This' : undeclared identifier
D:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\shobjidl.h(1609) : error C2275: 'HWND' : illegal use of this type as an expression
D:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\windef.h(207) : see declaration of 'HWND'
D:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\shobjidl.h(1609) : error C2146: syntax error : missing ')' before identifier 'hwnd'
D:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\shobjidl.h(1609) : warning C4229: anachronism used : modifiers on data are ignored
D:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\shobjidl.h(1609) : error C2078: too many initializers
Thanks in advance for your kind help!
dtwilliamson
Did you read up on COM smart pointers The smart pointers that are given in comdefsp.h are based on C++'s compiler COM support. Please read up on Compiler COM support before continuing.
#include <shlobj.h>
#include <comdef.h>
#include <comdefsp.h>
...
IShellFolderPtr psfFolder;
// Manages an IShellFolder* for you. An auto_ptr for COM objects.
SHGetDesktopFolder(&psfFolder.GetInterfacePtr());
// GetInterfacePtr will get the underlying IShellFolder pointer which the object manages.
IEnumIDListPtr ienum;
psfFolder->EnumObjects(NULL, SHCONTF_FOLDERS, &ienum.GetInterfacePtr());
// Release() will be called for you by the destructor.
kzu
Tracy - MSFT
Thank you very much for your kind respond.
The functions I want to use in the project are:
SHGetDesktopFolder
SHGetSpecialFolderLocation
SHGetFileInfo
IShellFolder Interface functions
Is PInvoke the only method to use these functions
Can I manage using the funtions adding related header files (shlobj.h and shobjidl.h) to the project