Reputation: 138
Question speaks for itself. I have a program that used SHBrowseforfolder, but now they want me to upgrade it to IFileDialog which I made but is in C++, so is it even possible to get it to work with C since it's OOP?
Upvotes: 2
Views: 724
Reputation: 115
This is C code to print the name of a selected folder using IFileDialog
:
#include <shobjidl_core.h> //somewhere in your program
//...
IFileDialog *pfd;
IShellItem *psiResult;
PWSTR pszFilePath = NULL;
if (SUCCEEDED(CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, &IID_IFileOpenDialog, &pfd))){
pfd->lpVtbl->SetOptions(pfd, FOS_PICKFOLDERS);
pfd->lpVtbl->Show(pfd, hwnd);
if (SUCCEEDED(pfd->lpVtbl->GetResult(pfd, &psiResult))){
if (SUCCEEDED(psiResult->lpVtbl->GetDisplayName(psiResult, SIGDN_FILESYSPATH, &pszFilePath))){
WCHAR *p = pszFilePath;
while (*p){
printf("%c",*p);//I don't like unicode
p++;
}
CoTaskMemFree(pszFilePath);
}
psiResult->lpVtbl->Release(psiResult);
}
pfd->lpVtbl->Release(pfd);
}
Upvotes: 0
Reputation: 87957
IFileDialog is part of Microsoft's Component Object Model (COM). COM programming can be done in C. Quite tedious though.
Here's a tutorial (can't vouch for it's quality)
http://www.codeproject.com/Articles/13601/COM-in-plain-C
Upvotes: 4