if (FAILED(hr))
return 0;
std::unique_ptr<MIMECPINFO[]> pcpInfo(new MIMECPINFO[count]);
- pEnumCodePage->Next(count, pcpInfo.get(), &ccpInfo);
+ if (FAILED(pEnumCodePage->Next(count, pcpInfo.get(), &ccpInfo)))
+ return 0;
for (int i = 0; i < (int)ccpInfo; i++)
{
return CSize(0,0);
LONG hmWidth, hmHeight; // HIMETRIC units
- m_spIPicture->get_Width(&hmWidth);
- m_spIPicture->get_Height(&hmHeight);
+ if (FAILED(m_spIPicture->get_Width(&hmWidth)) || FAILED(m_spIPicture->get_Height(&hmHeight)))
+ return CSize(0, 0);
CSize sz(hmWidth,hmHeight);
if (pDC==NULL) {
CWindowDC dc(NULL);
{
pDispInfo->ceItem.mask |= CBEIF_DI_SETITEM;
SHFILEINFO sfi = {0};
- TCHAR szDrive[5] = {0};
CString sText;
GetLBText(static_cast<int>(pDispInfo->ceItem.iItem), sText);
- lstrcpyn(szDrive, sText, 4);
- if (sText[1] != '\\' && GetDriveType(szDrive) != DRIVE_REMOTE)
+ CString sDrive = sText.Left(3);
+ if (!(sText.GetLength() > 2 && (sText[1] == '\\' || GetDriveType(sDrive) == DRIVE_REMOTE)))
{
// The path is not a network path.
if (SHGetFileInfo(sText, 0, &sfi, sizeof(sfi),
{
m_bVersionFound = TRUE;
m_pVffInfo.reset(new BYTE[dwVerInfoSize]);
- if (GetFileVersionInfo(szFileName, dwVerHnd, dwVerInfoSize, m_pVffInfo.get()))
+ if (GetFileVersionInfo(szFileName, 0, dwVerInfoSize, m_pVffInfo.get()))
{
GetFixedVersionInfo();
if (m_bVersionOnly == FALSE)
ASSERT(::GlobalSize(hData) == cbData);
LPTSTR pszData = (LPTSTR)::GlobalLock (hData);
- memcpy (pszData, text, cbData);
+ if (pszData)
+ memcpy (pszData, text, cbData);
::GlobalUnlock (hData);
m_ptDraggedTextBegin = m_ptDrawSelStart;
std::string GetIconPNGData(int iconIndex) const
{
HIMAGELIST hImageList = ListView_GetImageList(m_hwndListCtrl, LVSIL_SMALL);
- IMAGEINFO imageInfo = {0};
- LARGE_INTEGER li = {0};
- IStream *pStream = NULL;
- CImage image;
-
- ImageList_GetImageInfo(hImageList, iconIndex, &imageInfo);
- int w = imageInfo.rcImage.right - imageInfo.rcImage.left;
- int h = imageInfo.rcImage.bottom - imageInfo.rcImage.top;
- CreateStreamOnHGlobal(NULL, TRUE, &pStream);
- HDC hdcMem = CreateCompatibleDC(NULL);
- BITMAPINFO bmpinfo = {0};
- bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmpinfo.bmiHeader.biWidth = w;
- bmpinfo.bmiHeader.biHeight = h;
- bmpinfo.bmiHeader.biPlanes = 1;
- bmpinfo.bmiHeader.biBitCount = 32;
- bmpinfo.bmiHeader.biCompression = BI_RGB;
- HBITMAP hbmpImage = CreateDIBSection( NULL, &bmpinfo, DIB_RGB_COLORS, NULL, NULL, NULL);
- HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpImage);
- ImageList_Draw(hImageList, iconIndex, hdcMem, 0, 0, ILD_TRANSPARENT);
- image.Attach(hbmpImage);
- image.SetHasAlphaChannel(true);
- image.Save(pStream, Gdiplus::ImageFormatPNG);
- STATSTG stat;
- pStream->Stat(&stat, STATFLAG_NONAME);
- std::string ret(stat.cbSize.LowPart, 0);
- pStream->Seek(li, STREAM_SEEK_SET, NULL);
- pStream->Read(&ret[0], stat.cbSize.LowPart, NULL);
- pStream->Release();
-
- SelectObject(hdcMem, hbmpOld);
- DeleteObject(hdcMem);
- DeleteObject(hbmpImage);
+ IMAGEINFO imageInfo;
+ std::string ret;
+ if (ImageList_GetImageInfo(hImageList, iconIndex, &imageInfo))
+ {
+ HDC hdcMem = CreateCompatibleDC(NULL);
+ BITMAPINFO bmpinfo = { 0 };
+ bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ int w = imageInfo.rcImage.right - imageInfo.rcImage.left;
+ int h = imageInfo.rcImage.bottom - imageInfo.rcImage.top;
+ bmpinfo.bmiHeader.biWidth = w;
+ bmpinfo.bmiHeader.biHeight = h;
+ bmpinfo.bmiHeader.biPlanes = 1;
+ bmpinfo.bmiHeader.biBitCount = 32;
+ bmpinfo.bmiHeader.biCompression = BI_RGB;
+ HBITMAP hbmpImage = CreateDIBSection(NULL, &bmpinfo, DIB_RGB_COLORS, NULL, NULL, NULL);
+ HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmpImage);
+ ImageList_Draw(hImageList, iconIndex, hdcMem, 0, 0, ILD_TRANSPARENT);
+ CImage image;
+ image.Attach(hbmpImage);
+ image.SetHasAlphaChannel(true);
+ IStream *pStream = NULL;
+ if (SUCCEEDED(CreateStreamOnHGlobal(NULL, TRUE, &pStream)))
+ {
+ image.Save(pStream, Gdiplus::ImageFormatPNG);
+ STATSTG stat;
+ if (SUCCEEDED(pStream->Stat(&stat, STATFLAG_NONAME)))
+ {
+ LARGE_INTEGER li = {0};
+ ret.resize(0, stat.cbSize.LowPart);
+ pStream->Seek(li, STREAM_SEEK_SET, NULL);
+ pStream->Read(&ret[0], stat.cbSize.LowPart, NULL);
+ }
+ pStream->Release();
+ }
+ SelectObject(hdcMem, hbmpOld);
+ DeleteObject(hdcMem);
+ DeleteObject(hbmpImage);
+ }
return ret;
}
if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
{
PROPVARIANT pv;
- InitPropVariantFromString(title.c_str(), &pv);
- pPS->SetValue(PKEY_Title, pv);
- PropVariantClear(&pv);
+ if (SUCCEEDED(InitPropVariantFromString(title.c_str(), &pv)))
+ {
+ pPS->SetValue(PKEY_Title, pv);
+ PropVariantClear(&pv);
+ }
pPS->Commit();
pPS->Release();
}
if (SUCCEEDED(pDocumentLists->GetList(ADLT_RECENT, static_cast<UINT>(nMaxItems), IID_IObjectArray, (void **)&pObjectArray)))
{
UINT nObjects;
- pObjectArray->GetCount(&nObjects);
- for (UINT i = 0; i < nObjects; ++i)
+ if (SUCCEEDED(pObjectArray->GetCount(&nObjects)))
{
- IShellLinkW *pShellLink;
- if (SUCCEEDED(pObjectArray->GetAt(i, IID_IShellLinkW, (void **)&pShellLink)))
+ for (UINT i = 0; i < nObjects; ++i)
{
- wchar_t szPath[MAX_PATH];
- wchar_t szDescription[MAX_PATH];
- wchar_t szArguments[MAX_PATH * 6];
- pShellLink->GetPath(szPath, sizeof(szPath)/sizeof(szPath[0]), NULL, SLGP_RAWPATH);
- pShellLink->GetDescription(szDescription, sizeof(szDescription)/sizeof(szDescription[0]));
- pShellLink->GetArguments(szArguments, sizeof(szArguments)/sizeof(szArguments[0]));
- IPropertyStore *pPS = NULL;
- PROPVARIANT pv;
- InitPropVariantFromString(L"", &pv);
- if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
+ IShellLinkW *pShellLink;
+ if (SUCCEEDED(pObjectArray->GetAt(i, IID_IShellLinkW, (void **)&pShellLink)))
{
- pPS->GetValue(PKEY_Title, &pv);
- pPS->Release();
+ wchar_t szPath[MAX_PATH];
+ wchar_t szDescription[MAX_PATH];
+ wchar_t szArguments[MAX_PATH * 6];
+ pShellLink->GetPath(szPath, sizeof(szPath) / sizeof(szPath[0]), NULL, SLGP_RAWPATH);
+ pShellLink->GetDescription(szDescription, sizeof(szDescription) / sizeof(szDescription[0]));
+ pShellLink->GetArguments(szArguments, sizeof(szArguments) / sizeof(szArguments[0]));
+ IPropertyStore *pPS = NULL;
+ if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
+ {
+ PROPVARIANT pv;
+ if (SUCCEEDED(pPS->GetValue(PKEY_Title, &pv)))
+ {
+ list.push_back(Item(ucr::toTString(szPath), ucr::toTString(szArguments), ucr::toTString(pv.bstrVal), ucr::toTString(szDescription)));
+ PropVariantClear(&pv);
+ }
+ pPS->Release();
+ }
+ pShellLink->Release();
}
- list.push_back(Item(ucr::toTString(szPath), ucr::toTString(szArguments), ucr::toTString(pv.bstrVal), ucr::toTString(szDescription)));
- PropVariantClear(&pv);
- pShellLink->Release();
- }
+ }
}
pObjectArray->Release();
}
g_bPredifferMode = theApp.GetProfileInt(_T("Settings"), _T("PredifferMode"), PLUGIN_MANUAL);
NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS };
- SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0);
- HDC hdc = ::GetDC(NULL);
- int lfHeight = -MulDiv(9, GetDeviceCaps(hdc, LOGPIXELSY), 72);
- ::ReleaseDC(NULL, hdc);
- if (abs(ncm.lfMenuFont.lfHeight) > abs(lfHeight))
- ncm.lfMenuFont.lfHeight = lfHeight;
- m_fontGUI.CreateFontIndirect(&ncm.lfMenuFont);
+ if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0))
+ {
+ HDC hdc = ::GetDC(NULL);
+ int lfHeight = -MulDiv(9, GetDeviceCaps(hdc, LOGPIXELSY), 72);
+ ::ReleaseDC(NULL, hdc);
+ if (abs(ncm.lfMenuFont.lfHeight) > abs(lfHeight))
+ ncm.lfMenuFont.lfHeight = lfHeight;
+ m_fontGUI.CreateFontIndirect(&ncm.lfMenuFont);
+ }
if (m_pSyntaxColors)
Options::SyntaxColors::Load(m_pSyntaxColors.get());
))
{
str = (LPCTSTR)lpMsgBuf;
+ // Free the buffer.
+ LocalFree( lpMsgBuf );
}
- // Free the buffer.
- LocalFree( lpMsgBuf );
return str;
}
szError[1] = '\n';
strError += szError;
}
- if (bFreeLibrary)
+ if (bFreeLibrary && handle)
{
FreeLibrary(handle);
}
#include <shlwapi.h>
#include "PathContext.h"
#include "unicoder.h"
+#include "coretools.h"
static bool IsSlash(const String& pszStart, size_t nPos);
static bool GetDirName(const String& sDir, String& sName);
// Expand environment variables:
// Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
- const TCHAR *lpcszPath;
- TCHAR expandedPath[_MAX_PATH] = {0};
+ const TCHAR *lpcszPath = szPath.c_str();
+ TCHAR expandedPath[_MAX_PATH];
- if (_tcschr(szPath.c_str(), '%') &&
- ExpandEnvironmentStrings(szPath.c_str(), expandedPath, _MAX_PATH))
+ if (_tcschr(lpcszPath, '%'))
{
- lpcszPath = expandedPath;
+ DWORD dwLen = ExpandEnvironmentStrings(lpcszPath, expandedPath, _MAX_PATH);
+ if (dwLen > 0 && dwLen < _MAX_PATH)
+ lpcszPath = expandedPath;
}
- else
- lpcszPath = szPath.c_str();
DWORD attr = GetFileAttributes(lpcszPath);
// Expand environment variables:
// Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
- TCHAR expandedPath[_MAX_PATH] = {0};
- const TCHAR *lpcszPath = NULL;
-
- if (bExpandEnvs && _tcschr(sPath.c_str(), '%'))
+ TCHAR expandedPath[_MAX_PATH];
+ const TCHAR *lpcszPath = sPath.c_str();
+ if (bExpandEnvs && _tcschr(lpcszPath, '%'))
{
- if (ExpandEnvironmentStrings(sPath.c_str(), expandedPath, _MAX_PATH))
- {
+ DWORD dwLen = ExpandEnvironmentStrings(lpcszPath, expandedPath, _MAX_PATH);
+ if (dwLen > 0 && dwLen < _MAX_PATH)
lpcszPath = expandedPath;
- }
}
- else
- lpcszPath = sPath.c_str();
- if (!GetFullPathName(lpcszPath, _MAX_PATH, fullPath, &lpPart))
- _tcscpy(fullPath, sPath.c_str());
+ DWORD dwLen = GetFullPathName(lpcszPath, _MAX_PATH, fullPath, &lpPart);
+ if (dwLen == 0 || dwLen >= _MAX_PATH)
+ _tcscpy_safe(fullPath, lpcszPath);
// We are done if this is not a short name.
if (_tcschr(fullPath, _T('~')) == NULL)
// Expand environment variables:
// Convert "%userprofile%\My Documents" to "C:\Documents and Settings\username\My Documents"
- TCHAR fullPath[_MAX_PATH] = _T("");
- if (!_tcschr(szPath.c_str(), '%') || !ExpandEnvironmentStrings(szPath.c_str(), fullPath, _MAX_PATH))
+ TCHAR fullPath[_MAX_PATH];
+ if (_tcschr(szPath.c_str(), '%'))
{
- _tcscpy(fullPath, szPath.c_str());
+ DWORD dwLen = ExpandEnvironmentStrings(szPath.c_str(), fullPath, _MAX_PATH);
+ if (dwLen == 0 || dwLen >= _MAX_PATH)
+ _tcscpy_safe(fullPath, szPath.c_str());
}
+ else
+ _tcscpy_safe(fullPath, szPath.c_str());
// Now fullPath holds our desired path
TCHAR *ptr = fullPath;
{
WCHAR wsz[MAX_PATH];
#ifdef _UNICODE
- wcsncpy((wchar_t *)wsz, inFile.c_str(), sizeof(wsz) / sizeof(WCHAR));
+ _tcscpy_safe(wsz, inFile.c_str());
#else
::MultiByteToWideChar(CP_ACP, 0, inFile.c_str(), -1, wsz, MAX_PATH);
#endif