fix: improve dialog helper

- remove template for CoTaskMemDeleter due to previous confusion.
- use std::remove_pointer_t instead of directly writting underlying type.
This commit is contained in:
yyc12345 2024-05-27 19:48:25 +08:00
parent cebe2f004d
commit efcc371e31
2 changed files with 3 additions and 4 deletions

View File

@ -161,7 +161,7 @@ namespace YYCC::DialogHelper {
bool ExtractDisplayName(IShellItem* item, std::string& ret) {
// fetch display name from IShellItem*
WCHAR* _name;
LPWSTR _name;
HRESULT hr = item->GetDisplayName(SIGDN_FILESYSPATH, &_name);
if (FAILED(hr)) return false;
SmartLPWSTR display_name(_name);

View File

@ -32,18 +32,17 @@ namespace YYCC::DialogHelper {
using SmartIShellItemArray = std::unique_ptr<IShellItemArray, ComPtrDeleter>;
using SmartIShellFolder = std::unique_ptr<IShellFolder, ComPtrDeleter>;
template<typename _Ty>
class CoTaskMemDeleter {
public:
CoTaskMemDeleter() {}
void operator() (_Ty* com_ptr) {
void operator() (void* com_ptr) {
if (com_ptr != nullptr) {
CoTaskMemFree(com_ptr);
}
}
};
using SmartLPWSTR = std::unique_ptr<WCHAR, CoTaskMemDeleter<WCHAR>>;
using SmartLPWSTR = std::unique_ptr<std::remove_pointer_t<LPWSTR>, CoTaskMemDeleter>;
#pragma endregion