IShellFolder::GetDisplayNameOf return 乱码
IShellFolder::GetDisplayNameOf return gibberish
我是 winapi 和 c/c++ 的新手,我尝试使用 IShellFolder::GetDisplayNameOf 打印出桌面上图标的名称,但由于某种原因,我遇到了乱码。这是我的代码:
int main() {
HRESULT hr;
IShellFolder* deskFolder;
hr = SHGetDesktopFolder(&deskFolder);
IEnumIDList* listilist;
deskFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &listilist);
ITEMIDLIST* item;
deskFolder->Release();
while (listilist->Next(1, &item, NULL) == S_OK) {
STRRET coo = {0};
deskFolder->GetDisplayNameOf(item, SHGDN_INFOLDER, &coo);
printf("%s\n", coo.cStr);
item = NULL;
}
return 0;
}
根据 document:
uType
Type: UINT
A value that specifies the desired format of the string. This can be
one of the following values.
STRRET_CSTR
The string is returned in the cStr member.
STRRET_OFFSET
The uOffset member value indicates the number of bytes
from the beginning of the item identifier list where the string is
located.
STRRET_WSTR
The string is at the address specified by pOleStr member.
可以查看coo
的utype
参数:
printf("%d\n", coo.uType);
经查其return值为0(STRRET_WSTR
),所以需要修改代码为
printf("%S\n", coo.pOleStr);
我是 winapi 和 c/c++ 的新手,我尝试使用 IShellFolder::GetDisplayNameOf 打印出桌面上图标的名称,但由于某种原因,我遇到了乱码。这是我的代码:
int main() {
HRESULT hr;
IShellFolder* deskFolder;
hr = SHGetDesktopFolder(&deskFolder);
IEnumIDList* listilist;
deskFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &listilist);
ITEMIDLIST* item;
deskFolder->Release();
while (listilist->Next(1, &item, NULL) == S_OK) {
STRRET coo = {0};
deskFolder->GetDisplayNameOf(item, SHGDN_INFOLDER, &coo);
printf("%s\n", coo.cStr);
item = NULL;
}
return 0;
}
根据 document:
uType
Type: UINT
A value that specifies the desired format of the string. This can be one of the following values.
STRRET_CSTR
The string is returned in the cStr member.
STRRET_OFFSET
The uOffset member value indicates the number of bytes from the beginning of the item identifier list where the string is located.
STRRET_WSTR
The string is at the address specified by pOleStr member.
可以查看coo
的utype
参数:
printf("%d\n", coo.uType);
经查其return值为0(STRRET_WSTR
),所以需要修改代码为
printf("%S\n", coo.pOleStr);