首页 > 代码库 > MFC 手动选择文件夹并将文件夹地址从CString转换为char[]数组

MFC 手动选择文件夹并将文件夹地址从CString转换为char[]数组

 1     BROWSEINFO bi;
 2     ZeroMemory(&bi, sizeof(BROWSEINFO));
 3     bi.hwndOwner = m_hWnd;
 4     bi.ulFlags = BIF_RETURNONLYFSDIRS;
 5     LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
 6     BOOL bRet = FALSE;
 7     TCHAR szFolder[100];
 8     szFolder[0] = _T(\0);
 9     if (pidl)
10     {
11         if (SHGetPathFromIDList(pidl, szFolder))
12             bRet = TRUE;
13         IMalloc *pMalloc = NULL;
14         if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc)
15         {
16             pMalloc->Free(pidl);
17             pMalloc->Release();
18         }
19     }
20     CString path;
21     CString end("/");
22     path=szFolder+end;
23     memcpy(pathPrefix,path,100); //char pathPrefix[100];

 

MFC 手动选择文件夹并将文件夹地址从CString转换为char[]数组