How to- Assign Default Folder: IFileDialog

Hey there,
I need your help.

I'm trying to set the default folder of a IFileDialog instance and I'm having trouble getting the char array containing the pathway, into the IShellItem to set it.

What I've done so far is:
1
2
3
4
5
6
7
8
9
10
11
12
CComPtr<IShellItem> psiFolder;
LPWSTR wszPath = NULL;

// Convert char[] to LPWSTR here..

hr = SHCreateItemFromParsingName(wszPath, NULL, IID_PPV_ARGS(&psiFolder));               
if (SUCCEEDED(hr))
{
	hr = pDlg->SetDefaultFolder(psiFolder);
	CoTaskMemFree(wszPath);

	// ... 


I've tried all manner of macros and functions to convert this values.
Including:
mbstowcs_s()
CreateDirectoryA()
MultiByteToWideChar()

I have a feeling I have to use mbstowcs_s() but, I can't get it to work.

Am I going about this whole process wrong?

Please, enlighten me.
This is an example of how to use MultiByteToWideChar. Replace CP_UTF8 with CP_ACP or whatever encoding your char* buffer have (btw, why don't you use wchar_t directly ?)

1
2
3
4
5
int wchars_num =  MultiByteToWideChar( CP_UTF8 , 0 , x.c_str() , -1, NULL , 0 );
wchar_t* wstr = new wchar_t[wchars_num];
MultiByteToWideChar( CP_UTF8 , 0 , x.c_str() , -1, wstr , wchars_num );
// do whatever with wstr
delete[] wstr;
Topic archived. No new replies allowed.