문제

내가 원하는 폴더를 삭제 C:\Users\username\AppData\Roaming\appname 사용자가 응용 프로그램을 제거 appname.

첫째,내가 다음 코드를 사용하여 경로를 얻 C:\Users\username\AppData\Roaming:

TCHAR dir[MAX_PATH];
dir[0] = '\0';
BOOL ok = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, TRUE);

appname 으로 정의 _T("appname")

첫 번째 질문입니다: How to append "appname" to "dir"?

가정한 상이 수행됩니다.다음 사용 SHFileOperation 을 삭제하는 비어 있는 폴더 C:\Users\username\AppData\Roaming\appname.그래서 나를 필요로 한다 null 로 끝나는 문자열에서 SHFILEOPSTRUCT 구조입니다.그래서

How to get a double null-terminated string from the result of the first step? Just append _T("\0\0") to it?

업데이트:나는 사용할 수 있는 TCHAR *dir2 = lstrcat(dir, appname); 을 얻습니다.그러나 때 사용하려고 했 TCHAR *dir3 = lstrcat(dir2, _T("\0\0"));, 폴더가 삭제되지 않습니다.의 수 \0 이 작동하지 않습니다.


p.s:

내가 할 경우 다음과 같은 바로,나는 그것을 가지고 작동합니다.문제는 내가 원하는 그것을 할 사용자-독립적입니다.

TCHAR path[] = _T("C:\\Users\\username\\AppData\\Roaming\\appname");
memcpy(path + sizeof(path) / sizeof(TCHAR) - 1, _T("\0\0\0"), 3);
도움이 되었습니까?

해결책

에 대한 추가하는 경로를 볼 PathAppend 기능입니다.

TCHAR dir[MAX_PATH] = {0};

BOOL ok = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, TRUE);

PathAppend(dir, _T("appname"));

당신이 원하는 경우도록 더블 null 약 dir 변:

dir[MAX_PATH - 1] = 0;
dir[MAX_PATH - 2] = 0;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top