Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into windivs8-dev
  • Loading branch information
errortek committed Oct 25, 2023
2 parents 279f8a9 + 6b35b77 commit 1b75f23
Show file tree
Hide file tree
Showing 41 changed files with 730 additions and 262 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ Enable this if the module uses typeid or dynamic_cast. You will probably need to
include(sdk/cmake/baseaddress_msvc.cmake)
endif()
else()
include(sdk/cmake/baseaddress.cmake)
if (ARCH STREQUAL "amd64")
include(sdk/cmake/baseaddress_gcc_x64.cmake)
else()
include(sdk/cmake/baseaddress.cmake)
endif()
endif()

# For MSVC builds, this puts all debug symbols file in the same directory.
Expand Down
9 changes: 8 additions & 1 deletion base/applications/mspaint/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ void ImageModel::ClearHistory()

void ImageModel::PushImageForUndo()
{
PushImageForUndo(CopyBitmap());
HBITMAP hbm = CopyBitmap();
if (hbm)
{
ShowOutOfMemory();
return;
}

PushImageForUndo(hbm);
}

void ImageModel::PushImageForUndo(HBITMAP hbm)
Expand Down
5 changes: 1 addition & 4 deletions base/applications/mspaint/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ CMainWindow mainWindow;

void ShowOutOfMemory(void)
{
WCHAR szTitle[64];
::LoadStringW(NULL, IDS_PROGRAMNAME, szTitle, _countof(szTitle));

WCHAR szText[256];
::FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
ERROR_OUTOFMEMORY,
0,
szText, _countof(szText),
NULL);
mainWindow.MessageBox(szText, szTitle, MB_ICONERROR);
mainWindow.MessageBox(szText, NULL, MB_ICONERROR);
}

// get file name extension from filter string
Expand Down
9 changes: 5 additions & 4 deletions base/applications/regedit/childwnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void SuggestKeys(HKEY hRootKey, LPCWSTR pszKeyPath, LPWSTR pszSuggestions
RegCloseKey(hOtherKey);

bFound = TRUE;
wcscpy(szLastFound, szBuffer);
StringCbCopyW(szLastFound, sizeof(szLastFound), szBuffer);
pszKeyPath = szLastFound;
}
}
Expand Down Expand Up @@ -258,10 +258,11 @@ UpdateAddress(HTREEITEM hItem, HKEY hRootKey, LPCWSTR pszPath, BOOL bSelectNone)
if (fullPath)
{
/* set (correct) the address bar text */
if (keyPath[0] != L'\0')
swprintf(fullPath, L"%s%s%s", rootName, keyPath[0]==L'\\'?L"":L"\\", keyPath);
if (keyPath[0] != UNICODE_NULL)
StringCbPrintfW(fullPath, cbFullPath, L"%s%s%s", rootName,
((keyPath[0] == L'\\') ? L"" : L"\\"), keyPath);
else
fullPath = wcscpy(fullPath, rootName);
StringCbCopyW(fullPath, cbFullPath, rootName);

SendMessageW(hStatusBar, SB_SETTEXTW, 0, (LPARAM)fullPath);
SendMessageW(g_pChildWnd->hAddressBarWnd, WM_SETTEXT, 0, (LPARAM)fullPath);
Expand Down
26 changes: 14 additions & 12 deletions base/applications/regedit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ void error(HWND hwnd, INT resId, ...)
hInstance = GetModuleHandle(0);

if (!LoadStringW(hInstance, IDS_ERROR, title, ARRAY_SIZE(title)))
wcscpy(title, L"Error");
StringCbCopyW(title, sizeof(title), L"Error");

if (!LoadStringW(hInstance, resId, errfmt, ARRAY_SIZE(errfmt)))
wcscpy(errfmt, L"Unknown error string!");
StringCbCopyW(errfmt, sizeof(errfmt), L"Unknown error string!");

va_start(ap, resId);
_vsnwprintf(errstr, ARRAY_SIZE(errstr), errfmt, ap);
Expand All @@ -66,7 +66,7 @@ static void error_code_messagebox(HWND hwnd, DWORD error_code)
{
WCHAR title[256];
if (!LoadStringW(hInst, IDS_ERROR, title, ARRAY_SIZE(title)))
wcscpy(title, L"Error");
StringCbCopyW(title, sizeof(title), L"Error");
ErrorMessageBox(hwnd, title, error_code);
}

Expand All @@ -81,13 +81,13 @@ void warning(HWND hwnd, INT resId, ...)
hInstance = GetModuleHandle(0);

if (!LoadStringW(hInstance, IDS_WARNING, title, ARRAY_SIZE(title)))
wcscpy(title, L"Warning");
StringCbCopyW(title, sizeof(title), L"Warning");

if (!LoadStringW(hInstance, resId, errfmt, ARRAY_SIZE(errfmt)))
wcscpy(errfmt, L"Unknown error string!");
StringCbCopyW(errfmt, sizeof(errfmt), L"Unknown error string!");

va_start(ap, resId);
_vsnwprintf(errstr, ARRAY_SIZE(errstr), errfmt, ap);
StringCbVPrintfW(errstr, sizeof(errstr), errfmt, ap);
va_end(ap);

MessageBoxW(hwnd, errstr, title, MB_OK | MB_ICONSTOP);
Expand Down Expand Up @@ -304,7 +304,7 @@ INT_PTR CALLBACK modify_dword_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP
SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, buffer);
}
CheckRadioButton (hwndDlg, IDC_FORMAT_HEX, IDC_FORMAT_DEC, IDC_FORMAT_HEX);
swprintf(ValueString, L"%lx", dwordValueData);
StringCbPrintfW(ValueString, sizeof(ValueString), L"%lx", dwordValueData);
SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, ValueString);
SendMessage(GetDlgItem(hwndDlg, IDC_VALUE_DATA), EM_SETSEL, 0, -1);
SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA));
Expand All @@ -327,7 +327,7 @@ INT_PTR CALLBACK modify_dword_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP
}
}
}
swprintf(ValueString, L"%lx", Value);
StringCbPrintfW(ValueString, sizeof(ValueString), L"%lx", Value);
SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, ValueString);
return TRUE;
}
Expand All @@ -347,7 +347,7 @@ INT_PTR CALLBACK modify_dword_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP
}
}
}
swprintf(ValueString, L"%lu", Value);
StringCbPrintfW(ValueString, sizeof(ValueString), L"%lu", Value);
SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, ValueString);
return TRUE;
}
Expand Down Expand Up @@ -1491,6 +1491,7 @@ LONG RenameKey(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpNewName)
LPCWSTR s;
LPWSTR lpNewSubKey = NULL;
LONG Ret = 0;
SIZE_T cbNewSubKey;

if (!lpSubKey)
return Ret;
Expand All @@ -1499,11 +1500,12 @@ LONG RenameKey(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpNewName)
if (s)
{
s++;
lpNewSubKey = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (s - lpSubKey + wcslen(lpNewName) + 1) * sizeof(WCHAR));
cbNewSubKey = (s - lpSubKey + wcslen(lpNewName) + 1) * sizeof(WCHAR);
lpNewSubKey = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, cbNewSubKey);
if (lpNewSubKey != NULL)
{
memcpy(lpNewSubKey, lpSubKey, (s - lpSubKey) * sizeof(WCHAR));
wcscpy(lpNewSubKey + (s - lpSubKey), lpNewName);
StringCbCopyNW(lpNewSubKey, cbNewSubKey, lpSubKey, (s - lpSubKey) * sizeof(WCHAR));
StringCbCatW(lpNewSubKey, cbNewSubKey, lpNewName);
lpNewName = lpNewSubKey;
}
else
Expand Down
21 changes: 10 additions & 11 deletions base/applications/regedit/find.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ BOOL RegFindRecurse(
if(wcslen(pszSubKey) >= _countof(szSubKey))
return FALSE;

wcscpy(szSubKey, pszSubKey);
StringCbCopyW(szSubKey, sizeof(szSubKey), pszSubKey);
hSubKey = NULL;

lResult = RegOpenKeyExW(hKey, szSubKey, 0, KEY_ALL_ACCESS, &hSubKey);
Expand Down Expand Up @@ -304,14 +304,14 @@ BOOL RegFindRecurse(
ppszFoundValueName))
{
LPWSTR psz = *ppszFoundSubKey;
*ppszFoundSubKey = malloc(
(wcslen(szSubKey) + wcslen(psz) + 2) * sizeof(WCHAR));
SIZE_T cbFoundSubKey = (wcslen(szSubKey) + wcslen(psz) + 2) * sizeof(WCHAR);
*ppszFoundSubKey = malloc(cbFoundSubKey);
if (*ppszFoundSubKey == NULL)
goto err;
if (szSubKey[0])
{
wcscpy(*ppszFoundSubKey, szSubKey);
wcscat(*ppszFoundSubKey, s_backslash);
StringCbCopyW(*ppszFoundSubKey, cbFoundSubKey, szSubKey);
StringCbCatW(*ppszFoundSubKey, cbFoundSubKey, s_backslash);
}
else
**ppszFoundSubKey = 0;
Expand Down Expand Up @@ -368,7 +368,7 @@ BOOL RegFindWalk(
ppszFoundValueName))
return TRUE;

wcscpy(szSubKey, pszSubKey);
StringCbCopyW(szSubKey, sizeof(szSubKey), pszSubKey);
while(szSubKey[0] != 0)
{
if (DoEvents())
Expand Down Expand Up @@ -460,15 +460,14 @@ BOOL RegFindWalk(
ppszFoundSubKey, ppszFoundValueName))
{
LPWSTR psz = *ppszFoundSubKey;
*ppszFoundSubKey = malloc(
(wcslen(szSubKey) + wcslen(psz) + 2) *
sizeof(WCHAR));
SIZE_T cbFoundSubKey = (wcslen(szSubKey) + wcslen(psz) + 2) * sizeof(WCHAR);
*ppszFoundSubKey = malloc(cbFoundSubKey);
if (*ppszFoundSubKey == NULL)
goto err;
if (szSubKey[0])
{
wcscpy(*ppszFoundSubKey, szSubKey);
wcscat(*ppszFoundSubKey, s_backslash);
StringCbCopyW(*ppszFoundSubKey, cbFoundSubKey, szSubKey);
StringCbCatW(*ppszFoundSubKey, cbFoundSubKey, s_backslash);
}
else
**ppszFoundSubKey = 0;
Expand Down
8 changes: 5 additions & 3 deletions base/applications/regedit/framewnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
WCHAR str[100];

wcscpy(str, L"");
str[0] = UNICODE_NULL;
if (nFlags & MF_POPUP)
{
if (hSysMenu != GetMenu(hWnd))
Expand Down Expand Up @@ -814,6 +814,7 @@ BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCWSTR keyName)
WCHAR szBuffer[512];
HGLOBAL hGlobal;
LPWSTR s;
SIZE_T cbGlobal;

if (!OpenClipboard(hWnd))
goto done;
Expand All @@ -825,12 +826,13 @@ BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCWSTR keyName)
if (!GetKeyName(szBuffer, ARRAY_SIZE(szBuffer), hRootKey, keyName))
goto done;

hGlobal = GlobalAlloc(GMEM_MOVEABLE, (wcslen(szBuffer) + 1) * sizeof(WCHAR));
cbGlobal = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
hGlobal = GlobalAlloc(GMEM_MOVEABLE, cbGlobal);
if (!hGlobal)
goto done;

s = GlobalLock(hGlobal);
wcscpy(s, szBuffer);
StringCbCopyW(s, cbGlobal, szBuffer);
GlobalUnlock(hGlobal);

SetClipboardData(CF_UNICODETEXT, hGlobal);
Expand Down
3 changes: 1 addition & 2 deletions base/applications/regedit/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,7 @@ CRegKeySecurity_fnConstructor(LPWSTR lpRegKey,
obj->ObjectInfo = *ObjectInfo;
obj->Btn = Btn;
obj->hRootKey = hRootKey;
wcscpy(obj->szRegKey,
lpRegKey);
StringCbCopyW(obj->szRegKey, sizeof(obj->szRegKey), lpRegKey);
}
else
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
Expand Down
5 changes: 3 additions & 2 deletions base/applications/regedit/txtproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ static WCHAR *
txt_build_subkey_path(LPCWSTR path, DWORD path_len, LPCWSTR subkey_name, DWORD subkey_len)
{
WCHAR *subkey_path;
subkey_path = malloc((path_len + subkey_len + 2) * sizeof(WCHAR));
swprintf(subkey_path, L"%s\\%s", path, subkey_name);
SIZE_T cb_subkey_path = (path_len + subkey_len + 2) * sizeof(WCHAR);
subkey_path = malloc(cb_subkey_path);
StringCbPrintfW(subkey_path, cb_subkey_path, L"%s\\%s", path, subkey_name);
return subkey_path;
}

Expand Down
3 changes: 3 additions & 0 deletions dll/cpl/desk/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,9 @@ DrawThemePreview(IN HDC hdcMem, IN PCOLOR_SCHEME scheme, IN PTHEME_SELECTION pSe
FillRect(hdcMem, prcWindow, hbrBack);
DeleteObject(hbrBack);

InflateRect(prcWindow, -8, -8);
prcWindow->bottom -= 12;

hres = DrawNCPreview(hdcMem,
DNCP_DRAW_ALL,
prcWindow,
Expand Down
53 changes: 22 additions & 31 deletions dll/cpl/hotplug/hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ ShowContextMenu(


static
DWORD
DEVINST
GetSelectedDeviceInst(
_In_ HWND hwndDeviceTree)
{
Expand All @@ -365,37 +365,11 @@ GetSelectedDeviceInst(
return item.lParam;
}

static
int
_DevicePropertiesW(
_In_ HWND hWndParent,
_In_ LPCWSTR lpMachineName,
_In_ LPCWSTR lpDeviceID,
_In_ BOOL bShowDevMgr)
{
typedef int (WINAPI *PFDEVICEPROPERTIESW)(HWND, LPCWSTR, LPCWSTR, BOOL);
HMODULE hDll;
PFDEVICEPROPERTIESW pFunc;
int ret = -1;

hDll = LoadLibraryW(L"devmgr.dll");
if (hDll == NULL)
return -1;

pFunc = (PFDEVICEPROPERTIESW)GetProcAddress(hDll, "DevicePropertiesW");
if (pFunc != NULL)
ret = pFunc(hWndParent, lpMachineName, lpDeviceID, bShowDevMgr);

FreeLibrary(hDll);

return ret;
}

static
VOID
ShowDeviceProperties(
_In_ HWND hwndParent,
_In_ DWORD DevInst)
_In_ DEVINST DevInst)
{
ULONG ulSize;
CONFIGRET cr;
Expand All @@ -405,13 +379,30 @@ ShowDeviceProperties(
if (cr != CR_SUCCESS || ulSize == 0)
return;

pszDevId = HeapAlloc(GetProcessHeap(), 0, (ulSize + 1) * sizeof(WCHAR));
/* Take the terminating NULL into account */
ulSize++;

pszDevId = HeapAlloc(GetProcessHeap(), 0, ulSize * sizeof(WCHAR));
if (pszDevId == NULL)
return;

cr = CM_Get_Device_IDW(DevInst, pszDevId, ulSize + 1, 0);
cr = CM_Get_Device_IDW(DevInst, pszDevId, ulSize, 0);
if (cr == CR_SUCCESS)
_DevicePropertiesW(hwndParent, NULL, pszDevId, FALSE);
{
typedef int (WINAPI *PFDEVICEPROPERTIESW)(HWND, LPCWSTR, LPCWSTR, BOOL);
HMODULE hDevMgrDll;
PFDEVICEPROPERTIESW pDevicePropertiesW;

hDevMgrDll = LoadLibraryW(L"devmgr.dll");
if (hDevMgrDll != NULL)
{
pDevicePropertiesW = (PFDEVICEPROPERTIESW)GetProcAddress(hDevMgrDll, "DevicePropertiesW");
if (pDevicePropertiesW != NULL)
pDevicePropertiesW(hwndParent, NULL, pszDevId, FALSE);

FreeLibrary(hDevMgrDll);
}
}

HeapFree(GetProcessHeap(), 0, pszDevId);
}
Expand Down
Loading

0 comments on commit 1b75f23

Please sign in to comment.