I am trying to create open file dialog. In the past I used to use GetOpenFileName function, however MSDN suggests not to use it and it's not available in Visual Studio 2012 at all, so I had to use IFileOpenDialog interface. Sadly I ran into some problems, it just fails randomly with HRESULT of RPC_E_WRONG_THREAD, even though whole dialog is handled on the single thread. Anyone knows solution to this? Here's my code:
COMDLG_FILTERSPEC c_rgSaveTypes[] = {
{L"Any File", L"*.*"},
};
IFileOpenDialog *pfd;
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
assert(pfd);
DWORD dwFlags;
pfd->GetOptions(&dwFlags);
pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
pfd->SetFileTypeIndex(0);
if(FAILED(pfd->Show(0)))
return;
IShellItem *result;
pfd->GetResult(&result);
PWSTR pszFilePath;
HRESULT hr = result->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); // this call fails
if(FAILED(hr))
return; // breakpoint gets triggered here
pathToFile = string_cast<string>(wstring(pszFilePath));
CoTaskMemFree(pszFilePath);
Thank you in advance.
Edited by Ripiz, 10 August 2012 - 01:05 PM.






