|
1 |
| -/* Copyright (C) 2022-2024 Stefan-Mihai MOGA |
| 1 | +/* Copyright (C) 2022-2025 Stefan-Mihai MOGA |
2 | 2 | This file is part of WebSearchEngine application developed by Stefan-Mihai MOGA.
|
3 | 3 |
|
4 | 4 | WebSearchEngine is free software: you can redistribute it and/or modify it
|
@@ -77,20 +77,46 @@ BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
|
77 | 77 | ON_WM_DESTROY()
|
78 | 78 | END_MESSAGE_MAP()
|
79 | 79 |
|
| 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 | + |
80 | 110 | BOOL CAboutDlg::OnInitDialog()
|
81 | 111 | {
|
82 | 112 | CDialog::OnInitDialog();
|
83 | 113 |
|
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; |
92 | 118 |
|
93 |
| - if (m_pVersionInfo.Load(lpszFullPath)) |
| 119 | + if (m_pVersionInfo.Load(strFullPath.GetString())) |
94 | 120 | {
|
95 | 121 | CString strName = m_pVersionInfo.GetProductName().c_str();
|
96 | 122 | CString strVersion = m_pVersionInfo.GetProductVersionAsString().c_str();
|
|
0 commit comments