Click here to Skip to main content
15,899,007 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CFileFind Pin
locoone27-Oct-06 10:46
locoone27-Oct-06 10:46 
GeneralRe: CFileFind Pin
Stephen Hewitt29-Oct-06 12:14
Stephen Hewitt29-Oct-06 12:14 
GeneralRe: CFileFind Pin
locoone29-Oct-06 13:17
locoone29-Oct-06 13:17 
GeneralRe: CFileFind Pin
Stephen Hewitt29-Oct-06 13:29
Stephen Hewitt29-Oct-06 13:29 
GeneralRe: CFileFind Pin
locoone29-Oct-06 14:05
locoone29-Oct-06 14:05 
GeneralRe: CFileFind Pin
Stephen Hewitt29-Oct-06 14:16
Stephen Hewitt29-Oct-06 14:16 
GeneralRe: CFileFind Pin
locoone30-Oct-06 13:12
locoone30-Oct-06 13:12 
GeneralRe: CFileFind Pin
Stephen Hewitt30-Oct-06 13:37
Stephen Hewitt30-Oct-06 13:37 
Ok, here a crude implementation of the "Dir" DOS command which uses the shell instead of the file APIs:

--------------------------------------------------

// VDir.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <shlobj.h>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")

void Go(LPCTSTR pFolder)
{
using namespace std;
USES_CONVERSION;

HRESULT hr;

CComPtr<IMalloc> spAlloc;
hr = SHGetMalloc(&spAlloc);
if (FAILED(hr))
{
cerr << "SHGetMalloc failed!" << endl;
return;
}

CComPtr<IShellFolder> spDesktop;
hr = SHGetDesktopFolder(&spDesktop);
if (FAILED(hr))
{
cerr << "SHGetDesktopFolder failed!" << endl;
return;
}

LPITEMIDLIST pFolderPIDL;
hr = spDesktop->ParseDisplayName(
NULL,
NULL,
T2OLE(pFolder),
NULL,
&pFolderPIDL,
NULL
);
if (FAILED(hr))
{
cerr << "IShellFolder::ParseDisplayName failed!" << endl;
return;
}

CComPtr<IShellFolder> spFolder;
hr = spDesktop->BindToObject(
pFolderPIDL,
NULL,
IID_IShellFolder,
reinterpret_cast<void**>(&spFolder)
);
spAlloc->Free(pFolderPIDL);
if (FAILED(hr))
{
cerr << "IShellFolder::BindToObject failed!" << endl;
return;
}

CComPtr<IEnumIDList> spEnum;
hr = spFolder->EnumObjects(
NULL,
SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN,
&spEnum
);
if (FAILED(hr))
{
cerr << "IShellFolder::EnumObjects failed!" << endl;
return;
}

LPITEMIDLIST pPIDL;
while ( (hr=spEnum->Next(1, &pPIDL, NULL))==S_OK )
{
STRRET Name;
hr = spFolder->GetDisplayNameOf(pPIDL, SHGDN_NORMAL, &Name);
if (SUCCEEDED(hr))
{
LPWSTR pDisplayName;
hr = StrRetToStrW(&Name, pPIDL, &pDisplayName);
if (SUCCEEDED(hr))
{
cout << W2CA(pDisplayName) << endl;
spAlloc->Free(pDisplayName);
}
}

spAlloc->Free(pPIDL);
}
}

int main(int argc, char* argv[])
{
using namespace std;

if (argc<2)
{
cerr << "No directory specified!" << endl;
return 1;
}

OleInitialize(NULL);
Go(argv[1]);
OleUninitialize();

return 0;
}


Steve
GeneralRe: CFileFind Pin
locoone30-Oct-06 13:47
locoone30-Oct-06 13:47 
GeneralRe: CFileFind Pin
Stephen Hewitt30-Oct-06 13:59
Stephen Hewitt30-Oct-06 13:59 
GeneralRe: CFileFind Pin
locoone30-Oct-06 14:07
locoone30-Oct-06 14:07 
GeneralRe: CFileFind Pin
Stephen Hewitt30-Oct-06 14:19
Stephen Hewitt30-Oct-06 14:19 
GeneralRe: CFileFind Pin
Stephen Hewitt30-Oct-06 14:26
Stephen Hewitt30-Oct-06 14:26 
QuestionExcel Page Pin
roadme25-Oct-06 11:26
roadme25-Oct-06 11:26 
AnswerRe: Excel Page Pin
freeman86825-Oct-06 16:59
freeman86825-Oct-06 16:59 
GeneralRe: Excel Page [modified] Pin
freeman86825-Oct-06 17:01
freeman86825-Oct-06 17:01 
GeneralRe: Excel Page Pin
roadme27-Oct-06 8:42
roadme27-Oct-06 8:42 
GeneralRe: Excel Page Pin
roadme27-Oct-06 9:00
roadme27-Oct-06 9:00 
QuestionReading from File question... [modified] Pin
q_p25-Oct-06 11:20
q_p25-Oct-06 11:20 
AnswerRe: Reading from File question... Pin
led mike25-Oct-06 11:34
led mike25-Oct-06 11:34 
GeneralRe: Reading from File question... Pin
q_p25-Oct-06 11:40
q_p25-Oct-06 11:40 
GeneralRe: Reading from File question... Pin
Zac Howland25-Oct-06 11:47
Zac Howland25-Oct-06 11:47 
GeneralRe: Reading from File question... Pin
led mike25-Oct-06 11:49
led mike25-Oct-06 11:49 
AnswerRe: Reading from File question... Pin
Zac Howland25-Oct-06 11:45
Zac Howland25-Oct-06 11:45 
GeneralRe: Reading from File question... Pin
led mike25-Oct-06 12:01
led mike25-Oct-06 12:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.