Method that provides the path of a file containing the image to use for the icon of the plugin in the contextual menu.
| 105 | // Method that provides the path of a file containing the image to use |
| 106 | // for the icon of the plugin in the contextual menu. |
| 107 | [[gsl::suppress(c.128), gsl::suppress(f.6)]] |
| 108 | STDMETHODIMP CPathCopyCopyPlugin2b::get_IconFile(BSTR *p_ppIconFile) |
| 109 | { |
| 110 | // Initialize to NULL in case we fail to provide a file. |
| 111 | if (p_ppIconFile != nullptr) { |
| 112 | *p_ppIconFile = nullptr; |
| 113 | } else { |
| 114 | return E_INVALIDARG; |
| 115 | } |
| 116 | HRESULT hRes = E_FAIL; |
| 117 | |
| 118 | try { |
| 119 | // Get path to this module. |
| 120 | std::wstring thisModulePath(MAX_PATH + 1, L'\0'); |
| 121 | if (::GetModuleFileNameW(CTestPluginsModule::HInstance(), &*thisModulePath.begin(), gsl::narrow<DWORD>(thisModulePath.size())) != 0) { |
| 122 | // Remove filename from path. |
| 123 | std::wstring path(thisModulePath.c_str()); |
| 124 | std::wstring::size_type lastDelimPos = path.find_last_of(L"\\/"); |
| 125 | if (lastDelimPos != std::wstring::npos) { |
| 126 | path.erase(lastDelimPos); |
| 127 | } else { |
| 128 | path.clear(); |
| 129 | } |
| 130 | |
| 131 | // Go up three levels then dig to find the icon file. |
| 132 | for (int i = 0; i < 3; ++i) { |
| 133 | lastDelimPos = path.find_last_of(L"\\/"); |
| 134 | if (lastDelimPos != std::wstring::npos) { |
| 135 | path.erase(lastDelimPos); |
| 136 | } else { |
| 137 | path.clear(); |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | path += L"\\icons\\settings.ico"; |
| 142 | |
| 143 | // Return resulting path. |
| 144 | *p_ppIconFile = ::SysAllocString(path.c_str()); |
| 145 | hRes = S_OK; |
| 146 | } |
| 147 | } catch (...) { |
| 148 | hRes = E_UNEXPECTED; |
| 149 | } |
| 150 | |
| 151 | return hRes; |
| 152 | } |
| 153 | |
| 154 | // Method that determines whether the plugin uses the default icon. |
| 155 | [[gsl::suppress(c.128), gsl::suppress(f.6)]] |
no test coverage detected