Skip to content

Commit ba0ea58

Browse files
committed
Updated GetModuleFileName calls to handle path length > _MAX_PATH.
1 parent 3061ee4 commit ba0ea58

16 files changed

+53
-26
lines changed

ConnectionSettingsDlg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

ConnectionSettingsDlg.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

HtmlToText.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

HtmlToText.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

UnquoteHTML.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

WebSearchEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

WebSearchEngine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

WebSearchEngine.rc

0 Bytes
Binary file not shown.

WebSearchEngineDlg.cpp

+36-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it
@@ -77,20 +77,46 @@ BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
7777
ON_WM_DESTROY()
7878
END_MESSAGE_MAP()
7979

80+
CString GetModuleFileName(_Inout_opt_ DWORD* pdwLastError = nullptr)
81+
{
82+
CString strModuleFileName;
83+
DWORD dwSize{ _MAX_PATH };
84+
while (true)
85+
{
86+
TCHAR* pszModuleFileName{ strModuleFileName.GetBuffer(dwSize) };
87+
const DWORD dwResult{ ::GetModuleFileName(nullptr, pszModuleFileName, dwSize) };
88+
if (dwResult == 0)
89+
{
90+
if (pdwLastError != nullptr)
91+
*pdwLastError = GetLastError();
92+
strModuleFileName.ReleaseBuffer(0);
93+
return CString{};
94+
}
95+
else if (dwResult < dwSize)
96+
{
97+
if (pdwLastError != nullptr)
98+
*pdwLastError = ERROR_SUCCESS;
99+
strModuleFileName.ReleaseBuffer(dwResult);
100+
return strModuleFileName;
101+
}
102+
else if (dwResult == dwSize)
103+
{
104+
strModuleFileName.ReleaseBuffer(0);
105+
dwSize *= 2;
106+
}
107+
}
108+
}
109+
80110
BOOL CAboutDlg::OnInitDialog()
81111
{
82112
CDialog::OnInitDialog();
83113

84-
TCHAR lpszDrive[_MAX_DRIVE];
85-
TCHAR lpszDirectory[_MAX_DIR];
86-
TCHAR lpszFilename[_MAX_FNAME];
87-
TCHAR lpszExtension[_MAX_EXT];
88-
TCHAR lpszFullPath[_MAX_PATH];
89-
90-
VERIFY(0 == _tsplitpath_s(AfxGetApp()->m_pszHelpFilePath, lpszDrive, _MAX_DRIVE, lpszDirectory, _MAX_DIR, lpszFilename, _MAX_FNAME, lpszExtension, _MAX_EXT));
91-
VERIFY(0 == _tmakepath_s(lpszFullPath, _MAX_PATH, lpszDrive, lpszDirectory, lpszFilename, _T(".exe")));
114+
CString strFullPath{ GetModuleFileName() };
115+
if (strFullPath.IsEmpty())
116+
#pragma warning(suppress: 26487)
117+
return FALSE;
92118

93-
if (m_pVersionInfo.Load(lpszFullPath))
119+
if (m_pVersionInfo.Load(strFullPath.GetString()))
94120
{
95121
CString strName = m_pVersionInfo.GetProductName().c_str();
96122
CString strVersion = m_pVersionInfo.GetProductVersionAsString().c_str();

WebSearchEngineDlg.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

WebSearchEngineExt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

WebSearchEngineExt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

stdafx.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

stdafx.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it
@@ -76,6 +76,7 @@ WebSearchEngine. If not, see <http://www.opensource.org/licenses/gpl-3.0.html>*/
7676
#include <sstream>
7777
#include <iomanip>
7878
#include <algorithm>
79+
#include <filesystem>
7980

8081
#define REGKEY_SECTION _T("Settings")
8182
#define REGKEY_DBTYPE _T("dbtype")
@@ -100,6 +101,6 @@ WebSearchEngine. If not, see <http://www.opensource.org/licenses/gpl-3.0.html>*/
100101
#define ODBC_CHECK_RETURN_FALSE(nRet, handle) \
101102
handle.ValidateReturnValue(nRet); \
102103
if (!SQL_SUCCEEDED(nRet)) \
103-
{ \
104-
return false; \
105-
}
104+
{ \
105+
return false; \
106+
}

targetver.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2022-2024 Stefan-Mihai MOGA
1+
/* Copyright (C) 2022-2025 Stefan-Mihai MOGA
22
This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
33
44
WebSearchEngine is free software: you can redistribute it and/or modify it

x64/Release/WebSearchEngine.exe

-1 KB
Binary file not shown.

0 commit comments

Comments
 (0)