ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
January 2008
----- 2025 -----
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
24 participants
539 discussions
Start a n
N
ew thread
[janderwald] 31548: - revert changes which shouldnt be in (yet)
by janderwald@svn.reactos.org
Author: janderwald Date: Wed Jan 2 02:42:01 2008 New Revision: 31548 URL:
http://svn.reactos.org/svn/reactos?rev=31548&view=rev
Log: - revert changes which shouldnt be in (yet) Removed: trunk/reactos/dll/win32/shell32/shv_default_context_menu.c Modified: trunk/reactos/dll/win32/shell32/shv_item_cmenu.c Removed: trunk/reactos/dll/win32/shell32/shv_default_context_menu.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shv_defa…
============================================================================== --- trunk/reactos/dll/win32/shell32/shv_default_context_menu.c (original) +++ trunk/reactos/dll/win32/shell32/shv_default_context_menu.c (removed) @@ -1,1246 +1,0 @@ -/* - * PROJECT: shell32 - * LICENSE: GPL - See COPYING in the top level directory - * FILE: dll/win32/shell32/shv_item_new.c - * PURPOSE: provides default context menu implementation - * PROGRAMMERS: Johannes Anderwald (janderwald(a)reactos.org) - */ - -#include <string.h> - -#define COBJMACROS -#define NONAMELESSUNION -#define NONAMELESSSTRUCT -#define YDEBUG -#include "winerror.h" -#include "wine/debug.h" - -#include "windef.h" -#include "wingdi.h" -#include "pidl.h" -#include "undocshell.h" -#include "shlobj.h" -#include "objbase.h" - -#include "shlwapi.h" -#include "shell32_main.h" -#include "shellfolder.h" -#include "debughlp.h" -#include "shresdef.h" -#include "shlguid.h" - -WINE_DEFAULT_DEBUG_CHANNEL(dmenu); - -typedef struct _DynamicShellEntry_ -{ - UINT iIdCmdFirst; - UINT NumIds; - IContextMenu * CMenu; - struct _DynamicShellEntry_ * Next; -}DynamicShellEntry, *PDynamicShellEntry; - -typedef struct _StaticShellEntry_ -{ - LPWSTR szVerb; - LPWSTR szClass; - struct _StaticShellEntry_ * Next; -}StaticShellEntry, *PStaticShellEntry; - - -typedef struct -{ - const IContextMenu2Vtbl *lpVtbl; - LONG ref; - DEFCONTEXTMENU dcm; - IDataObject * pDataObj; - DWORD bGroupPolicyActive; - PDynamicShellEntry dhead; /* first dynamic shell extension entry */ - UINT iIdSHEFirst; /* first used id */ - UINT iIdSHELast; /* last used id */ - PStaticShellEntry shead; /* first static shell extension entry */ - UINT iIdSCMFirst; /* first static used id */ - UINT iIdSCMLast; /* last static used id */ -}IDefaultContextMenuImpl; - -static inline IDefaultContextMenuImpl *impl_from_IContextMenu( IContextMenu2 *iface ) -{ - return (IDefaultContextMenuImpl *)((char*)iface - FIELD_OFFSET(IDefaultContextMenuImpl, lpVtbl)); -} - -static -HRESULT -WINAPI -IDefaultContextMenu_fnQueryInterface( - IContextMenu2 *iface, - REFIID riid, - LPVOID *ppvObj) -{ - IDefaultContextMenuImpl *This = (IDefaultContextMenuImpl *)iface; - - TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj); - - *ppvObj = NULL; - - if(IsEqualIID(riid, &IID_IUnknown) || - IsEqualIID(riid, &IID_IContextMenu) || - IsEqualIID(riid, &IID_IContextMenu2)) - { - *ppvObj = This; - } - - if(*ppvObj) - { - IUnknown_AddRef((IUnknown*)*ppvObj); - TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj); - return S_OK; - } - TRACE("-- Interface: E_NOINTERFACE\n"); - return E_NOINTERFACE; -} - - -static -ULONG -WINAPI -IDefaultContextMenu_fnAddRef( - IContextMenu2 *iface) -{ - IDefaultContextMenuImpl *This = (IDefaultContextMenuImpl *)iface; - ULONG refCount = InterlockedIncrement(&This->ref); - - TRACE("(%p)->(count=%u)\n", This, refCount - 1); - - return refCount; -} - -static -ULONG -WINAPI -IDefaultContextMenu_fnRelease( - IContextMenu2 *iface) -{ - IDefaultContextMenuImpl *This = (IDefaultContextMenuImpl *)iface; - ULONG refCount = InterlockedDecrement(&This->ref); - - TRACE("(%p)->(count=%u)\n", This, refCount + 1); - if (!refCount) - { - TRACE(" destroying IContextMenu(%p)\n",This); - - HeapFree(GetProcessHeap(),0,This); - } - - return refCount; -} - -static -void -SH_AddStaticEntry(IDefaultContextMenuImpl * This, HKEY hKey, WCHAR *szVerb, WCHAR * szClass) -{ - PStaticShellEntry curEntry; - PStaticShellEntry lastEntry = NULL; - - curEntry = This->shead; - - while(curEntry) - { - if (!wcsicmp(curEntry->szVerb, szVerb)) - { - /* entry already exists */ - return; - } - lastEntry = curEntry; - curEntry = curEntry->Next; - } - - TRACE("adding verb %s szClass %s\n", debugstr_w(szVerb), debugstr_w(szClass)); - - curEntry = malloc(sizeof(StaticShellEntry)); - if (curEntry) - { - curEntry->Next = NULL; - curEntry->szVerb = wcsdup(szVerb); - curEntry->szClass = wcsdup(szClass); - } - - if (lastEntry) - { - lastEntry->Next = curEntry; - } - else - { - This->shead = curEntry; - } -} - -static -void -SH_AddStaticEntryForKey(IDefaultContextMenuImpl * This, HKEY hKey, WCHAR * szClass) -{ - LONG result; - DWORD dwIndex; - WCHAR szName[40]; - DWORD dwName; - - dwIndex = 0; - do - { - szName[0] = 0; - dwName = sizeof(szName) / sizeof(WCHAR); - result = RegEnumKeyExW(hKey, dwIndex, szName, &dwName, NULL, NULL, NULL, NULL); - szName[39] = 0; - if (result == ERROR_SUCCESS) - { - SH_AddStaticEntry(This, hKey, szName, szClass); - } - dwIndex++; - }while(result == ERROR_SUCCESS); -} - -static -void -SH_AddStaticEntryForFileClass(IDefaultContextMenuImpl * This, WCHAR * szExt) -{ - WCHAR szBuffer[100]; - HKEY hKey; - LONG result; - DWORD dwBuffer; - - TRACE("SH_AddStaticEntryForFileClass entered with %s\n", debugstr_w(szExt)); - - wcscpy(szBuffer, szExt); - wcscat(szBuffer, L"\\shell"); - result = RegOpenKeyExW(HKEY_CLASSES_ROOT, szBuffer, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); - if (result == ERROR_SUCCESS) - { - SH_AddStaticEntryForKey(This, hKey, szExt); - RegCloseKey(hKey); - } - - dwBuffer = sizeof(szBuffer); - result = RegGetValueW(HKEY_CLASSES_ROOT, szExt, NULL, RRF_RT_REG_SZ, NULL, (LPBYTE)szBuffer, &dwBuffer); - if (result == ERROR_SUCCESS) - { - UINT length = strlenW(szBuffer); - wcscat(szBuffer, L"\\shell"); - TRACE("szBuffer %s\n", debugstr_w(szBuffer)); - - result = RegOpenKeyExW(HKEY_CLASSES_ROOT, szBuffer, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); - if (result == ERROR_SUCCESS) - { - szBuffer[length] = 0; - SH_AddStaticEntryForKey(This, hKey, szBuffer); - RegCloseKey(hKey); - } - } - - strcpyW(szBuffer, "SystemFileAssociations\\"); - dwBuffer = sizeof(szBuffer) - strlenW(szBuffer) * sizeof(WCHAR); - result = RegGetValueW(HKEY_CLASSES_ROOT, szExt, L"PerceivedType", RRF_RT_REG_SZ, NULL, (LPBYTE)&szBuffer[23], &dwBuffer); - if (result == ERROR_SUCCESS) - { - UINT length = strlenW(szBuffer); - wcscat(szBuffer, L"\\shell"); - TRACE("szBuffer %s\n", debugstr_w(szBuffer)); - - result = RegOpenKeyExW(HKEY_CLASSES_ROOT, szBuffer, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); - if (result == ERROR_SUCCESS) - { - szBuffer[length] = 0; - SH_AddStaticEntryForKey(This, hKey, szBuffer); - RegCloseKey(hKey); - } - } - RegCloseKey(hKey); -} - -static -BOOL -HasClipboardData() -{ - BOOL ret = FALSE; - IDataObject * pda; - - if(SUCCEEDED(OleGetClipboard(&pda))) - { - STGMEDIUM medium; - FORMATETC formatetc; - - TRACE("pda=%p\n", pda); - - /* Set the FORMATETC structure*/ - InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL); - if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium))) - { - ret = TRUE; - } - - IDataObject_Release(pda); - ReleaseStgMedium(&medium); - } - - return ret; -} - -VOID -DisablePasteOptions(HMENU hMenu) -{ - MENUITEMINFOW mii; - - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STATE; - mii.fState = MFS_DISABLED; - - TRACE("result %d\n", SetMenuItemInfoW(hMenu, FCIDM_SHVIEW_INSERT, FALSE, &mii)); - TRACE("result %d\n", SetMenuItemInfoW(hMenu, FCIDM_SHVIEW_INSERTLINK, FALSE, &mii)); -} - -static -HRESULT -SH_LoadDynamicContextMenuHandler(IDefaultContextMenuImpl * This, HKEY hKey, const CLSID * szClass, BOOL bExternalInit) -{ - HRESULT hr; - IContextMenu * cmobj; - IShellExtInit *shext; - PDynamicShellEntry curEntry; - TRACE("SH_LoadDynamicContextMenuHandler entered with This %p hKey %p szClass %s bExternalInit %u\n",This, hKey, wine_dbgstr_guid(szClass), bExternalInit); - - hr = SHCoCreateInstance(NULL, szClass, NULL, &IID_IContextMenu, (void**)&cmobj); - if (hr != S_OK) - { - TRACE("SHCoCreateInstance failed %x\n", GetLastError()); - return hr; - } - - if (bExternalInit) - { - hr = cmobj->lpVtbl->QueryInterface(cmobj, &IID_IShellExtInit, (void**)&shext); - if (hr != S_OK) - { - TRACE("Failed to query for interface IID_IShellExtInit\n"); - cmobj->lpVtbl->Release(cmobj); - return FALSE; - } - hr = shext->lpVtbl->Initialize(shext, NULL, This->pDataObj, hKey); - shext->lpVtbl->Release(shext); - if (hr != S_OK) - { - TRACE("Failed to initialize shell extension error %x\n", hr); - cmobj->lpVtbl->Release(cmobj); - return hr; - } - } - - curEntry = malloc(sizeof(DynamicShellEntry)); - if(!curEntry) - { - return E_OUTOFMEMORY; - } - - curEntry->iIdCmdFirst = 0; - curEntry->Next = NULL; - curEntry->NumIds = 0; - curEntry->CMenu = cmobj; - - if (This->dhead) - { - PDynamicShellEntry pEntry = This->dhead; - - while(pEntry->Next) - { - pEntry = pEntry->Next; - } - - pEntry->Next = curEntry; - } - else - { - This->dhead = curEntry; - } - - return hr; -} - -static -UINT -EnumerateDynamicContextHandlerForKey(IDefaultContextMenuImpl *This, HKEY hRootKey) -{ - WCHAR szKey[MAX_PATH] = {0}; - WCHAR szName[MAX_PATH] = {0}; - DWORD dwIndex, dwName; - LONG res; - HRESULT hResult; - UINT index; - CLSID clsid; - HKEY hKey; - - static const WCHAR szShellEx[] = { 's','h','e','l','l','e','x','\\','C','o','n','t','e','x','t','M','e','n','u','H','a','n','d','l','e','r','s',0 }; - - if (RegOpenKeyExW(hRootKey, szShellEx, 0, KEY_READ, &hKey) != ERROR_SUCCESS) - { - TRACE("RegOpenKeyExW failed for key %s\n", debugstr_w(szKey)); - return 0; - } - - dwIndex = 0; - index = 0; - do - { - dwName = MAX_PATH; - res = RegEnumKeyExW(hKey, dwIndex, szName, &dwName, NULL, NULL, NULL, NULL); - if (res == ERROR_SUCCESS) - { - hResult = CLSIDFromString(szName, &clsid); - if (hResult != S_OK) - { - dwName = MAX_PATH; - if (RegGetValueW(hKey, szName, NULL, RRF_RT_REG_SZ, NULL, szKey, &dwName) == ERROR_SUCCESS) - { - if (CLSIDFromString(szKey, &clsid) == S_OK) - { - if (This->bGroupPolicyActive) - { - if (RegGetValueW(HKEY_LOCAL_MACHINE, - L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", - szKey, - RRF_RT_REG_SZ, - NULL, - NULL, - &dwName) == ERROR_SUCCESS) - { - SH_LoadDynamicContextMenuHandler(This, hKey, &clsid, TRUE); - } - - } - else - { - SH_LoadDynamicContextMenuHandler(This, hKey, &clsid, TRUE); - } - } - } - } - if (hResult == S_OK) - { - if (This->bGroupPolicyActive) - { - if (RegGetValueW(HKEY_LOCAL_MACHINE, - L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", - szKey, - RRF_RT_REG_SZ, - NULL, - NULL, - &dwName) == ERROR_SUCCESS) - { - SH_LoadDynamicContextMenuHandler(This, hKey, &clsid, TRUE); - } - } - else - { - SH_LoadDynamicContextMenuHandler(This, hKey, &clsid, TRUE); - } - } - } - dwIndex++; - }while(res == ERROR_SUCCESS); - - RegCloseKey(hKey); - return index; -} - - -static -UINT -InsertMenuItemsOfDynamicContextMenuExtension(IDefaultContextMenuImpl * This, HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast) -{ - PDynamicShellEntry curEntry; - HRESULT hResult; - MENUITEMINFOW mii; - if (!This->dhead) - { - This->iIdSHEFirst = 0; - This->iIdSHELast = 0; - return indexMenu; - } - - curEntry = This->dhead; - This->iIdSHEFirst = idCmdFirst; - - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_FTYPE | MIIM_STATE; - mii.fType = MFT_SEPARATOR; - mii.fState = MFS_ENABLED; - InsertMenuItemW(hMenu, indexMenu++, TRUE, &mii); - - do - { - hResult = IContextMenu_QueryContextMenu(curEntry->CMenu, hMenu, indexMenu, idCmdFirst, idCmdLast, CMF_NORMAL); - if (SUCCEEDED(hResult)) - { - curEntry->iIdCmdFirst = idCmdFirst; - curEntry->NumIds = LOWORD(hResult); - indexMenu += curEntry->NumIds; - idCmdFirst += curEntry->NumIds + 0x10; - } - TRACE("curEntry %p hresult %x contextmenu %p cmdfirst %x num ids %x\n", curEntry, hResult, curEntry->CMenu, curEntry->iIdCmdFirst, curEntry->NumIds); - curEntry = curEntry->Next; - }while(curEntry); - - This->iIdSHELast = idCmdFirst; - TRACE("SH_LoadContextMenuHandlers first %x last %x\n", This->iIdSHEFirst, This->iIdSHELast); - return indexMenu; -} - -UINT -BuildBackgroundContextMenu( - IDefaultContextMenuImpl * This, - HMENU hMenu, - UINT iIdCmdFirst, - UINT iIdCmdLast, - UINT uFlags) -{ - MENUITEMINFOW mii; - WCHAR szBuffer[MAX_PATH]; - UINT indexMenu = 0; - HMENU hSubMenu; - HKEY hKey; - - ZeroMemory(&mii, sizeof(mii)); - - TRACE("BuildBackgroundContextMenu entered\n"); - - if (!_ILIsDesktop(This->dcm.pidlFolder)) - { - /* view option is only available in browsing mode */ - hSubMenu = LoadMenuA(shell32_hInstance, "MENU_001"); - if (hSubMenu) - { - szBuffer[0] = 0; - LoadStringW(shell32_hInstance, FCIDM_SHVIEW_VIEW, szBuffer, MAX_PATH); - szBuffer[MAX_PATH-1] = 0; - - TRACE("szBuffer %s\n", debugstr_w(szBuffer)); - - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_TYPE | MIIM_STATE | MIIM_SUBMENU | MIIM_ID; - mii.fType = MFT_STRING; - mii.wID = iIdCmdFirst++; - mii.dwTypeData = szBuffer; - mii.cch = strlenW( mii.dwTypeData ); - mii.fState = MFS_ENABLED; - mii.hSubMenu = hSubMenu; - InsertMenuItemW(hMenu, indexMenu++, TRUE, &mii); - DestroyMenu(hSubMenu); - } - } - hSubMenu = LoadMenuA(shell32_hInstance, "MENU_002"); - if (hSubMenu) - { - /* merge general background context menu in */ - iIdCmdFirst = Shell_MergeMenus(hMenu, hSubMenu, indexMenu, 0, iIdCmdLast, MM_DONTREMOVESEPS | MM_SUBMENUSHAVEIDS) + 1; - DestroyMenu(hSubMenu); - } - - if (!HasClipboardData()) - { - TRACE("disabling paste options\n"); - DisablePasteOptions(hMenu); - } - /* load extensions from HKCR\* key */ - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, - L"*", - 0, - KEY_READ, - &hKey) == ERROR_SUCCESS) - { - EnumerateDynamicContextHandlerForKey(This, hKey); - RegCloseKey(hKey); - } - - /* load create new shell extension */ - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, - L"CLSID\\{D969A300-E7FF-11d0-A93B-00A0C90F2719}", - 0, - KEY_READ, - &hKey) == ERROR_SUCCESS) - { - static const GUID dummy1 = {0xD969A300, 0xE7FF, 0x11d0, {0xA9, 0x3B, 0x00, 0xA0, 0xC9, 0x0F, 0x27, 0x19} }; - SH_LoadDynamicContextMenuHandler(This, hKey, &dummy1, FALSE); - RegCloseKey(hKey); - } - - InsertMenuItemsOfDynamicContextMenuExtension(This, hMenu, GetMenuItemCount(hMenu), iIdCmdFirst, iIdCmdLast); - return iIdCmdLast; -} - -static -UINT -AddStaticContextMenusToMenu( - HMENU hMenu, - UINT indexMenu, - IDefaultContextMenuImpl * This) -{ - MENUITEMINFOW mii; - PStaticShellEntry curEntry; - - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE | MIIM_DATA; - mii.fType = MFT_STRING; - mii.fState = MFS_ENABLED | MFS_DEFAULT; - mii.wID = 0x4000; - This->iIdSCMFirst = mii.wID; - - curEntry = This->shead; - - while(curEntry) - { - /* FIXME - * load localized verbs if its an open edit find print printto openas properties verb - */ - - mii.dwTypeData = curEntry->szVerb; - mii.cch = strlenW(mii.dwTypeData); - InsertMenuItemW(hMenu, indexMenu++, TRUE, &mii); - mii.fState = MFS_ENABLED; - mii.wID++; - curEntry = curEntry->Next; - } - This->iIdSCMLast = mii.wID - 1; - return indexMenu; -} - -static -const char * -GetLocalizedString( - HMENU hMenu, - UINT wID, - char * sResult) -{ - MENUITEMINFOA mii; - - sResult[0] = 0; - if (!hMenu) - { - return sResult; - } - - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_TYPE; - mii.fType = MFT_STRING; - mii.dwTypeData = sResult; - mii.cch = 100; - - GetMenuItemInfoA(hMenu, wID, FALSE, &mii); - return sResult; -} -#if 0 -UINT -BuildControlPanelContextMenu( - IDefaultContextMenuImpl * This, - HMENU hMenu, - UINT iIdCmdFirst, - UINT iIdCmdLast) -{ - GUID * guid; - SFGAOF attributes; - DWORD dwSize; - UINT indexMenu = 0; - LPOLESTR pwszCLSID; - WCHAR szClass[80]; - UINT length; - MENUITEMINFOW mii; - - - ZeroMemory(&mii, sizeof(MENUITEMINFOW)); - - mii.cbSize = sizeof(MENUITEMINFOW); - mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID; - mii.fType = MFT_STRING; - mii.fState = MFS_ENABLED; - - guid = _ILGetGUIDPointer(This->dcm.apidl[0]); - if (guid) - { - /* the cpl is registered as a namespace extension */ - dwSize = sizeof(SFGAOF); - wcscpy(szClass, L"CLSID\\"); - if (SUCCEEDED(StringFromCLSID(guid, &pwszCLSID))) - { - wcscpy(&szClass[6], pwszCLSID); - length = strlenW(szClass); - - CoTaskMemFree(pwszCLSID); - - /* check if the CLSID is a folder */ - wcscat(szClass, L"\\ShellFolder"); - - if (RegGetValueW(HKEY_CLASSES_ROOT, szClass, L"Attributes", RRF_RT_REG_BINARY, NULL, &attributes, &dwSize) == ERROR_SUCCESS) - { - if (attributes & SFGAO_FOLDER) - { - WCHAR szBuffer[100]; - /* insert explore string */ - LoadStringW(shell32_hInstance, FCIDM_SHVIEW_EXPLORE, szBuffer, sizeof(szBuffer) / sizeof(WCHAR)); - szBuffer[99] = 0; - mii.wID = FCIDM_SHVIEW_EXPLORE; - mii.dwTypeData = szBuffer; - mii.fState |= MFS_DEFAULT; - InsertMenuItem(hMenu, indexMenu++, TRUE, &mii); - mii.fState = MFS_ENABLED; - } - } - - /* add static handlers*/ - szClass[length] = 0; - SH_AddStaticEntryForFileClass(This, szClass); - indexMenu = AddStaticContextMenusToMenu(hMenu, indexMenu, This); - } - } - else - { - /* cpl is registered with full path */ - SH_AddStaticEntryForFileClass(This, L".cpl"); - } - - if (AppendMenu(hMenu, MF_SEPARATOR, -1, NULL)) - { - LoadStringW(shell32_hInstance, FCIDM_SHVIEW_CREATELINK, szClass, sizeof(szClass) / sizeof(WCHAR)); - szClass[79] = 0; - InsertMenuItem(hMenu, indexMenu++, TRUE, &mii); - } -} -#endif - -UINT -BuildShellItemContextMenu( - IDefaultContextMenuImpl * This, - HMENU hMenu, - UINT iIdCmdFirst, - UINT iIdCmdLast, - UINT uFlags) -{ - WCHAR szExt[10]; - char sBuffer[100]; - HKEY hKey; - UINT indexMenu; - SFGAOF rfg; - HRESULT hr; - BOOL bAddSep; - HMENU hLocalMenu; - GUID * guid; - - TRACE("BuildShellItemContextMenu entered\n"); - - if (_ILGetExtension(This->dcm.apidl[0], &sBuffer[1], sizeof(sBuffer))) - { - sBuffer[9] = 0; - sBuffer[0] = '.'; - - if (MultiByteToWideChar( CP_ACP, 0, sBuffer, -1, (LPWSTR)szExt, 10)) - { - TRACE("szExt %d\n", debugstr_w(szExt)); - SH_AddStaticEntryForFileClass(This, szExt); - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szExt, 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { - EnumerateDynamicContextHandlerForKey(This, hKey); - RegCloseKey(hKey); - } - } - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"*", 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { - /* load default extensions */ - EnumerateDynamicContextHandlerForKey(This, hKey); - RegCloseKey(hKey); - } - } - - if (!_ILIsPidlSimple(This->dcm.apidl[0])|| _ILIsFolder(This->dcm.apidl[0])) - { - /* add the default verbs open / explore */ - SH_AddStaticEntryForFileClass(This, L"Folder"); - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Folder", 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { - EnumerateDynamicContextHandlerForKey(This, hKey); - RegCloseKey(hKey); - } - } - - guid = _ILGetGUIDPointer(This->dcm.apidl[0]); - if (guid) - { - LPOLESTR pwszCLSID; - WCHAR buffer[60]; - - wcscpy(buffer, L"CLSID\\"); - hr = StringFromCLSID(guid, &pwszCLSID); - if (hr == S_OK) - { - wcscpy(&buffer[6], pwszCLSID); - TRACE("buffer %s\n", debugstr_w(buffer)); - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, buffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { - EnumerateDynamicContextHandlerForKey(This, hKey); - SH_AddStaticEntryForFileClass(This, buffer); - RegCloseKey(hKey); - } - CoTaskMemFree(pwszCLSID); - } - } - - - if (_ILIsDrive(This->dcm.apidl[0])) - { - SH_AddStaticEntryForFileClass(This, L"Drive"); - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Drive", 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { - EnumerateDynamicContextHandlerForKey(This, hKey); - RegCloseKey(hKey); - } - } - - - /* add static actions */ - rfg = SFGAO_BROWSABLE | SFGAO_CANCOPY | SFGAO_CANLINK | SFGAO_CANMOVE | SFGAO_CANDELETE | SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_FILESYSTEM; - hr = IShellFolder_GetAttributesOf(This->dcm.psf, This->dcm.cidl, This->dcm.apidl, &rfg); - if (!SUCCEEDED(hr)) - rfg = 0; - - if (rfg & SFGAO_FILESYSTEM) - { - if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"AllFilesystemObjects", 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { - /* sendto service is registered there */ - EnumerateDynamicContextHandlerForKey(This, hKey); - RegCloseKey(hKey); - } - } - - /* add static context menu handlers */ - indexMenu = AddStaticContextMenusToMenu(hMenu, 0, This); - /* now process dynamic context menu handlers */ - indexMenu = InsertMenuItemsOfDynamicContextMenuExtension(This, hMenu, indexMenu, iIdCmdFirst, iIdCmdLast); - TRACE("indexMenu %d\n", indexMenu); - - hLocalMenu = LoadMenuW(shell32_hInstance, L"MENU_SHV_FILE"); - if (!hLocalMenu) - { - return iIdCmdLast; - } - - if (rfg & (SFGAO_CANCOPY | SFGAO_CANMOVE)) - { - _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); - if (rfg & SFGAO_CANMOVE) - _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_CUT, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_CUT, sBuffer), MFS_ENABLED); - if (rfg & SFGAO_CANCOPY) - _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_COPY, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_COPY, sBuffer), MFS_ENABLED); - } - - bAddSep = TRUE; - if (rfg & SFGAO_CANLINK) - { - bAddSep = FALSE; - _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); - _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_CREATELINK, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_CREATELINK, sBuffer), MFS_ENABLED); - } - - - if (rfg & SFGAO_CANDELETE) - { - if (bAddSep) - { - bAddSep = FALSE; - _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); - } - _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_DELETE, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_DELETE, sBuffer), MFS_ENABLED); - } - - if (rfg & SFGAO_CANRENAME) - { - if (bAddSep) - { - bAddSep = FALSE; - _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); - } - _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_RENAME, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_RENAME, sBuffer), MFS_ENABLED); - } - - _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); - _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_PROPERTIES, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_PROPERTIES, sBuffer), MFS_ENABLED); - - DestroyMenu(hLocalMenu); - return iIdCmdLast; -} - -static -HRESULT -WINAPI -IDefaultContextMenu_fnQueryContextMenu( - IContextMenu2 *iface, - HMENU hmenu, - UINT indexMenu, - UINT idCmdFirst, - UINT idCmdLast, - UINT uFlags) -{ - IDefaultContextMenuImpl * This = impl_from_IContextMenu(iface); - - if (This->dcm.cidl) - { - idCmdFirst = BuildShellItemContextMenu(This, hmenu, idCmdFirst, idCmdLast, uFlags); - } - else - { - idCmdFirst = BuildBackgroundContextMenu(This, hmenu, idCmdFirst, idCmdLast, uFlags); - } - - return S_OK; -} - -static -HRESULT -NotifyShellViewWindow(LPCMINVOKECOMMANDINFO lpcmi) -{ - LPSHELLBROWSER lpSB; - LPSHELLVIEW lpSV = NULL; - HWND hwndSV = NULL; - - if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0))) - { - if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV))) - { - IShellView_GetWindow(lpSV, &hwndSV); - } - } - - if (LOWORD(lpcmi->lpVerb) == FCIDM_SHVIEW_REFRESH) - { - if (lpSV) - IShellView_Refresh(lpSV); - - return S_OK; - } - - SendMessageW(hwndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0), 0); - - return S_OK; -} - -static -HRESULT -DoPaste( - IDefaultContextMenuImpl *iface, - LPCMINVOKECOMMANDINFO lpcmi) -{ - - - return E_FAIL; -} - -static -HRESULT -DoOpenOrExplore( - IDefaultContextMenuImpl *iface, - LPCMINVOKECOMMANDINFO lpcmi) -{ - - - return E_FAIL; -} - -static -HRESULT -DoCopyOrCut( - IDefaultContextMenuImpl *iface, - LPCMINVOKECOMMANDINFO lpcmi) -{ - - - return E_FAIL; -} - -static -HRESULT -DoCreateLink( - IDefaultContextMenuImpl *iface) -{ - - - return E_FAIL; -} - -static -HRESULT -DoDelete( - IDefaultContextMenuImpl *iface) -{ - - - return E_FAIL; -} - -static -HRESULT -DoRename( - IDefaultContextMenuImpl *iface) -{ - - - return E_FAIL; -} - -static -HRESULT -DoProperties( - IDefaultContextMenuImpl *iface, - LPCMINVOKECOMMANDINFO lpcmi) -{ - - - return E_FAIL; -} - -static -HRESULT -DoDynamicShellExtensions( - IDefaultContextMenuImpl *iface, - LPCMINVOKECOMMANDINFO lpcmi) -{ - - - return E_FAIL; -} - - -static -HRESULT -DoStaticShellExtensions( - IDefaultContextMenuImpl *This, - LPCMINVOKECOMMANDINFO lpcmi) -{ - SHELLEXECUTEINFOW sei; - PStaticShellEntry pCurrent = This->shead; - int verb = LOWORD(lpcmi->lpVerb) - This->iIdSCMFirst; - - - while(pCurrent && verb-- > 0) - pCurrent = pCurrent->Next; - - if (verb > 0) - return E_FAIL; - - - ZeroMemory(&sei, sizeof(sei)); - sei.cbSize = sizeof(sei); - sei.fMask = SEE_MASK_CLASSNAME; - sei.lpClass = pCurrent->szClass; - sei.hwnd = lpcmi->hwnd; - sei.nShow = SW_SHOWNORMAL; - sei.lpVerb = pCurrent->szVerb; - ShellExecuteExW(&sei); - return S_OK; - - -} - -static -HRESULT -WINAPI -IDefaultContextMenu_fnInvokeCommand( - IContextMenu2 *iface, - LPCMINVOKECOMMANDINFO lpcmi) -{ - IDefaultContextMenuImpl * This = impl_from_IContextMenu(iface); - - switch(LOWORD(lpcmi->lpVerb)) - { - case FCIDM_SHVIEW_BIGICON: - case FCIDM_SHVIEW_SMALLICON: - case FCIDM_SHVIEW_LISTVIEW: - case FCIDM_SHVIEW_REPORTVIEW: - case 0x30: /* FIX IDS in resource files */ - case 0x31: - case 0x32: - case 0x33: - case FCIDM_SHVIEW_AUTOARRANGE: - case FCIDM_SHVIEW_SNAPTOGRID: - case FCIDM_SHVIEW_REFRESH: - return NotifyShellViewWindow(lpcmi); - case FCIDM_SHVIEW_INSERT: - case FCIDM_SHVIEW_INSERTLINK: - return DoPaste(This, lpcmi); - case FCIDM_SHVIEW_OPEN: - case FCIDM_SHVIEW_EXPLORE: - return DoOpenOrExplore(This, lpcmi); - case FCIDM_SHVIEW_COPY: - case FCIDM_SHVIEW_CUT: - return DoCopyOrCut(This, lpcmi); - case FCIDM_SHVIEW_CREATELINK: - return DoCreateLink(This); - case FCIDM_SHVIEW_DELETE: - return DoDelete(This); - case FCIDM_SHVIEW_RENAME: - return DoRename(This); - case FCIDM_SHVIEW_PROPERTIES: - return DoProperties(This, lpcmi); - } - - if (This->iIdSHEFirst && This->iIdSHELast) - { - if (LOWORD(lpcmi->lpVerb) >= This->iIdSHEFirst && LOWORD(lpcmi->lpVerb) <= This->iIdSHELast) - { - return DoDynamicShellExtensions(This, lpcmi); - } - } - - if (This->iIdSCMFirst && This->iIdSCMLast) - { - if (LOWORD(lpcmi->lpVerb) >= This->iIdSCMFirst && LOWORD(lpcmi->lpVerb) <= This->iIdSCMLast) - { - return DoStaticShellExtensions(This, lpcmi); - } - } - - FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi->lpVerb)); - return E_UNEXPECTED; -} - -static -HRESULT -WINAPI -IDefaultContextMenu_fnGetCommandString( - IContextMenu2 *iface, - UINT_PTR idCommand, - UINT uFlags, - UINT* lpReserved, - LPSTR lpszName, - UINT uMaxNameLen) -{ - - return S_OK; -} - -static -HRESULT -WINAPI -IDefaultContextMenu_fnHandleMenuMsg( - IContextMenu2 *iface, - UINT uMsg, - WPARAM wParam, - LPARAM lParam) -{ - - return S_OK; -} - -static const IContextMenu2Vtbl cmvt = -{ - IDefaultContextMenu_fnQueryInterface, - IDefaultContextMenu_fnAddRef, - IDefaultContextMenu_fnRelease, - IDefaultContextMenu_fnQueryContextMenu, - IDefaultContextMenu_fnInvokeCommand, - IDefaultContextMenu_fnGetCommandString, - IDefaultContextMenu_fnHandleMenuMsg -}; - -static -HRESULT -IDefaultContextMenu_Constructor( - const DEFCONTEXTMENU *pdcm, - REFIID riid, - void **ppv) -{ - IDefaultContextMenuImpl * This; - HRESULT hr = E_FAIL; - IDataObject * pDataObj; - - This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDefaultContextMenuImpl)); - if (This) - { - This->lpVtbl = &cmvt; - This->ref = 1; - TRACE("cidl %u\n", This->dcm.cidl); - if (SUCCEEDED(SHCreateDataObject(pdcm->pidlFolder, pdcm->cidl, pdcm->apidl, NULL, &IID_IDataObject, (void**)&pDataObj))) - { - This->pDataObj = pDataObj; - } - CopyMemory(&This->dcm, pdcm, sizeof(DEFCONTEXTMENU)); - hr = IDefaultContextMenu_fnQueryInterface((IContextMenu2*)This, riid, ppv); - } - - TRACE("This(%p)(%x) cidl %u\n",This, hr, This->dcm.cidl); - return hr; -} - - -/************************************************************************* - * SHCreateDefaultContextMenu [SHELL32.325] Vista API - * - */ - -HRESULT -WINAPI -SHCreateDefaultContextMenu( - const DEFCONTEXTMENU *pdcm, - REFIID riid, - void **ppv) -{ -#if 1 - HRESULT hr = E_FAIL; - - *ppv = NULL; - hr = IDefaultContextMenu_Constructor( pdcm, riid, ppv ); - - TRACE("pcm %p hr %x\n", pdcm, hr); - return hr; -#else - HRESULT hr; - IContextMenu2 * pcm; - - if (pdcm->cidl > 0) - pcm = ISvItemCm_Constructor( pdcm->psf, pdcm->pidlFolder, pdcm->apidl, pdcm->cidl ); - else - pcm = ISvBgCm_Constructor( pdcm->psf, TRUE ); - - hr = S_OK; - *ppv = pcm; - - return hr; -#endif -} - -/************************************************************************* - * CDefFolderMenu_Create2 [SHELL32.701] - * - */ - -INT -WINAPI -CDefFolderMenu_Create2( - LPCITEMIDLIST pidlFolder, - HWND hwnd, - UINT cidl, - LPCITEMIDLIST *apidl, - IShellFolder *psf, - LPFNDFMCALLBACK lpfn, - UINT nKeys, - HKEY *ahkeyClsKeys, - IContextMenu **ppcm) -{ - DEFCONTEXTMENU pdcm; - HRESULT hr; - - pdcm.hwnd = hwnd; - pdcm.pcmcb = NULL; - pdcm.pidlFolder = pidlFolder; - pdcm.psf = psf; - pdcm.cidl = cidl; - pdcm.apidl = apidl; - pdcm.punkAssociationInfo = NULL; - pdcm.cKeys = nKeys; - pdcm.aKeys = ahkeyClsKeys; - - hr = SHCreateDefaultContextMenu(&pdcm, &IID_IContextMenu, (void**)ppcm); - return hr; -} - Modified: trunk/reactos/dll/win32/shell32/shv_item_cmenu.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shv_item…
============================================================================== --- trunk/reactos/dll/win32/shell32/shv_item_cmenu.c (original) +++ trunk/reactos/dll/win32/shell32/shv_item_cmenu.c Wed Jan 2 02:42:01 2008 @@ -1262,3 +1262,62 @@ RegCloseKey(hKey); return index; } + +/************************************************************************* + * SHCreateDefaultContextMenu [SHELL32.325] Vista API + * + */ + +HRESULT WINAPI SHCreateDefaultContextMenu( + const DEFCONTEXTMENU *pdcm, + REFIID riid, + void **ppv) +{ + HRESULT hr; + IContextMenu2 * pcm; + + if (pdcm->cidl > 0) + pcm = ISvItemCm_Constructor( pdcm->psf, pdcm->pidlFolder, pdcm->apidl, pdcm->cidl ); + else + pcm = ISvBgCm_Constructor( pdcm->psf, TRUE ); + + hr = S_OK; + *ppv = pcm; + + return hr; +} + +/************************************************************************* + * CDefFolderMenu_Create2 [SHELL32.701] + * + */ + +INT +WINAPI +CDefFolderMenu_Create2( + LPCITEMIDLIST pidlFolder, + HWND hwnd, + UINT cidl, + LPCITEMIDLIST *apidl, + IShellFolder *psf, + LPFNDFMCALLBACK lpfn, + UINT nKeys, + HKEY *ahkeyClsKeys, + IContextMenu **ppcm) +{ + DEFCONTEXTMENU pdcm; + HRESULT hr; + + pdcm.hwnd = hwnd; + pdcm.pcmcb = NULL; //FIXME + pdcm.pidlFolder = pidlFolder; + pdcm.psf = psf; + pdcm.cidl = cidl; + pdcm.apidl = apidl; + pdcm.punkAssociationInfo = NULL; + pdcm.cKeys = nKeys; + pdcm.aKeys = ahkeyClsKeys; + + hr = SHCreateDefaultContextMenu(&pdcm, &IID_IContextMenu, (void**)ppcm); + return hr; +}
17 years
1
0
0
0
[janderwald] 31547: - scan HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu key if a shellfolder should be hidden - also add items which should should not be hidden - network location shell folder now appears but isnt working
by janderwald@svn.reactos.org
Author: janderwald Date: Wed Jan 2 02:34:28 2008 New Revision: 31547 URL:
http://svn.reactos.org/svn/reactos?rev=31547&view=rev
Log: - scan HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu key if a shellfolder should be hidden - also add items which should should not be hidden - network location shell folder now appears but isnt working Added: trunk/reactos/dll/win32/shell32/shv_default_context_menu.c (with props) Modified: trunk/reactos/dll/win32/shell32/enumidlist.c trunk/reactos/dll/win32/shell32/enumidlist.h trunk/reactos/dll/win32/shell32/shfldr_desktop.c trunk/reactos/dll/win32/shell32/shlfldr_mydocuments.c trunk/reactos/dll/win32/shell32/shlfolder.c trunk/reactos/dll/win32/shell32/shv_item_cmenu.c Modified: trunk/reactos/dll/win32/shell32/enumidlist.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/enumidli…
============================================================================== --- trunk/reactos/dll/win32/shell32/enumidlist.c (original) +++ trunk/reactos/dll/win32/shell32/enumidlist.c Wed Jan 2 02:34:28 2008 @@ -98,6 +98,29 @@ } return FALSE; } +/************************************************************************** + * HasItemWithCLSID() + */ +BOOL HasItemWithCLSID(IEnumIDList *iface, LPITEMIDLIST pidl) +{ + IEnumIDListImpl *This = (IEnumIDListImpl *)iface; + LPENUMLIST pCur; + REFIID refid = _ILGetGUIDPointer(pidl); + + pCur = This->mpFirst; + + while(pCur) + { + REFIID curid = _ILGetGUIDPointer(pCur->pidl); + if (IsEqualIID(curid, refid)) + { + return TRUE; + } + pCur = pCur->pNext; + } + return FALSE; +} + /************************************************************************** * CreateFolderEnumList() Modified: trunk/reactos/dll/win32/shell32/enumidlist.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/enumidli…
============================================================================== --- trunk/reactos/dll/win32/shell32/enumidlist.h (original) +++ trunk/reactos/dll/win32/shell32/enumidlist.h Wed Jan 2 02:34:28 2008 @@ -21,6 +21,7 @@ /* Creates an IEnumIDList; add LPITEMIDLISTs to it with AddToEnumList. */ LPENUMIDLIST IEnumIDList_Constructor(void); BOOL AddToEnumList(IEnumIDList *list, LPITEMIDLIST pidl); +BOOL HasItemWithCLSID(IEnumIDList *list, LPITEMIDLIST pidl); /* Enumerates the folders and/or files (depending on dwFlags) in lpszPath and * adds them to the already-created list. Modified: trunk/reactos/dll/win32/shell32/shfldr_desktop.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shfldr_d…
============================================================================== --- trunk/reactos/dll/win32/shell32/shfldr_desktop.c (original) +++ trunk/reactos/dll/win32/shell32/shfldr_desktop.c Wed Jan 2 02:34:28 2008 @@ -239,6 +239,34 @@ return hr; } +static const WCHAR ClassicStartMenuW[] = {'S','O','F','T','W','A','R','E','\\', + 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\', + 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r', + '\\','H','i','d','e','D','e','s','k','t','o','p','I','c','o','n','s','\\', + 'C','l','a','s','s','i','c','S','t','a','r','t','M','e','n','u','\0' }; + +INT +HideNamespaceExtension(WCHAR *iid) +{ + DWORD Result, dwResult; + dwResult = sizeof(DWORD); + + if (RegGetValueW(HKEY_CURRENT_USER, /* FIXME use NewStartPanel when activated */ + ClassicStartMenuW, + iid, + RRF_RT_DWORD, + NULL, + &Result, + &dwResult) != ERROR_SUCCESS) + { + return -1; + } + + return Result; +} + + + /************************************************************************** * CreateDesktopEnumList() */ @@ -252,6 +280,8 @@ { BOOL ret = TRUE; WCHAR szPath[MAX_PATH]; + static WCHAR MyDocumentsClassString[] = L"{450D8FBA-AD25-11D0-98A8-0800361B1103}"; + TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags); @@ -260,14 +290,23 @@ { HKEY hkey; UINT i; + DWORD dwResult; /* create the pidl for This item */ - ret = AddToEnumList(list, _ILCreateMyDocuments()); + if (HideNamespaceExtension(MyDocumentsClassString) < 1) + { + ret = AddToEnumList(list, _ILCreateMyDocuments()); + } ret = AddToEnumList(list, _ILCreateMyComputer()); - for (i=0; i<2; i++) { - if (ret && !RegOpenKeyExW(i == 0 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, - Desktop_NameSpaceW, 0, KEY_READ, &hkey)) + for (i = 0; i < 2; i++) + { + if (i == 0) + dwResult = RegOpenKeyExW(HKEY_LOCAL_MACHINE, Desktop_NameSpaceW, 0, KEY_READ, &hkey); + else + dwResult = RegOpenKeyExW(HKEY_CURRENT_USER, Desktop_NameSpaceW, 0, KEY_READ, &hkey); + + if (dwResult == ERROR_SUCCESS) { WCHAR iid[50]; LPITEMIDLIST pidl; @@ -282,24 +321,69 @@ r = RegEnumKeyExW(hkey, i, iid, &size, 0, NULL, NULL, NULL); if (ERROR_SUCCESS == r) { - pidl = _ILCreateGuidFromStrW(iid); - if (_ILIsMyDocuments(pidl)) + if (HideNamespaceExtension(iid) < 1) { - SHFree(pidl); + pidl = _ILCreateGuidFromStrW(iid); + if (!HasItemWithCLSID(list, pidl)) + { + ret = AddToEnumList(list, pidl); + } + else + { + SHFree(pidl); + } + } + } + else if (ERROR_NO_MORE_ITEMS == r) + break; + else + ret = FALSE; + i++; + } + RegCloseKey(hkey); + } + } + for (i = 0; i < 2; i++) + { + if (i == 0) + dwResult = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ClassicStartMenuW, 0, KEY_READ, &hkey); + else + dwResult = RegOpenKeyExW(HKEY_CURRENT_USER, ClassicStartMenuW, 0, KEY_READ, &hkey); + + if (dwResult == ERROR_SUCCESS) + { + DWORD j = 0, dwVal, Val, dwType, dwIID; + LONG r; + WCHAR iid[50]; + + while(ret) + { + dwVal = sizeof(Val); + dwIID = sizeof(iid) / sizeof(WCHAR); + + r = RegEnumValueW(hkey, j++, iid, &dwIID, NULL, &dwType, (LPBYTE)&Val, &dwVal); + if (r == ERROR_SUCCESS) + { + if (Val == 0 && dwType == REG_DWORD) + { + LPITEMIDLIST pidl = _ILCreateGuidFromStrW(iid); + if (!HasItemWithCLSID(list, pidl)) + { + AddToEnumList(list, pidl); + } + else + { + SHFree(pidl); + } } - else - { - ret = AddToEnumList(list, pidl); - } - i++; } else if (ERROR_NO_MORE_ITEMS == r) break; else ret = FALSE; } - RegCloseKey(hkey); } + } } Modified: trunk/reactos/dll/win32/shell32/shlfldr_mydocuments.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shlfldr_…
============================================================================== --- trunk/reactos/dll/win32/shell32/shlfldr_mydocuments.c (original) +++ trunk/reactos/dll/win32/shell32/shlfldr_mydocuments.c Wed Jan 2 02:34:28 2008 @@ -52,7 +52,7 @@ #include "debughlp.h" #include "shfldr.h" -WINE_DEFAULT_DEBUG_CHANNEL (shell); +WINE_DEFAULT_DEBUG_CHANNEL (mydocs); /*********************************************************************** * MyDocumentsfolder implementation @@ -500,13 +500,14 @@ if (!pszPath) return E_OUTOFMEMORY; - if (_ILIsMyDocuments (pidl) || _ILIsDesktop(pidl)) + if (_ILIsMyDocuments (pidl)) { if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING)) strcpyW(pszPath, This->sPathTarget); else HCR_GetClassNameW(&CLSID_MyDocuments, pszPath, MAX_PATH); + TRACE("CP\n"); } else if (_ILIsPidlSimple (pidl)) { @@ -563,6 +564,7 @@ hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, pszPath, MAX_PATH); + TRACE("CP\n"); } else { @@ -570,12 +572,14 @@ pszPath[0] = ':'; pszPath[1] = ':'; SHELL32_GUIDToStringW (clsid, &pszPath[2]); + TRACE("CP\n"); } } else { /* user friendly name */ HCR_GetClassNameW (clsid, pszPath, MAX_PATH); + TRACE("CP\n"); } } else @@ -587,14 +591,20 @@ (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)) { lstrcpynW(pszPath, This->sPathTarget, MAX_PATH - 1); + TRACE("CP %s\n", debugstr_w(pszPath)); + } + + if (!_ILIsDesktop(pidl)) + { PathAddBackslashW(pszPath); cLen = lstrlenW(pszPath); + _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen); + if (!_ILIsFolder(pidl)) + { + SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags); + TRACE("CP\n"); + } } - - _ILSimpleGetTextW(pidl, pszPath + cLen, MAX_PATH - cLen); - - if (!_ILIsFolder(pidl)) - SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags); } } else @@ -602,31 +612,18 @@ /* a complex pidl, let the subfolder do the work */ hr = SHELL32_GetDisplayNameOfChild (iface, pidl, dwFlags, pszPath, MAX_PATH); + TRACE("CP\n"); } if (SUCCEEDED(hr)) { - /* Win9x always returns ANSI strings, NT always returns Unicode strings */ - if (GetVersion() & 0x80000000) - { - strRet->uType = STRRET_CSTR; - if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH, - NULL, NULL)) - strRet->u.cStr[0] = '\0'; - CoTaskMemFree(pszPath); - } - else - { - strRet->uType = STRRET_WSTR; - strRet->u.pOleStr = pszPath; - } + strRet->uType = STRRET_WSTR; + strRet->u.pOleStr = pszPath; } else CoTaskMemFree(pszPath); - TRACE ("-- (%p)->(%s,0x%08x)\n", This, - strRet->uType == STRRET_CSTR ? strRet->u.cStr : - debugstr_w(strRet->u.pOleStr), hr); + TRACE ("-- (%p)->(%s,0x%08x)\n", This, debugstr_w(strRet->u.pOleStr), hr); return hr; } Modified: trunk/reactos/dll/win32/shell32/shlfolder.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shlfolde…
============================================================================== --- trunk/reactos/dll/win32/shell32/shlfolder.c (original) +++ trunk/reactos/dll/win32/shell32/shlfolder.c Wed Jan 2 02:34:28 2008 @@ -418,7 +418,7 @@ if (_ILIsDrive (pidl)) { *pdwAttributes &= SFGAO_HASSUBFOLDER|SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR| - SFGAO_DROPTARGET|SFGAO_HASPROPSHEET|SFGAO_CANLINK; + SFGAO_DROPTARGET|SFGAO_HASPROPSHEET|SFGAO_CANLINK|SFGAO_CANRENAME; } else if (has_guid && HCR_GetFolderAttributes(pidl, &dwAttributes)) { *pdwAttributes = dwAttributes; } else if (_ILGetDataPointer (pidl)) { Added: trunk/reactos/dll/win32/shell32/shv_default_context_menu.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shv_defa…
============================================================================== --- trunk/reactos/dll/win32/shell32/shv_default_context_menu.c (added) +++ trunk/reactos/dll/win32/shell32/shv_default_context_menu.c Wed Jan 2 02:34:28 2008 @@ -1,0 +1,1246 @@ +/* + * PROJECT: shell32 + * LICENSE: GPL - See COPYING in the top level directory + * FILE: dll/win32/shell32/shv_item_new.c + * PURPOSE: provides default context menu implementation + * PROGRAMMERS: Johannes Anderwald (janderwald(a)reactos.org) + */ + +#include <string.h> + +#define COBJMACROS +#define NONAMELESSUNION +#define NONAMELESSSTRUCT +#define YDEBUG +#include "winerror.h" +#include "wine/debug.h" + +#include "windef.h" +#include "wingdi.h" +#include "pidl.h" +#include "undocshell.h" +#include "shlobj.h" +#include "objbase.h" + +#include "shlwapi.h" +#include "shell32_main.h" +#include "shellfolder.h" +#include "debughlp.h" +#include "shresdef.h" +#include "shlguid.h" + +WINE_DEFAULT_DEBUG_CHANNEL(dmenu); + +typedef struct _DynamicShellEntry_ +{ + UINT iIdCmdFirst; + UINT NumIds; + IContextMenu * CMenu; + struct _DynamicShellEntry_ * Next; +}DynamicShellEntry, *PDynamicShellEntry; + +typedef struct _StaticShellEntry_ +{ + LPWSTR szVerb; + LPWSTR szClass; + struct _StaticShellEntry_ * Next; +}StaticShellEntry, *PStaticShellEntry; + + +typedef struct +{ + const IContextMenu2Vtbl *lpVtbl; + LONG ref; + DEFCONTEXTMENU dcm; + IDataObject * pDataObj; + DWORD bGroupPolicyActive; + PDynamicShellEntry dhead; /* first dynamic shell extension entry */ + UINT iIdSHEFirst; /* first used id */ + UINT iIdSHELast; /* last used id */ + PStaticShellEntry shead; /* first static shell extension entry */ + UINT iIdSCMFirst; /* first static used id */ + UINT iIdSCMLast; /* last static used id */ +}IDefaultContextMenuImpl; + +static inline IDefaultContextMenuImpl *impl_from_IContextMenu( IContextMenu2 *iface ) +{ + return (IDefaultContextMenuImpl *)((char*)iface - FIELD_OFFSET(IDefaultContextMenuImpl, lpVtbl)); +} + +static +HRESULT +WINAPI +IDefaultContextMenu_fnQueryInterface( + IContextMenu2 *iface, + REFIID riid, + LPVOID *ppvObj) +{ + IDefaultContextMenuImpl *This = (IDefaultContextMenuImpl *)iface; + + TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj); + + *ppvObj = NULL; + + if(IsEqualIID(riid, &IID_IUnknown) || + IsEqualIID(riid, &IID_IContextMenu) || + IsEqualIID(riid, &IID_IContextMenu2)) + { + *ppvObj = This; + } + + if(*ppvObj) + { + IUnknown_AddRef((IUnknown*)*ppvObj); + TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj); + return S_OK; + } + TRACE("-- Interface: E_NOINTERFACE\n"); + return E_NOINTERFACE; +} + + +static +ULONG +WINAPI +IDefaultContextMenu_fnAddRef( + IContextMenu2 *iface) +{ + IDefaultContextMenuImpl *This = (IDefaultContextMenuImpl *)iface; + ULONG refCount = InterlockedIncrement(&This->ref); + + TRACE("(%p)->(count=%u)\n", This, refCount - 1); + + return refCount; +} + +static +ULONG +WINAPI +IDefaultContextMenu_fnRelease( + IContextMenu2 *iface) +{ + IDefaultContextMenuImpl *This = (IDefaultContextMenuImpl *)iface; + ULONG refCount = InterlockedDecrement(&This->ref); + + TRACE("(%p)->(count=%u)\n", This, refCount + 1); + if (!refCount) + { + TRACE(" destroying IContextMenu(%p)\n",This); + + HeapFree(GetProcessHeap(),0,This); + } + + return refCount; +} + +static +void +SH_AddStaticEntry(IDefaultContextMenuImpl * This, HKEY hKey, WCHAR *szVerb, WCHAR * szClass) +{ + PStaticShellEntry curEntry; + PStaticShellEntry lastEntry = NULL; + + curEntry = This->shead; + + while(curEntry) + { + if (!wcsicmp(curEntry->szVerb, szVerb)) + { + /* entry already exists */ + return; + } + lastEntry = curEntry; + curEntry = curEntry->Next; + } + + TRACE("adding verb %s szClass %s\n", debugstr_w(szVerb), debugstr_w(szClass)); + + curEntry = malloc(sizeof(StaticShellEntry)); + if (curEntry) + { + curEntry->Next = NULL; + curEntry->szVerb = wcsdup(szVerb); + curEntry->szClass = wcsdup(szClass); + } + + if (lastEntry) + { + lastEntry->Next = curEntry; + } + else + { + This->shead = curEntry; + } +} + +static +void +SH_AddStaticEntryForKey(IDefaultContextMenuImpl * This, HKEY hKey, WCHAR * szClass) +{ + LONG result; + DWORD dwIndex; + WCHAR szName[40]; + DWORD dwName; + + dwIndex = 0; + do + { + szName[0] = 0; + dwName = sizeof(szName) / sizeof(WCHAR); + result = RegEnumKeyExW(hKey, dwIndex, szName, &dwName, NULL, NULL, NULL, NULL); + szName[39] = 0; + if (result == ERROR_SUCCESS) + { + SH_AddStaticEntry(This, hKey, szName, szClass); + } + dwIndex++; + }while(result == ERROR_SUCCESS); +} + +static +void +SH_AddStaticEntryForFileClass(IDefaultContextMenuImpl * This, WCHAR * szExt) +{ + WCHAR szBuffer[100]; + HKEY hKey; + LONG result; + DWORD dwBuffer; + + TRACE("SH_AddStaticEntryForFileClass entered with %s\n", debugstr_w(szExt)); + + wcscpy(szBuffer, szExt); + wcscat(szBuffer, L"\\shell"); + result = RegOpenKeyExW(HKEY_CLASSES_ROOT, szBuffer, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); + if (result == ERROR_SUCCESS) + { + SH_AddStaticEntryForKey(This, hKey, szExt); + RegCloseKey(hKey); + } + + dwBuffer = sizeof(szBuffer); + result = RegGetValueW(HKEY_CLASSES_ROOT, szExt, NULL, RRF_RT_REG_SZ, NULL, (LPBYTE)szBuffer, &dwBuffer); + if (result == ERROR_SUCCESS) + { + UINT length = strlenW(szBuffer); + wcscat(szBuffer, L"\\shell"); + TRACE("szBuffer %s\n", debugstr_w(szBuffer)); + + result = RegOpenKeyExW(HKEY_CLASSES_ROOT, szBuffer, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); + if (result == ERROR_SUCCESS) + { + szBuffer[length] = 0; + SH_AddStaticEntryForKey(This, hKey, szBuffer); + RegCloseKey(hKey); + } + } + + strcpyW(szBuffer, "SystemFileAssociations\\"); + dwBuffer = sizeof(szBuffer) - strlenW(szBuffer) * sizeof(WCHAR); + result = RegGetValueW(HKEY_CLASSES_ROOT, szExt, L"PerceivedType", RRF_RT_REG_SZ, NULL, (LPBYTE)&szBuffer[23], &dwBuffer); + if (result == ERROR_SUCCESS) + { + UINT length = strlenW(szBuffer); + wcscat(szBuffer, L"\\shell"); + TRACE("szBuffer %s\n", debugstr_w(szBuffer)); + + result = RegOpenKeyExW(HKEY_CLASSES_ROOT, szBuffer, 0, KEY_READ | KEY_QUERY_VALUE, &hKey); + if (result == ERROR_SUCCESS) + { + szBuffer[length] = 0; + SH_AddStaticEntryForKey(This, hKey, szBuffer); + RegCloseKey(hKey); + } + } + RegCloseKey(hKey); +} + +static +BOOL +HasClipboardData() +{ + BOOL ret = FALSE; + IDataObject * pda; + + if(SUCCEEDED(OleGetClipboard(&pda))) + { + STGMEDIUM medium; + FORMATETC formatetc; + + TRACE("pda=%p\n", pda); + + /* Set the FORMATETC structure*/ + InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL); + if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium))) + { + ret = TRUE; + } + + IDataObject_Release(pda); + ReleaseStgMedium(&medium); + } + + return ret; +} + +VOID +DisablePasteOptions(HMENU hMenu) +{ + MENUITEMINFOW mii; + + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_STATE; + mii.fState = MFS_DISABLED; + + TRACE("result %d\n", SetMenuItemInfoW(hMenu, FCIDM_SHVIEW_INSERT, FALSE, &mii)); + TRACE("result %d\n", SetMenuItemInfoW(hMenu, FCIDM_SHVIEW_INSERTLINK, FALSE, &mii)); +} + +static +HRESULT +SH_LoadDynamicContextMenuHandler(IDefaultContextMenuImpl * This, HKEY hKey, const CLSID * szClass, BOOL bExternalInit) +{ + HRESULT hr; + IContextMenu * cmobj; + IShellExtInit *shext; + PDynamicShellEntry curEntry; + TRACE("SH_LoadDynamicContextMenuHandler entered with This %p hKey %p szClass %s bExternalInit %u\n",This, hKey, wine_dbgstr_guid(szClass), bExternalInit); + + hr = SHCoCreateInstance(NULL, szClass, NULL, &IID_IContextMenu, (void**)&cmobj); + if (hr != S_OK) + { + TRACE("SHCoCreateInstance failed %x\n", GetLastError()); + return hr; + } + + if (bExternalInit) + { + hr = cmobj->lpVtbl->QueryInterface(cmobj, &IID_IShellExtInit, (void**)&shext); + if (hr != S_OK) + { + TRACE("Failed to query for interface IID_IShellExtInit\n"); + cmobj->lpVtbl->Release(cmobj); + return FALSE; + } + hr = shext->lpVtbl->Initialize(shext, NULL, This->pDataObj, hKey); + shext->lpVtbl->Release(shext); + if (hr != S_OK) + { + TRACE("Failed to initialize shell extension error %x\n", hr); + cmobj->lpVtbl->Release(cmobj); + return hr; + } + } + + curEntry = malloc(sizeof(DynamicShellEntry)); + if(!curEntry) + { + return E_OUTOFMEMORY; + } + + curEntry->iIdCmdFirst = 0; + curEntry->Next = NULL; + curEntry->NumIds = 0; + curEntry->CMenu = cmobj; + + if (This->dhead) + { + PDynamicShellEntry pEntry = This->dhead; + + while(pEntry->Next) + { + pEntry = pEntry->Next; + } + + pEntry->Next = curEntry; + } + else + { + This->dhead = curEntry; + } + + return hr; +} + +static +UINT +EnumerateDynamicContextHandlerForKey(IDefaultContextMenuImpl *This, HKEY hRootKey) +{ + WCHAR szKey[MAX_PATH] = {0}; + WCHAR szName[MAX_PATH] = {0}; + DWORD dwIndex, dwName; + LONG res; + HRESULT hResult; + UINT index; + CLSID clsid; + HKEY hKey; + + static const WCHAR szShellEx[] = { 's','h','e','l','l','e','x','\\','C','o','n','t','e','x','t','M','e','n','u','H','a','n','d','l','e','r','s',0 }; + + if (RegOpenKeyExW(hRootKey, szShellEx, 0, KEY_READ, &hKey) != ERROR_SUCCESS) + { + TRACE("RegOpenKeyExW failed for key %s\n", debugstr_w(szKey)); + return 0; + } + + dwIndex = 0; + index = 0; + do + { + dwName = MAX_PATH; + res = RegEnumKeyExW(hKey, dwIndex, szName, &dwName, NULL, NULL, NULL, NULL); + if (res == ERROR_SUCCESS) + { + hResult = CLSIDFromString(szName, &clsid); + if (hResult != S_OK) + { + dwName = MAX_PATH; + if (RegGetValueW(hKey, szName, NULL, RRF_RT_REG_SZ, NULL, szKey, &dwName) == ERROR_SUCCESS) + { + if (CLSIDFromString(szKey, &clsid) == S_OK) + { + if (This->bGroupPolicyActive) + { + if (RegGetValueW(HKEY_LOCAL_MACHINE, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", + szKey, + RRF_RT_REG_SZ, + NULL, + NULL, + &dwName) == ERROR_SUCCESS) + { + SH_LoadDynamicContextMenuHandler(This, hKey, &clsid, TRUE); + } + + } + else + { + SH_LoadDynamicContextMenuHandler(This, hKey, &clsid, TRUE); + } + } + } + } + if (hResult == S_OK) + { + if (This->bGroupPolicyActive) + { + if (RegGetValueW(HKEY_LOCAL_MACHINE, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", + szKey, + RRF_RT_REG_SZ, + NULL, + NULL, + &dwName) == ERROR_SUCCESS) + { + SH_LoadDynamicContextMenuHandler(This, hKey, &clsid, TRUE); + } + } + else + { + SH_LoadDynamicContextMenuHandler(This, hKey, &clsid, TRUE); + } + } + } + dwIndex++; + }while(res == ERROR_SUCCESS); + + RegCloseKey(hKey); + return index; +} + + +static +UINT +InsertMenuItemsOfDynamicContextMenuExtension(IDefaultContextMenuImpl * This, HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast) +{ + PDynamicShellEntry curEntry; + HRESULT hResult; + MENUITEMINFOW mii; + if (!This->dhead) + { + This->iIdSHEFirst = 0; + This->iIdSHELast = 0; + return indexMenu; + } + + curEntry = This->dhead; + This->iIdSHEFirst = idCmdFirst; + + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_FTYPE | MIIM_STATE; + mii.fType = MFT_SEPARATOR; + mii.fState = MFS_ENABLED; + InsertMenuItemW(hMenu, indexMenu++, TRUE, &mii); + + do + { + hResult = IContextMenu_QueryContextMenu(curEntry->CMenu, hMenu, indexMenu, idCmdFirst, idCmdLast, CMF_NORMAL); + if (SUCCEEDED(hResult)) + { + curEntry->iIdCmdFirst = idCmdFirst; + curEntry->NumIds = LOWORD(hResult); + indexMenu += curEntry->NumIds; + idCmdFirst += curEntry->NumIds + 0x10; + } + TRACE("curEntry %p hresult %x contextmenu %p cmdfirst %x num ids %x\n", curEntry, hResult, curEntry->CMenu, curEntry->iIdCmdFirst, curEntry->NumIds); + curEntry = curEntry->Next; + }while(curEntry); + + This->iIdSHELast = idCmdFirst; + TRACE("SH_LoadContextMenuHandlers first %x last %x\n", This->iIdSHEFirst, This->iIdSHELast); + return indexMenu; +} + +UINT +BuildBackgroundContextMenu( + IDefaultContextMenuImpl * This, + HMENU hMenu, + UINT iIdCmdFirst, + UINT iIdCmdLast, + UINT uFlags) +{ + MENUITEMINFOW mii; + WCHAR szBuffer[MAX_PATH]; + UINT indexMenu = 0; + HMENU hSubMenu; + HKEY hKey; + + ZeroMemory(&mii, sizeof(mii)); + + TRACE("BuildBackgroundContextMenu entered\n"); + + if (!_ILIsDesktop(This->dcm.pidlFolder)) + { + /* view option is only available in browsing mode */ + hSubMenu = LoadMenuA(shell32_hInstance, "MENU_001"); + if (hSubMenu) + { + szBuffer[0] = 0; + LoadStringW(shell32_hInstance, FCIDM_SHVIEW_VIEW, szBuffer, MAX_PATH); + szBuffer[MAX_PATH-1] = 0; + + TRACE("szBuffer %s\n", debugstr_w(szBuffer)); + + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_TYPE | MIIM_STATE | MIIM_SUBMENU | MIIM_ID; + mii.fType = MFT_STRING; + mii.wID = iIdCmdFirst++; + mii.dwTypeData = szBuffer; + mii.cch = strlenW( mii.dwTypeData ); + mii.fState = MFS_ENABLED; + mii.hSubMenu = hSubMenu; + InsertMenuItemW(hMenu, indexMenu++, TRUE, &mii); + DestroyMenu(hSubMenu); + } + } + hSubMenu = LoadMenuA(shell32_hInstance, "MENU_002"); + if (hSubMenu) + { + /* merge general background context menu in */ + iIdCmdFirst = Shell_MergeMenus(hMenu, hSubMenu, indexMenu, 0, iIdCmdLast, MM_DONTREMOVESEPS | MM_SUBMENUSHAVEIDS) + 1; + DestroyMenu(hSubMenu); + } + + if (!HasClipboardData()) + { + TRACE("disabling paste options\n"); + DisablePasteOptions(hMenu); + } + /* load extensions from HKCR\* key */ + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, + L"*", + 0, + KEY_READ, + &hKey) == ERROR_SUCCESS) + { + EnumerateDynamicContextHandlerForKey(This, hKey); + RegCloseKey(hKey); + } + + /* load create new shell extension */ + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, + L"CLSID\\{D969A300-E7FF-11d0-A93B-00A0C90F2719}", + 0, + KEY_READ, + &hKey) == ERROR_SUCCESS) + { + static const GUID dummy1 = {0xD969A300, 0xE7FF, 0x11d0, {0xA9, 0x3B, 0x00, 0xA0, 0xC9, 0x0F, 0x27, 0x19} }; + SH_LoadDynamicContextMenuHandler(This, hKey, &dummy1, FALSE); + RegCloseKey(hKey); + } + + InsertMenuItemsOfDynamicContextMenuExtension(This, hMenu, GetMenuItemCount(hMenu), iIdCmdFirst, iIdCmdLast); + return iIdCmdLast; +} + +static +UINT +AddStaticContextMenusToMenu( + HMENU hMenu, + UINT indexMenu, + IDefaultContextMenuImpl * This) +{ + MENUITEMINFOW mii; + PStaticShellEntry curEntry; + + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE | MIIM_DATA; + mii.fType = MFT_STRING; + mii.fState = MFS_ENABLED | MFS_DEFAULT; + mii.wID = 0x4000; + This->iIdSCMFirst = mii.wID; + + curEntry = This->shead; + + while(curEntry) + { + /* FIXME + * load localized verbs if its an open edit find print printto openas properties verb + */ + + mii.dwTypeData = curEntry->szVerb; + mii.cch = strlenW(mii.dwTypeData); + InsertMenuItemW(hMenu, indexMenu++, TRUE, &mii); + mii.fState = MFS_ENABLED; + mii.wID++; + curEntry = curEntry->Next; + } + This->iIdSCMLast = mii.wID - 1; + return indexMenu; +} + +static +const char * +GetLocalizedString( + HMENU hMenu, + UINT wID, + char * sResult) +{ + MENUITEMINFOA mii; + + sResult[0] = 0; + if (!hMenu) + { + return sResult; + } + + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_TYPE; + mii.fType = MFT_STRING; + mii.dwTypeData = sResult; + mii.cch = 100; + + GetMenuItemInfoA(hMenu, wID, FALSE, &mii); + return sResult; +} +#if 0 +UINT +BuildControlPanelContextMenu( + IDefaultContextMenuImpl * This, + HMENU hMenu, + UINT iIdCmdFirst, + UINT iIdCmdLast) +{ + GUID * guid; + SFGAOF attributes; + DWORD dwSize; + UINT indexMenu = 0; + LPOLESTR pwszCLSID; + WCHAR szClass[80]; + UINT length; + MENUITEMINFOW mii; + + + ZeroMemory(&mii, sizeof(MENUITEMINFOW)); + + mii.cbSize = sizeof(MENUITEMINFOW); + mii.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_ID; + mii.fType = MFT_STRING; + mii.fState = MFS_ENABLED; + + guid = _ILGetGUIDPointer(This->dcm.apidl[0]); + if (guid) + { + /* the cpl is registered as a namespace extension */ + dwSize = sizeof(SFGAOF); + wcscpy(szClass, L"CLSID\\"); + if (SUCCEEDED(StringFromCLSID(guid, &pwszCLSID))) + { + wcscpy(&szClass[6], pwszCLSID); + length = strlenW(szClass); + + CoTaskMemFree(pwszCLSID); + + /* check if the CLSID is a folder */ + wcscat(szClass, L"\\ShellFolder"); + + if (RegGetValueW(HKEY_CLASSES_ROOT, szClass, L"Attributes", RRF_RT_REG_BINARY, NULL, &attributes, &dwSize) == ERROR_SUCCESS) + { + if (attributes & SFGAO_FOLDER) + { + WCHAR szBuffer[100]; + /* insert explore string */ + LoadStringW(shell32_hInstance, FCIDM_SHVIEW_EXPLORE, szBuffer, sizeof(szBuffer) / sizeof(WCHAR)); + szBuffer[99] = 0; + mii.wID = FCIDM_SHVIEW_EXPLORE; + mii.dwTypeData = szBuffer; + mii.fState |= MFS_DEFAULT; + InsertMenuItem(hMenu, indexMenu++, TRUE, &mii); + mii.fState = MFS_ENABLED; + } + } + + /* add static handlers*/ + szClass[length] = 0; + SH_AddStaticEntryForFileClass(This, szClass); + indexMenu = AddStaticContextMenusToMenu(hMenu, indexMenu, This); + } + } + else + { + /* cpl is registered with full path */ + SH_AddStaticEntryForFileClass(This, L".cpl"); + } + + if (AppendMenu(hMenu, MF_SEPARATOR, -1, NULL)) + { + LoadStringW(shell32_hInstance, FCIDM_SHVIEW_CREATELINK, szClass, sizeof(szClass) / sizeof(WCHAR)); + szClass[79] = 0; + InsertMenuItem(hMenu, indexMenu++, TRUE, &mii); + } +} +#endif + +UINT +BuildShellItemContextMenu( + IDefaultContextMenuImpl * This, + HMENU hMenu, + UINT iIdCmdFirst, + UINT iIdCmdLast, + UINT uFlags) +{ + WCHAR szExt[10]; + char sBuffer[100]; + HKEY hKey; + UINT indexMenu; + SFGAOF rfg; + HRESULT hr; + BOOL bAddSep; + HMENU hLocalMenu; + GUID * guid; + + TRACE("BuildShellItemContextMenu entered\n"); + + if (_ILGetExtension(This->dcm.apidl[0], &sBuffer[1], sizeof(sBuffer))) + { + sBuffer[9] = 0; + sBuffer[0] = '.'; + + if (MultiByteToWideChar( CP_ACP, 0, sBuffer, -1, (LPWSTR)szExt, 10)) + { + TRACE("szExt %d\n", debugstr_w(szExt)); + SH_AddStaticEntryForFileClass(This, szExt); + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szExt, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + EnumerateDynamicContextHandlerForKey(This, hKey); + RegCloseKey(hKey); + } + } + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"*", 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + /* load default extensions */ + EnumerateDynamicContextHandlerForKey(This, hKey); + RegCloseKey(hKey); + } + } + + if (!_ILIsPidlSimple(This->dcm.apidl[0])|| _ILIsFolder(This->dcm.apidl[0])) + { + /* add the default verbs open / explore */ + SH_AddStaticEntryForFileClass(This, L"Folder"); + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Folder", 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + EnumerateDynamicContextHandlerForKey(This, hKey); + RegCloseKey(hKey); + } + } + + guid = _ILGetGUIDPointer(This->dcm.apidl[0]); + if (guid) + { + LPOLESTR pwszCLSID; + WCHAR buffer[60]; + + wcscpy(buffer, L"CLSID\\"); + hr = StringFromCLSID(guid, &pwszCLSID); + if (hr == S_OK) + { + wcscpy(&buffer[6], pwszCLSID); + TRACE("buffer %s\n", debugstr_w(buffer)); + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, buffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + EnumerateDynamicContextHandlerForKey(This, hKey); + SH_AddStaticEntryForFileClass(This, buffer); + RegCloseKey(hKey); + } + CoTaskMemFree(pwszCLSID); + } + } + + + if (_ILIsDrive(This->dcm.apidl[0])) + { + SH_AddStaticEntryForFileClass(This, L"Drive"); + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Drive", 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + EnumerateDynamicContextHandlerForKey(This, hKey); + RegCloseKey(hKey); + } + } + + + /* add static actions */ + rfg = SFGAO_BROWSABLE | SFGAO_CANCOPY | SFGAO_CANLINK | SFGAO_CANMOVE | SFGAO_CANDELETE | SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_FILESYSTEM; + hr = IShellFolder_GetAttributesOf(This->dcm.psf, This->dcm.cidl, This->dcm.apidl, &rfg); + if (!SUCCEEDED(hr)) + rfg = 0; + + if (rfg & SFGAO_FILESYSTEM) + { + if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"AllFilesystemObjects", 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + /* sendto service is registered there */ + EnumerateDynamicContextHandlerForKey(This, hKey); + RegCloseKey(hKey); + } + } + + /* add static context menu handlers */ + indexMenu = AddStaticContextMenusToMenu(hMenu, 0, This); + /* now process dynamic context menu handlers */ + indexMenu = InsertMenuItemsOfDynamicContextMenuExtension(This, hMenu, indexMenu, iIdCmdFirst, iIdCmdLast); + TRACE("indexMenu %d\n", indexMenu); + + hLocalMenu = LoadMenuW(shell32_hInstance, L"MENU_SHV_FILE"); + if (!hLocalMenu) + { + return iIdCmdLast; + } + + if (rfg & (SFGAO_CANCOPY | SFGAO_CANMOVE)) + { + _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); + if (rfg & SFGAO_CANMOVE) + _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_CUT, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_CUT, sBuffer), MFS_ENABLED); + if (rfg & SFGAO_CANCOPY) + _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_COPY, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_COPY, sBuffer), MFS_ENABLED); + } + + bAddSep = TRUE; + if (rfg & SFGAO_CANLINK) + { + bAddSep = FALSE; + _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); + _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_CREATELINK, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_CREATELINK, sBuffer), MFS_ENABLED); + } + + + if (rfg & SFGAO_CANDELETE) + { + if (bAddSep) + { + bAddSep = FALSE; + _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); + } + _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_DELETE, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_DELETE, sBuffer), MFS_ENABLED); + } + + if (rfg & SFGAO_CANRENAME) + { + if (bAddSep) + { + bAddSep = FALSE; + _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); + } + _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_RENAME, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_RENAME, sBuffer), MFS_ENABLED); + } + + _InsertMenuItem(hMenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0); + _InsertMenuItem(hMenu, indexMenu++, TRUE, FCIDM_SHVIEW_PROPERTIES, MFT_STRING, GetLocalizedString(hLocalMenu, FCIDM_SHVIEW_PROPERTIES, sBuffer), MFS_ENABLED); + + DestroyMenu(hLocalMenu); + return iIdCmdLast; +} + +static +HRESULT +WINAPI +IDefaultContextMenu_fnQueryContextMenu( + IContextMenu2 *iface, + HMENU hmenu, + UINT indexMenu, + UINT idCmdFirst, + UINT idCmdLast, + UINT uFlags) +{ + IDefaultContextMenuImpl * This = impl_from_IContextMenu(iface); + + if (This->dcm.cidl) + { + idCmdFirst = BuildShellItemContextMenu(This, hmenu, idCmdFirst, idCmdLast, uFlags); + } + else + { + idCmdFirst = BuildBackgroundContextMenu(This, hmenu, idCmdFirst, idCmdLast, uFlags); + } + + return S_OK; +} + +static +HRESULT +NotifyShellViewWindow(LPCMINVOKECOMMANDINFO lpcmi) +{ + LPSHELLBROWSER lpSB; + LPSHELLVIEW lpSV = NULL; + HWND hwndSV = NULL; + + if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0))) + { + if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV))) + { + IShellView_GetWindow(lpSV, &hwndSV); + } + } + + if (LOWORD(lpcmi->lpVerb) == FCIDM_SHVIEW_REFRESH) + { + if (lpSV) + IShellView_Refresh(lpSV); + + return S_OK; + } + + SendMessageW(hwndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0), 0); + + return S_OK; +} + +static +HRESULT +DoPaste( + IDefaultContextMenuImpl *iface, + LPCMINVOKECOMMANDINFO lpcmi) +{ + + + return E_FAIL; +} + +static +HRESULT +DoOpenOrExplore( + IDefaultContextMenuImpl *iface, + LPCMINVOKECOMMANDINFO lpcmi) +{ + + + return E_FAIL; +} + +static +HRESULT +DoCopyOrCut( + IDefaultContextMenuImpl *iface, + LPCMINVOKECOMMANDINFO lpcmi) +{ + + + return E_FAIL; +} + +static +HRESULT +DoCreateLink( + IDefaultContextMenuImpl *iface) +{ + + + return E_FAIL; +} + +static +HRESULT +DoDelete( + IDefaultContextMenuImpl *iface) +{ + + + return E_FAIL; +} + +static +HRESULT +DoRename( + IDefaultContextMenuImpl *iface) +{ + + + return E_FAIL; +} + +static +HRESULT +DoProperties( + IDefaultContextMenuImpl *iface, + LPCMINVOKECOMMANDINFO lpcmi) +{ + + + return E_FAIL; +} + +static +HRESULT +DoDynamicShellExtensions( + IDefaultContextMenuImpl *iface, + LPCMINVOKECOMMANDINFO lpcmi) +{ + + + return E_FAIL; +} + + +static +HRESULT +DoStaticShellExtensions( + IDefaultContextMenuImpl *This, + LPCMINVOKECOMMANDINFO lpcmi) +{ + SHELLEXECUTEINFOW sei; + PStaticShellEntry pCurrent = This->shead; + int verb = LOWORD(lpcmi->lpVerb) - This->iIdSCMFirst; + + + while(pCurrent && verb-- > 0) + pCurrent = pCurrent->Next; + + if (verb > 0) + return E_FAIL; + + + ZeroMemory(&sei, sizeof(sei)); + sei.cbSize = sizeof(sei); + sei.fMask = SEE_MASK_CLASSNAME; + sei.lpClass = pCurrent->szClass; + sei.hwnd = lpcmi->hwnd; + sei.nShow = SW_SHOWNORMAL; + sei.lpVerb = pCurrent->szVerb; + ShellExecuteExW(&sei); + return S_OK; + + +} + +static +HRESULT +WINAPI +IDefaultContextMenu_fnInvokeCommand( + IContextMenu2 *iface, + LPCMINVOKECOMMANDINFO lpcmi) +{ + IDefaultContextMenuImpl * This = impl_from_IContextMenu(iface); + + switch(LOWORD(lpcmi->lpVerb)) + { + case FCIDM_SHVIEW_BIGICON: + case FCIDM_SHVIEW_SMALLICON: + case FCIDM_SHVIEW_LISTVIEW: + case FCIDM_SHVIEW_REPORTVIEW: + case 0x30: /* FIX IDS in resource files */ + case 0x31: + case 0x32: + case 0x33: + case FCIDM_SHVIEW_AUTOARRANGE: + case FCIDM_SHVIEW_SNAPTOGRID: + case FCIDM_SHVIEW_REFRESH: + return NotifyShellViewWindow(lpcmi); + case FCIDM_SHVIEW_INSERT: + case FCIDM_SHVIEW_INSERTLINK: + return DoPaste(This, lpcmi); + case FCIDM_SHVIEW_OPEN: + case FCIDM_SHVIEW_EXPLORE: + return DoOpenOrExplore(This, lpcmi); + case FCIDM_SHVIEW_COPY: + case FCIDM_SHVIEW_CUT: + return DoCopyOrCut(This, lpcmi); + case FCIDM_SHVIEW_CREATELINK: + return DoCreateLink(This); + case FCIDM_SHVIEW_DELETE: + return DoDelete(This); + case FCIDM_SHVIEW_RENAME: + return DoRename(This); + case FCIDM_SHVIEW_PROPERTIES: + return DoProperties(This, lpcmi); + } + + if (This->iIdSHEFirst && This->iIdSHELast) + { + if (LOWORD(lpcmi->lpVerb) >= This->iIdSHEFirst && LOWORD(lpcmi->lpVerb) <= This->iIdSHELast) + { + return DoDynamicShellExtensions(This, lpcmi); + } + } + + if (This->iIdSCMFirst && This->iIdSCMLast) + { + if (LOWORD(lpcmi->lpVerb) >= This->iIdSCMFirst && LOWORD(lpcmi->lpVerb) <= This->iIdSCMLast) + { + return DoStaticShellExtensions(This, lpcmi); + } + } + + FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi->lpVerb)); + return E_UNEXPECTED; +} + +static +HRESULT +WINAPI +IDefaultContextMenu_fnGetCommandString( + IContextMenu2 *iface, + UINT_PTR idCommand, + UINT uFlags, + UINT* lpReserved, + LPSTR lpszName, + UINT uMaxNameLen) +{ + + return S_OK; +} + +static +HRESULT +WINAPI +IDefaultContextMenu_fnHandleMenuMsg( + IContextMenu2 *iface, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + + return S_OK; +} + +static const IContextMenu2Vtbl cmvt = +{ + IDefaultContextMenu_fnQueryInterface, + IDefaultContextMenu_fnAddRef, + IDefaultContextMenu_fnRelease, + IDefaultContextMenu_fnQueryContextMenu, + IDefaultContextMenu_fnInvokeCommand, + IDefaultContextMenu_fnGetCommandString, + IDefaultContextMenu_fnHandleMenuMsg +}; + +static +HRESULT +IDefaultContextMenu_Constructor( + const DEFCONTEXTMENU *pdcm, + REFIID riid, + void **ppv) +{ + IDefaultContextMenuImpl * This; + HRESULT hr = E_FAIL; + IDataObject * pDataObj; + + This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDefaultContextMenuImpl)); + if (This) + { + This->lpVtbl = &cmvt; + This->ref = 1; + TRACE("cidl %u\n", This->dcm.cidl); + if (SUCCEEDED(SHCreateDataObject(pdcm->pidlFolder, pdcm->cidl, pdcm->apidl, NULL, &IID_IDataObject, (void**)&pDataObj))) + { + This->pDataObj = pDataObj; + } + CopyMemory(&This->dcm, pdcm, sizeof(DEFCONTEXTMENU)); + hr = IDefaultContextMenu_fnQueryInterface((IContextMenu2*)This, riid, ppv); + } + + TRACE("This(%p)(%x) cidl %u\n",This, hr, This->dcm.cidl); + return hr; +} + + +/************************************************************************* + * SHCreateDefaultContextMenu [SHELL32.325] Vista API + * + */ + +HRESULT +WINAPI +SHCreateDefaultContextMenu( + const DEFCONTEXTMENU *pdcm, + REFIID riid, + void **ppv) +{ +#if 1 + HRESULT hr = E_FAIL; + + *ppv = NULL; + hr = IDefaultContextMenu_Constructor( pdcm, riid, ppv ); + + TRACE("pcm %p hr %x\n", pdcm, hr); + return hr; +#else + HRESULT hr; + IContextMenu2 * pcm; + + if (pdcm->cidl > 0) + pcm = ISvItemCm_Constructor( pdcm->psf, pdcm->pidlFolder, pdcm->apidl, pdcm->cidl ); + else + pcm = ISvBgCm_Constructor( pdcm->psf, TRUE ); + + hr = S_OK; + *ppv = pcm; + + return hr; +#endif +} + +/************************************************************************* + * CDefFolderMenu_Create2 [SHELL32.701] + * + */ + +INT +WINAPI +CDefFolderMenu_Create2( + LPCITEMIDLIST pidlFolder, + HWND hwnd, + UINT cidl, + LPCITEMIDLIST *apidl, + IShellFolder *psf, + LPFNDFMCALLBACK lpfn, + UINT nKeys, + HKEY *ahkeyClsKeys, + IContextMenu **ppcm) +{ + DEFCONTEXTMENU pdcm; + HRESULT hr; + + pdcm.hwnd = hwnd; + pdcm.pcmcb = NULL; + pdcm.pidlFolder = pidlFolder; + pdcm.psf = psf; + pdcm.cidl = cidl; + pdcm.apidl = apidl; + pdcm.punkAssociationInfo = NULL; + pdcm.cKeys = nKeys; + pdcm.aKeys = ahkeyClsKeys; + + hr = SHCreateDefaultContextMenu(&pdcm, &IID_IContextMenu, (void**)ppcm); + return hr; +} + Propchange: trunk/reactos/dll/win32/shell32/shv_default_context_menu.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/reactos/dll/win32/shell32/shv_item_cmenu.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shv_item…
============================================================================== --- trunk/reactos/dll/win32/shell32/shv_item_cmenu.c (original) +++ trunk/reactos/dll/win32/shell32/shv_item_cmenu.c Wed Jan 2 02:34:28 2008 @@ -1262,62 +1262,3 @@ RegCloseKey(hKey); return index; } - -/************************************************************************* - * SHCreateDefaultContextMenu [SHELL32.325] Vista API - * - */ - -HRESULT WINAPI SHCreateDefaultContextMenu( - const DEFCONTEXTMENU *pdcm, - REFIID riid, - void **ppv) -{ - HRESULT hr; - IContextMenu2 * pcm; - - if (pdcm->cidl > 0) - pcm = ISvItemCm_Constructor( pdcm->psf, pdcm->pidlFolder, pdcm->apidl, pdcm->cidl ); - else - pcm = ISvBgCm_Constructor( pdcm->psf, TRUE ); - - hr = S_OK; - *ppv = pcm; - - return hr; -} - -/************************************************************************* - * CDefFolderMenu_Create2 [SHELL32.701] - * - */ - -INT -WINAPI -CDefFolderMenu_Create2( - LPCITEMIDLIST pidlFolder, - HWND hwnd, - UINT cidl, - LPCITEMIDLIST *apidl, - IShellFolder *psf, - LPFNDFMCALLBACK lpfn, - UINT nKeys, - HKEY *ahkeyClsKeys, - IContextMenu **ppcm) -{ - DEFCONTEXTMENU pdcm; - HRESULT hr; - - pdcm.hwnd = hwnd; - pdcm.pcmcb = NULL; //FIXME - pdcm.pidlFolder = pidlFolder; - pdcm.psf = psf; - pdcm.cidl = cidl; - pdcm.apidl = apidl; - pdcm.punkAssociationInfo = NULL; - pdcm.cKeys = nKeys; - pdcm.aKeys = ahkeyClsKeys; - - hr = SHCreateDefaultContextMenu(&pdcm, &IID_IContextMenu, (void**)ppcm); - return hr; -}
17 years
1
0
0
0
[akorotaev] 31546: One more try to fix branch build
by akorotaev@svn.reactos.org
Author: akorotaev Date: Wed Jan 2 02:32:34 2008 New Revision: 31546 URL:
http://svn.reactos.org/svn/reactos?rev=31546&view=rev
Log: One more try to fix branch build Modified: branches/cache_manager_rewrite/cc/mdl.c branches/cache_manager_rewrite/headers.patch Modified: branches/cache_manager_rewrite/cc/mdl.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/cc/mdl.c?…
============================================================================== --- branches/cache_manager_rewrite/cc/mdl.c (original) +++ branches/cache_manager_rewrite/cc/mdl.c Wed Jan 2 02:32:34 2008 @@ -96,7 +96,7 @@ } /* Use slow path */ - CcMdlReadCompleteDev (MdlChain, FileObject); + CcMdlReadComplete2 (MdlChain, FileObject); } /* @@ -122,7 +122,7 @@ } /* Use slow path */ - CcMdlWriteCompleteDev (FileObject, FileOffset, MdlChain); + CcMdlWriteComplete2 (FileObject, FileOffset, MdlChain); } /* Modified: branches/cache_manager_rewrite/headers.patch URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/headers.p…
============================================================================== --- branches/cache_manager_rewrite/headers.patch (original) +++ branches/cache_manager_rewrite/headers.patch Wed Jan 2 02:32:34 2008 @@ -1,3 +1,15 @@ +Index: include/reactos/exeformat.h +=================================================================== +--- include/reactos/exeformat.h (revision 31533) ++++ include/reactos/exeformat.h (working copy) +@@ -35,6 +35,7 @@ + typedef NTSTATUS (NTAPI * PEXEFMT_CB_READ_FILE) + ( + IN PVOID File, ++ ULONG SectorSize, + IN PLARGE_INTEGER Offset, + IN ULONG Length, + OUT PVOID * Data, Index: ntoskrnl/include/internal/mm.h =================================================================== --- ntoskrnl/include/internal/mm.h (revision 31533) @@ -126,6 +138,19 @@ CcCanIWrite@16 CcCopyRead@24 CcCopyWrite@20 +Index: drivers/filesystems/cdfs/cdfs.h +=================================================================== +--- drivers/filesystems/cdfs/cdfs.h (revision 31533) ++++ drivers/filesystems/cdfs/cdfs.h (working copy) +@@ -6,7 +6,7 @@ + #include <ntddcdrm.h> + #include <ccros.h> + +-#define USE_ROS_CC_AND_FS ++//#define USE_ROS_CC_AND_FS + + #define CDFS_BASIC_SECTOR 2048 + #define CDFS_PRIMARY_DESCRIPTOR_LOCATION 16 Index: drivers/filesystems/vfat/vfat.h =================================================================== --- drivers/filesystems/vfat/vfat.h (revision 31533)
17 years
1
0
0
0
[janderwald] 31545: - register the network folder location shell folder
by janderwald@svn.reactos.org
Author: janderwald Date: Wed Jan 2 02:30:18 2008 New Revision: 31545 URL:
http://svn.reactos.org/svn/reactos?rev=31545&view=rev
Log: - register the network folder location shell folder Modified: trunk/reactos/boot/bootdata/hivedef.inf trunk/reactos/boot/bootdata/hivesft.inf Modified: trunk/reactos/boot/bootdata/hivedef.inf URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/hivedef.inf?…
============================================================================== --- trunk/reactos/boot/bootdata/hivedef.inf (original) +++ trunk/reactos/boot/bootdata/hivedef.inf Wed Jan 2 02:30:18 2008 @@ -49,6 +49,9 @@ HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",,0x00000012 HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders",,0x00000012 HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts",,0x00000012 +HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons",,0x00000012 +HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu",,0x00000012 +HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu","{208D2C60-3AEA-1069-A2D7-08002B30309D}",0x00010001,0x00000000 HKCU,"Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}",,0x00000012 Modified: trunk/reactos/boot/bootdata/hivesft.inf URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/hivesft.inf?…
============================================================================== --- trunk/reactos/boot/bootdata/hivesft.inf (original) +++ trunk/reactos/boot/bootdata/hivesft.inf Wed Jan 2 02:30:18 2008 @@ -7,6 +7,9 @@ HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",,0x00000012 HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders",,0x00000012 HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce",,0x00000012 +HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons",,0x00000012 +HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu",,0x00000012 +HKCU,"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu","{208D2C60-3AEA-1069-A2D7-08002B30309D}",0x00010001,0x00000000 ; CMD Settings HKLM,"SOFTWARE\Microsoft\Command Processor","AutoRun",0x00020000,""
17 years
1
0
0
0
[ekohl] 31544: - Rotate the text around its center.
by ekohl@svn.reactos.org
Author: ekohl Date: Wed Jan 2 01:59:06 2008 New Revision: 31544 URL:
http://svn.reactos.org/svn/reactos?rev=31544&view=rev
Log: - Rotate the text around its center. Modified: trunk/reactos/base/applications/screensavers/3dtext/3dtext.c Modified: trunk/reactos/base/applications/screensavers/3dtext/3dtext.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/screensa…
============================================================================== --- trunk/reactos/base/applications/screensavers/3dtext/3dtext.c (original) +++ trunk/reactos/base/applications/screensavers/3dtext/3dtext.c Wed Jan 2 01:59:06 2008 @@ -32,6 +32,8 @@ GLuint base; // Base Display List For The Font Set GLfloat rot; // Used To Rotate The Text +GLfloat extentX = 0.0f; +GLfloat extentY = 0.0f; #define APPNAME _T("3DText") @@ -45,6 +47,12 @@ GLYPHMETRICSFLOAT gmf[256]; // Windows Font Handle HFONT font; + int i; + TCHAR c; + GLfloat cellOriginX = 0.0f; + GLfloat stringOriginX; + GLfloat stringExtentX = 0.0f; + GLfloat stringExtentY = 0.0f; // Storage For 256 Characters base = glGenLists(256); @@ -75,6 +83,23 @@ 0.2f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines gmf); // Address Of Buffer To Recieve Data + + // Calculate the string extent + for (i = 0; i < _tcslen(m_Text); i++) + { + c = m_Text[i]; + + stringOriginX = cellOriginX + gmf[c].gmfptGlyphOrigin.x; + + stringExtentX = stringOriginX + gmf[c].gmfBlackBoxX; + if (gmf[c].gmfBlackBoxY > stringExtentY) + stringExtentY = gmf[c].gmfBlackBoxY; + + cellOriginX = cellOriginX + gmf[c].gmfCellIncX; + } + + extentX = stringExtentX; + extentY = stringExtentY; } // Delete The Font @@ -201,7 +226,9 @@ glRotatef(rot * 1.4f, 0.0f, 0.0f, 1.0f); // Move to the Left and Down before drawing - glTranslatef(-3.5f, 0.0f, 0.0f); + glTranslatef(-(extentX / 2.0f), + -(extentY / 2.0f), + 0.0f); // Pulsing Colors Based On The Rotation glColor3f((1.0f * (cos(rot / 20.0f))),
17 years
1
0
0
0
[akorotaev] 31543: Update headers patch
by akorotaev@svn.reactos.org
Author: akorotaev Date: Wed Jan 2 01:25:57 2008 New Revision: 31543 URL:
http://svn.reactos.org/svn/reactos?rev=31543&view=rev
Log: Update headers patch Modified: branches/cache_manager_rewrite/headers.patch Modified: branches/cache_manager_rewrite/headers.patch URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/headers.p…
============================================================================== --- branches/cache_manager_rewrite/headers.patch (original) +++ branches/cache_manager_rewrite/headers.patch Wed Jan 2 01:25:57 2008 @@ -1,61 +1,71 @@ -Index: drivers/filesystems/cdfs/cdfs.h -=================================================================== ---- drivers/filesystems/cdfs/cdfs.h (revision 22988) -+++ drivers/filesystems/cdfs/cdfs.h (working copy) -@@ -6,7 +6,7 @@ - #include <ntddcdrm.h> - #include <ccros.h> +Index: ntoskrnl/include/internal/mm.h +=================================================================== +--- ntoskrnl/include/internal/mm.h (revision 31533) ++++ ntoskrnl/include/internal/mm.h (working copy) +@@ -176,6 +176,9 @@ + ULONG Flags; + ULONG Characteristics; + BOOLEAN WriteCopy; ++ LIST_ENTRY ListEntry; ++ ULONG BytesPerSector; ++ PFILE_OBJECT FileObject; + } MM_SECTION_SEGMENT, *PMM_SECTION_SEGMENT; --#define USE_ROS_CC_AND_FS -+//#define USE_ROS_CC_AND_FS + typedef struct _MM_IMAGE_SECTION_OBJECT +@@ -192,6 +195,10 @@ + BOOLEAN Executable; + ULONG NrSegments; + ULONG ImageSize; ++ ULONG RefCount; ++ LIST_ENTRY ListEntry; ++ PFILE_OBJECT FileObject; ++ ULONG BytesPerSector; + PMM_SECTION_SEGMENT Segments; + } MM_IMAGE_SECTION_OBJECT, *PMM_IMAGE_SECTION_OBJECT; - #define CDFS_BASIC_SECTOR 2048 - #define CDFS_PRIMARY_DESCRIPTOR_LOCATION 16 -Index: drivers/filesystems/ntfs/ntfs.h -=================================================================== ---- drivers/filesystems/ntfs/ntfs.h (revision 22988) -+++ drivers/filesystems/ntfs/ntfs.h (working copy) -@@ -6,7 +6,7 @@ - #include <ntdddisk.h> - #include <ccros.h> +@@ -210,6 +217,16 @@ + }; + } ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT; --#define USE_ROS_CC_AND_FS -+//#define USE_ROS_CC_AND_FS - - - #define CACHEPAGESIZE(pDeviceExt) \ -Index: drivers/filesystems/vfat/vfat.h -=================================================================== ---- drivers/filesystems/vfat/vfat.h (revision 25241) -+++ drivers/filesystems/vfat/vfat.h (working copy) -@@ -6,7 +6,7 @@ - #ifdef __GNUC__ - #include <ccros.h> - --#define USE_ROS_CC_AND_FS -+//#define USE_ROS_CC_AND_FS - #else - #define KEBUGCHECK KeBugCheck - #define KEBUGCHECKEX KeBugCheckEx -Index: include/reactos/exeformat.h -=================================================================== ---- include/reactos/exeformat.h (revision 22988) -+++ include/reactos/exeformat.h (working copy) -@@ -35,6 +35,7 @@ - typedef NTSTATUS (NTAPI * PEXEFMT_CB_READ_FILE) - ( - IN PVOID File, -+ ULONG SectorSize, - IN PLARGE_INTEGER Offset, - IN ULONG Length, - OUT PVOID * Data, -Index: ntoskrnl/include/internal/cc.h -=================================================================== ---- ntoskrnl/include/internal/cc.h (revision 22988) -+++ ntoskrnl/include/internal/cc.h (working copy) -@@ -1,17 +1,29 @@ - #ifndef __INCLUDE_INTERNAL_CC_H - #define __INCLUDE_INTERNAL_CC_H ++typedef struct ++{ ++ ROS_SECTION_OBJECT* Section; ++ ULONG ViewOffset; ++ LIST_ENTRY ViewListEntry; ++ PMM_SECTION_SEGMENT Segment; ++// BOOLEAN WriteCopyView; ++ LIST_ENTRY RegionListHead; ++} SECTION_DATA, *PSECTION_DATA; ++ + typedef struct _MEMORY_AREA + { + PVOID StartingAddress; +@@ -224,17 +241,10 @@ + ULONG PageOpCount; + union + { ++ SECTION_DATA SectionData; + struct + { +- ROS_SECTION_OBJECT* Section; +- ULONG ViewOffset; +- PMM_SECTION_SEGMENT Segment; +- BOOLEAN WriteCopyView; + LIST_ENTRY RegionListHead; +- } SectionData; +- struct +- { +- LIST_ENTRY RegionListHead; + } VirtualMemoryData; + } Data; + } MEMORY_AREA, *PMEMORY_AREA; +Index: ntoskrnl/include/internal/cc.h +=================================================================== +--- ntoskrnl/include/internal/cc.h (revision 31533) ++++ ntoskrnl/include/internal/cc.h (working copy) +@@ -102,17 +102,29 @@ + LONG ActivePrefetches; + } PFSN_PREFETCHER_GLOBALS, *PPFSN_PREFETCHER_GLOBALS; +#define CACHE_VIEW_SIZE (128 * 1024) // 128kB + @@ -91,7 +101,7 @@ ULONG RefCount; #if defined(DBG) || defined(KDBG) BOOLEAN Trace; /* enable extra trace output for this BCB and it's cache segments */ -@@ -56,8 +68,8 @@ +@@ -157,8 +169,8 @@ typedef struct _INTERNAL_BCB { PUBLIC_BCB PFCB; @@ -102,72 +112,11 @@ CSHORT RefCount; /* (At offset 0x34 on WinNT4) */ } INTERNAL_BCB, *PINTERNAL_BCB; -Index: ntoskrnl/include/internal/mm.h -=================================================================== ---- ntoskrnl/include/internal/mm.h (revision 22988) -+++ ntoskrnl/include/internal/mm.h (working copy) -@@ -176,6 +176,9 @@ - ULONG Flags; - ULONG Characteristics; - BOOLEAN WriteCopy; -+ LIST_ENTRY ListEntry; -+ ULONG BytesPerSector; -+ PFILE_OBJECT FileObject; - } MM_SECTION_SEGMENT, *PMM_SECTION_SEGMENT; - - typedef struct _MM_IMAGE_SECTION_OBJECT -@@ -191,6 +194,10 @@ - USHORT Machine; - BOOLEAN Executable; - ULONG NrSegments; -+ ULONG RefCount; -+ LIST_ENTRY ListEntry; -+ PFILE_OBJECT FileObject; -+ ULONG BytesPerSector; - PMM_SECTION_SEGMENT Segments; - } MM_IMAGE_SECTION_OBJECT, *PMM_IMAGE_SECTION_OBJECT; - -@@ -209,6 +216,16 @@ - }; - } ROS_SECTION_OBJECT, *PROS_SECTION_OBJECT; - -+typedef struct -+{ -+ ROS_SECTION_OBJECT* Section; -+ ULONG ViewOffset; -+ LIST_ENTRY ViewListEntry; -+ PMM_SECTION_SEGMENT Segment; -+// BOOLEAN WriteCopyView; -+ LIST_ENTRY RegionListHead; -+} SECTION_DATA, *PSECTION_DATA; -+ - typedef struct _MEMORY_AREA - { - PVOID StartingAddress; -@@ -223,17 +240,10 @@ - ULONG PageOpCount; - union - { -+ SECTION_DATA SectionData; - struct - { -- ROS_SECTION_OBJECT* Section; -- ULONG ViewOffset; -- PMM_SECTION_SEGMENT Segment; -- BOOLEAN WriteCopyView; - LIST_ENTRY RegionListHead; -- } SectionData; -- struct -- { -- LIST_ENTRY RegionListHead; - } VirtualMemoryData; - } Data; - } MEMORY_AREA, *PMEMORY_AREA; -Index: ntoskrnl/ntoskrnl.def -=================================================================== ---- ntoskrnl/ntoskrnl.def (revision 22988) -+++ ntoskrnl/ntoskrnl.def (working copy) -@@ -5,9 +5,6 @@ +Index: ntoskrnl/ntoskrnl.def +=================================================================== +--- ntoskrnl/ntoskrnl.def (revision 31533) ++++ ntoskrnl/ntoskrnl.def (working copy) +@@ -5,9 +5,6 @@ ; ReactOS Operating System ; EXPORTS @@ -177,3 +126,29 @@ CcCanIWrite@16 CcCopyRead@24 CcCopyWrite@20 +Index: drivers/filesystems/vfat/vfat.h +=================================================================== +--- drivers/filesystems/vfat/vfat.h (revision 31533) ++++ drivers/filesystems/vfat/vfat.h (working copy) +@@ -6,7 +6,7 @@ + #ifdef __GNUC__ + #include <ccros.h> + +-#define USE_ROS_CC_AND_FS ++//#define USE_ROS_CC_AND_FS + #else + #define KEBUGCHECK KeBugCheck + #define KEBUGCHECKEX KeBugCheckEx +Index: drivers/filesystems/ntfs/ntfs.h +=================================================================== +--- drivers/filesystems/ntfs/ntfs.h (revision 31533) ++++ drivers/filesystems/ntfs/ntfs.h (working copy) +@@ -6,7 +6,7 @@ + #include <ntdddisk.h> + #include <ccros.h> + +-#define USE_ROS_CC_AND_FS ++//#define USE_ROS_CC_AND_FS + + + #define CACHEPAGESIZE(pDeviceExt) \
17 years
1
0
0
0
[ekohl] 31542: [FORMATTING] Fix indentation and move comments
by ekohl@svn.reactos.org
Author: ekohl Date: Wed Jan 2 01:15:10 2008 New Revision: 31542 URL:
http://svn.reactos.org/svn/reactos?rev=31542&view=rev
Log: [FORMATTING] Fix indentation and move comments Modified: trunk/reactos/base/applications/screensavers/3dtext/3dtext.c Modified: trunk/reactos/base/applications/screensavers/3dtext/3dtext.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/screensa…
============================================================================== --- trunk/reactos/base/applications/screensavers/3dtext/3dtext.c (original) +++ trunk/reactos/base/applications/screensavers/3dtext/3dtext.c Wed Jan 2 01:15:10 2008 @@ -18,416 +18,524 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#include <windows.h> // Header File For Windows -#include <math.h> // Header File For Windows Math Library -#include <GL/gl.h> // Header File For The OpenGL32 Library -#include <GL/glu.h> // Header File For The GLu32 Library +#include <windows.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glu.h> #include <tchar.h> #include "resource.h" #include "3dtext.h" -static HGLRC hRC; // Permanent Rendering Context -static HDC hDC; // Private GDI Device Context - -GLuint base; // Base Display List For The Font Set -GLfloat rot; // Used To Rotate The Text +static HGLRC hRC; // Permanent Rendering Context +static HDC hDC; // Private GDI Device Context + +GLuint base; // Base Display List For The Font Set +GLfloat rot; // Used To Rotate The Text #define APPNAME _T("3DText") HINSTANCE hInstance; BOOL fullscreen = FALSE; -GLvoid BuildFont(GLvoid) // Build Our Bitmap Font -{ - GLYPHMETRICSFLOAT gmf[256]; // Address Buffer For Font Storage - HFONT font; // Windows Font ID - - base = glGenLists(256); // Storage For 256 Characters - - font = CreateFont( -12, // Height Of Font - 0, // Width Of Font - 0, // Angle Of Escapement - 0, // Orientation Angle - FW_BOLD, // Font Weight - FALSE, // Italic - FALSE, // Underline - FALSE, // Strikeout - DEFAULT_CHARSET, // Character Set Identifier - OUT_TT_PRECIS, // Output Precision - CLIP_DEFAULT_PRECIS, // Clipping Precision - ANTIALIASED_QUALITY, // Output Quality - FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch - _T("Tahoma")); // Font Name - - SelectObject(hDC, font); // Selects The Font We Created - - wglUseFontOutlines( hDC, // Select The Current DC - 0, // Starting Character - 255, // Number Of Display Lists To Build - base, // Starting Display Lists - 0.0f, // Deviation From The True Outlines - 0.2f, // Font Thickness In The Z Direction - WGL_FONT_POLYGONS, // Use Polygons, Not Lines - gmf); // Address Of Buffer To Recieve Data -} - -GLvoid KillFont(GLvoid) // Delete The Font -{ - glDeleteLists(base, 256); // Delete All 256 Characters -} - -GLvoid glPrint(LPTSTR text) // Custom GL "Print" Routine -{ - if (text == NULL) // If There's No Text - return; // Do Nothing - - glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits - glListBase(base); // Sets The Base Character to 32 - - glCallLists(_tcslen(text), -#ifdef UNICODE - GL_UNSIGNED_SHORT +// Build Our Bitmap Font +GLvoid BuildFont(GLvoid) +{ + // Address Buffer For Font Storage + GLYPHMETRICSFLOAT gmf[256]; + // Windows Font Handle + HFONT font; + + // Storage For 256 Characters + base = glGenLists(256); + + font = CreateFont(-12, + 0, // Width Of Font + 0, // Angle Of Escapement + 0, // Orientation Angle + FW_BOLD, // Font Weight + FALSE, // Italic + FALSE, // Underline + FALSE, // Strikeout + DEFAULT_CHARSET, // Character Set Identifier + OUT_TT_PRECIS, // Output Precision + CLIP_DEFAULT_PRECIS, // Clipping Precision + ANTIALIASED_QUALITY, // Output Quality + FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch + _T("Tahoma")); // Font Name + + // Selects The Font We Created + SelectObject(hDC, font); + + wglUseFontOutlines(hDC, // Select The Current DC + 0, // Starting Character + 255, // Number Of Display Lists To Build + base, // Starting Display Lists + 0.0f, // Deviation From The True Outlines + 0.2f, // Font Thickness In The Z Direction + WGL_FONT_POLYGONS, // Use Polygons, Not Lines + gmf); // Address Of Buffer To Recieve Data +} + +// Delete The Font +GLvoid KillFont(GLvoid) +{ + // Delete all 256 characters + glDeleteLists(base, 256); +} + +// Custom GL "Print" Routine +GLvoid glPrint(LPTSTR text) +{ + // If there's no text, do nothing + if (text == NULL) + return; + + // Pushes The Display List Bits + glPushAttrib(GL_LIST_BIT); + + // Sets The Base Character to 32 + glListBase(base); + + // Draws The Display List Text + glCallLists(_tcslen(text), +#ifdef UNICODE + GL_UNSIGNED_SHORT, #else - GL_UNSIGNED_BYTE + GL_UNSIGNED_BYTE, #endif - , text); // Draws The Display List Text - - glPopAttrib(); // Pops The Display List Bits -} - -GLvoid InitGL(GLsizei Width, GLsizei Height) // Will Be Called Right After The GL Window Is Created -{ - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Clear The Background Color To Black - glClearDepth(1.0); // Enables Clearing Of The Depth Buffer - glDepthFunc(GL_LESS); // The Type Of Depth Test To Do - glEnable(GL_DEPTH_TEST); // Enables Depth Testing - glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading - - glMatrixMode(GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity(); // Reset The Projection Matrix - - // Calculate The Aspect Ratio Of The Window - gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); - - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - - BuildFont(); // Build The Font - glEnable(GL_LIGHT0); // Enable Default Light (Quick And Dirty) - glEnable(GL_LIGHTING); // Enable Lighting - glEnable(GL_COLOR_MATERIAL); // Enable Coloring Of Material -} - -GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height) // Handles Window Resizing -{ - if (Height==0) // Is Window Too Small (Divide By Zero Error) - Height=1; // If So Make It One Pixel Tall - - // Reset The Current Viewport And Perspective Transformation - glViewport(0, 0, Width, Height); - - glMatrixMode(GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity(); // Reset The Projection Matrix - - // Calculate The Aspect Ratio Of The Window - gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix -} - -GLvoid DrawGLScene(GLvoid) // Handles Rendering -{ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer - glLoadIdentity(); // Reset The View - glTranslatef(0.0f,0.0f,-10.0f); // Move One Unit Into The Screen - glRotatef(rot,1.0f,0.0f,0.0f); // Rotate On The X Axis - glRotatef(rot*1.2f,0.0f,1.0f,0.0f); // Rotate On The Y Axis - glRotatef(rot*1.4f,0.0f,0.0f,1.0f); // Rotate On The Z Axis - glTranslatef(-3.5f,0.0f,0.0f); // Move To The Left Before Drawing - // Pulsing Colors Based On The Rotation - glColor3f( - (1.0f*(cos(rot/20.0f))), - (1.0f*(sin(rot/25.0f))), - (1.0f-0.5f*(cos(rot/17.0f)))); - glPrint(m_Text); // Print GL Text To The Screen - glColor3f(0.0f,0.0f,1.0f); // Make The Text Blue - rot+=0.1f; // Increase The Rotation Variable -} - -LRESULT CALLBACK WndProc( HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam) -{ - static POINT ptLast; - static POINT ptCursor; - static BOOL fFirstTime = TRUE; - RECT Screen; // Used Later On To Get The Size Of The Window - GLuint PixelFormat; // Pixel Format Storage - static PIXELFORMATDESCRIPTOR pfd= // Pixel Format Descriptor - { - sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor - 1, // Version Number (?) - PFD_DRAW_TO_WINDOW | // Format Must Support Window - PFD_SUPPORT_OPENGL | // Format Must Support OpenGL - PFD_DOUBLEBUFFER, // Must Support Double Buffering - PFD_TYPE_RGBA, // Request An RGBA Format - 16, // Select A 16Bit Color Depth - 0, 0, 0, 0, 0, 0, // Color Bits Ignored (?) - 0, // No Alpha Buffer - 0, // Shift Bit Ignored (?) - 0, // No Accumulation Buffer - 0, 0, 0, 0, // Accumulation Bits Ignored (?) - 16, // 16Bit Z-Buffer (Depth Buffer) - 0, // No Stencil Buffer - 0, // No Auxiliary Buffer (?) - PFD_MAIN_PLANE, // Main Drawing Layer - 0, // Reserved (?) - 0, 0, 0 // Layer Masks Ignored (?) - }; - - switch (message) // Tells Windows We Want To Check The Message - { - case WM_CREATE: // Window Creation - hDC = GetDC(hWnd); // Gets A Device Context For The Window - PixelFormat = ChoosePixelFormat(hDC, &pfd); // Finds The Closest Match To The Pixel Format We Set Above - - if (!PixelFormat) // No Matching Pixel Format? - { - MessageBox(0,_TEXT("Can't Find A Suitable PixelFormat."),_TEXT("Error"),MB_OK|MB_ICONERROR); - PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit - break; // Prevents The Rest Of The Code From Running - } - - if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Can We Set The Pixel Mode? - { - MessageBox(0,_TEXT("Can't Set The PixelFormat."),_TEXT("Error"),MB_OK|MB_ICONERROR); - PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit - break; // Prevents The Rest Of The Code From Running - } - - hRC = wglCreateContext(hDC); // Grab A Rendering Context - if(!hRC) // Did We Get One? - { - MessageBox(0,_TEXT("Can't Create A GL Rendering Context."),_TEXT("Error"),MB_OK|MB_ICONERROR); - PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit - break; // Prevents The Rest Of The Code From Running - } - - if(!wglMakeCurrent(hDC, hRC)) // Can We Make The RC Active? - { - MessageBox(0,_TEXT("Can't Activate GLRC."),_TEXT("Error"),MB_OK|MB_ICONERROR); - PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit - break; // Prevents The Rest Of The Code From Running - } - - GetClientRect(hWnd, &Screen); // Grab Screen Info For The Current Window - InitGL(Screen.right, Screen.bottom); // Initialize The GL Screen Using Screen Info - break; - - case WM_DESTROY: // Windows Being Destroyed - case WM_CLOSE: // Windows Being Closed - { - ChangeDisplaySettings(NULL, 0); // Disable Fullscreen Mode - KillFont(); // Deletes The Font Display List - - wglMakeCurrent(hDC,NULL); // Make The DC Current - wglDeleteContext(hRC); // Kill The RC - ReleaseDC(hWnd,hDC); // Free The DC - - PostQuitMessage(0); // Quit The Program - } - break; - case WM_PAINT: - { - DrawGLScene(); - SwapBuffers(hDC); - break; - } - case WM_NOTIFY: - case WM_SYSKEYDOWN: - PostMessage(hWnd, WM_CLOSE, 0, 0); - break; - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_MOUSEMOVE: - { - // If we've got a parent then we must be a preview - if(GetParent(hWnd) != 0) - return 0; - - if(fFirstTime) - { - GetCursorPos(&ptLast); - fFirstTime = FALSE; - } - - GetCursorPos(&ptCursor); - - // if the mouse has moved more than 3 pixels then exit - if(abs(ptCursor.x - ptLast.x) >= 3 || abs(ptCursor.y - ptLast.y) >= 3) - PostMessage(hWnd, WM_CLOSE, 0, 0); - - ptLast = ptCursor; - - return 0; - } - case WM_SIZE: // Resizing The Screen - ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // Resize To The New Window Size - break; - - default: - return (DefWindowProc(hWnd, message, wParam, lParam)); // Pass Windows Messages - } -return (0); -} - -void InitSaver(HWND hwndParent) -{ - WNDCLASS wc; - ZeroMemory(&wc, sizeof(wc)); - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = WndProc; - wc.lpszClassName = APPNAME; - RegisterClass(&wc); - - if (hwndParent != 0) - { - RECT rect; - GetClientRect(hwndParent, &rect); - CreateWindow(APPNAME, APPNAME, - WS_VISIBLE | WS_CHILD, - 0, 0, - rect.right, - rect.bottom, - hwndParent, 0, - hInstance, NULL); - fullscreen = FALSE; - } else { - HWND hwnd; - hwnd = CreateWindow(APPNAME, APPNAME, - WS_VISIBLE | WS_POPUP | WS_EX_TOPMOST, - 0, 0, - GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), - HWND_DESKTOP, 0, - hInstance, NULL); - ShowWindow(hwnd, SW_SHOWMAXIMIZED); - ShowCursor(FALSE); - fullscreen = TRUE; - } + text); + + // Pops The Display List Bits + glPopAttrib(); +} + +// Will Be Called Right After The GL Window Is Created +GLvoid InitGL(GLsizei Width, GLsizei Height) +{ + // Clear The Background Color To Black + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + // Enables Clearing Of The Depth Buffer + glClearDepth(1.0); + + // The Type Of Depth Test To Do + glDepthFunc(GL_LESS); + + // Enables Depth Testing + glEnable(GL_DEPTH_TEST); + + // Enables Smooth Color Shading + glShadeModel(GL_SMOOTH); + + // Select The Projection Matrix + glMatrixMode(GL_PROJECTION); + + // Reset The Projection Matrix + glLoadIdentity(); + + // Calculate The Aspect Ratio Of The Window + gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f); + + // Select The Modelview Matrix + glMatrixMode(GL_MODELVIEW); + + // Build The Font + BuildFont(); + + // Enable Default Light (Quick And Dirty) + glEnable(GL_LIGHT0); + + // Enable Lighting + glEnable(GL_LIGHTING); + + // Enable Coloring Of Material + glEnable(GL_COLOR_MATERIAL); +} + +// Handles Window Resizing +GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height) +{ + // Is Window Too Small (Divide By Zero Error) + if (Height == 0) + { + // If So Make It One Pixel Tall + Height = 1; + } + + // Reset The Current Viewport And Perspective Transformation + glViewport(0, 0, Width, Height); + + // Select The Projection Matrix + glMatrixMode(GL_PROJECTION); + + // Reset The Projection Matrix + glLoadIdentity(); + + // Calculate The Aspect Ratio Of The Window + gluPerspective(45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f); + + // Select The Modelview Matrix + glMatrixMode(GL_MODELVIEW); +} + +// Handles Rendering +GLvoid DrawGLScene(GLvoid) +{ + // Clear The Screen And The Depth Buffer + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // Reset The View + glLoadIdentity(); + + // Move One Unit Into The Screen + glTranslatef(0.0f, 0.0f, -10.0f); + + // Rotate On The X Axis + glRotatef(rot, 1.0f, 0.0f, 0.0f); + + // Rotate On The Y Axis + glRotatef(rot * 1.2f, 0.0f, 1.0f, 0.0f); + + // Rotate On The Z Axis + glRotatef(rot * 1.4f, 0.0f, 0.0f, 1.0f); + + // Move to the Left and Down before drawing + glTranslatef(-3.5f, 0.0f, 0.0f); + + // Pulsing Colors Based On The Rotation + glColor3f((1.0f * (cos(rot / 20.0f))), + (1.0f * (sin(rot / 25.0f))), + (1.0f - 0.5f * (cos(rot / 17.0f)))); + + // Print GL Text To The Screen + glPrint(m_Text); + + // Make The Text Blue + glColor3f(0.0f, 0.0f, 1.0f); + + // Increase The Rotation Variable + rot += 0.1f; +} + +LRESULT CALLBACK +WndProc(HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam) +{ + static POINT ptLast; + static POINT ptCursor; + static BOOL fFirstTime = TRUE; + RECT Screen; // Used Later On To Get The Size Of The Window + GLuint PixelFormat; // Pixel Format Storage + static PIXELFORMATDESCRIPTOR pfd= // Pixel Format Descriptor + { + sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor + 1, // Version Number (?) + PFD_DRAW_TO_WINDOW | // Format Must Support Window + PFD_SUPPORT_OPENGL | // Format Must Support OpenGL + PFD_DOUBLEBUFFER, // Must Support Double Buffering + PFD_TYPE_RGBA, // Request An RGBA Format + 16, // Select A 16Bit Color Depth + 0, 0, 0, 0, 0, 0, // Color Bits Ignored (?) + 0, // No Alpha Buffer + 0, // Shift Bit Ignored (?) + 0, // No Accumulation Buffer + 0, 0, 0, 0, // Accumulation Bits Ignored (?) + 16, // 16Bit Z-Buffer (Depth Buffer) + 0, // No Stencil Buffer + 0, // No Auxiliary Buffer (?) + PFD_MAIN_PLANE, // Main Drawing Layer + 0, // Reserved (?) + 0, 0, 0 // Layer Masks Ignored (?) + }; + + switch (message) + { + case WM_CREATE: + // Gets A Device Context For The Window + hDC = GetDC(hWnd); + + // Finds The Closest Match To The Pixel Format We Set Above + PixelFormat = ChoosePixelFormat(hDC, &pfd); + + // No Matching Pixel Format? + if (!PixelFormat) + { + MessageBox(0, _TEXT("Can't Find A Suitable PixelFormat."), _TEXT("Error"),MB_OK | MB_ICONERROR); + + // This Sends A 'Message' Telling The Program To Quit + PostQuitMessage(0); + break; + } + + // Can We Set The Pixel Mode? + if (!SetPixelFormat(hDC, PixelFormat, &pfd)) + { + MessageBox(0, _TEXT("Can't Set The PixelFormat."), _TEXT("Error"), MB_OK | MB_ICONERROR); + + // This Sends A 'Message' Telling The Program To Quit + PostQuitMessage(0); + break; + } + + // Grab A Rendering Context + hRC = wglCreateContext(hDC); + + // Did We Get One? + if (!hRC) + { + MessageBox(0, _TEXT("Can't Create A GL Rendering Context."), _TEXT("Error"), MB_OK | MB_ICONERROR); + + // This Sends A 'Message' Telling The Program To Quit + PostQuitMessage(0); + break; + } + + // Can We Make The RC Active? + if (!wglMakeCurrent(hDC, hRC)) + { + MessageBox(0, _TEXT("Can't Activate GLRC."), _TEXT("Error"), MB_OK | MB_ICONERROR); + + // This Sends A 'Message' Telling The Program To Quit + PostQuitMessage(0); + break; + } + + // Grab Screen Info For The Current Window + GetClientRect(hWnd, &Screen); + + // Initialize The GL Screen Using Screen Info + InitGL(Screen.right, Screen.bottom); + break; + + case WM_DESTROY: + case WM_CLOSE: + // Disable Fullscreen Mode + ChangeDisplaySettings(NULL, 0); + + // Deletes The Font Display List + KillFont(); + + // Make The DC Current + wglMakeCurrent(hDC, NULL); + + // Kill The RC + wglDeleteContext(hRC); + + // Free The DC + ReleaseDC(hWnd, hDC); + + // Quit The Program + PostQuitMessage(0); + break; + + case WM_PAINT: + DrawGLScene(); + SwapBuffers(hDC); + break; + + case WM_NOTIFY: + case WM_SYSKEYDOWN: + PostMessage(hWnd, WM_CLOSE, 0, 0); + break; + + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_MOUSEMOVE: + // If we've got a parent then we must be a preview + if (GetParent(hWnd) != 0) + return 0; + + if (fFirstTime) + { + GetCursorPos(&ptLast); + fFirstTime = FALSE; + } + + GetCursorPos(&ptCursor); + + // if the mouse has moved more than 3 pixels then exit + if (abs(ptCursor.x - ptLast.x) >= 3 || abs(ptCursor.y - ptLast.y) >= 3) + PostMessage(hWnd, WM_CLOSE, 0, 0); + + ptLast = ptCursor; + return 0; + + case WM_SIZE: // Resizing The Screen + // Resize To The New Window Size + ReSizeGLScene(LOWORD(lParam), HIWORD(lParam)); + break; + + default: + // Pass Windows Messages + return DefWindowProc(hWnd, message, wParam, lParam); + } + + return 0; +} + +VOID InitSaver(HWND hwndParent) +{ + WNDCLASS wc; + + ZeroMemory(&wc, sizeof(wc)); + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = WndProc; + wc.lpszClassName = APPNAME; + RegisterClass(&wc); + + if (hwndParent != 0) + { + RECT rect; + + GetClientRect(hwndParent, &rect); + CreateWindow(APPNAME, APPNAME, + WS_VISIBLE | WS_CHILD, + 0, 0, + rect.right, + rect.bottom, + hwndParent, 0, + hInstance, NULL); + fullscreen = FALSE; + } + else + { + HWND hwnd; + hwnd = CreateWindow(APPNAME, APPNAME, + WS_VISIBLE | WS_POPUP | WS_EX_TOPMOST, + 0, 0, + GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), + HWND_DESKTOP, 0, + hInstance, NULL); + ShowWindow(hwnd, SW_SHOWMAXIMIZED); + ShowCursor(FALSE); + fullscreen = TRUE; + } } // -// Look for any options Windows has passed to us: +// Look for any options Windows has passed to us: // -// -a <hwnd> (set password) -// -s (screensave) -// -p <hwnd> (preview) -// -c <hwnd> (configure) +// -a <hwnd> (set password) +// -s (screensave) +// -p <hwnd> (preview) +// -c <hwnd> (configure) // VOID ParseCommandLine(LPTSTR szCmdLine, UCHAR *chOption, HWND *hwndParent) { - TCHAR ch = *szCmdLine++; - - if(ch == _T('-') || ch == _T('/')) - ch = *szCmdLine++; - - if(ch >= _T('A') && ch <= _T('Z')) - ch += _T('a') - _T('A'); //convert to lower case - - *chOption = ch; - ch = *szCmdLine++; - - if(ch == _T(':')) - ch = *szCmdLine++; - - while(ch == _T(' ') || ch == _T('\t')) - ch = *szCmdLine++; - - if(isdigit(ch)) - { - unsigned int i = _ttoi(szCmdLine - 1); - *hwndParent = (HWND)i; - } - else - *hwndParent = NULL; -} + TCHAR ch = *szCmdLine++; + + if (ch == _T('-') || ch == _T('/')) + ch = *szCmdLine++; + + //convert to lower case + if (ch >= _T('A') && ch <= _T('Z')) + ch += _T('a') - _T('A'); + + *chOption = ch; + ch = *szCmdLine++; + + if (ch == _T(':')) + ch = *szCmdLine++; + + while (ch == _T(' ') || ch == _T('\t')) + ch = *szCmdLine++; + + if (_istdigit(ch)) + { + unsigned int i = _ttoi(szCmdLine - 1); + *hwndParent = (HWND)i; + } + else + { + *hwndParent = NULL; + } +} + // -// Dialogbox procedure for Configuration window +// Dialogbox procedure for Configuration window // BOOL CALLBACK ConfigDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch(uMsg) - { + switch (uMsg) + { case WM_INITDIALOG: - SetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text); - return TRUE; + SetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text); + return TRUE; + case WM_COMMAND: - switch(LOWORD(wParam)) + switch (LOWORD(wParam)) { case IDOK: - GetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text, MAX_PATH); - SaveSettings(); + GetDlgItemText(hwnd, IDC_MESSAGE_TEXT, m_Text, MAX_PATH); + SaveSettings(); EndDialog(hwnd, IDOK); - break; + break; + case IDCANCEL: EndDialog(hwnd, IDCANCEL); - break; + break; } - return FALSE; - case WM_CLOSE: - EndDialog(hwnd, 0); - break; + return FALSE; + + case WM_CLOSE: + EndDialog(hwnd, 0); + break; + default: return FALSE; - } - - return TRUE; -} - -void Configure(void) -{ - DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), NULL , (DLGPROC)ConfigDlgProc); -} - -int CALLBACK _tWinMain (HINSTANCE hInst, - HINSTANCE hPrev, - LPTSTR lpCmdLine, - int iCmdShow) -{ - HWND hwndParent = 0; - UCHAR chOption; - MSG Message; - - hInstance = hInst; - - ParseCommandLine(lpCmdLine, &chOption, &hwndParent); - - LoadSettings(); - - switch(chOption) - { - case 's': - InitSaver(0); - break; - - case 'p': - InitSaver(hwndParent); - break; - - case 'c': - default: - Configure(); - return 0; - } - - while (GetMessage(&Message, 0, 0, 0)) - DispatchMessage(&Message); - - return Message.wParam; -} - + } + + return TRUE; +} + +VOID Configure(VOID) +{ + DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), NULL , (DLGPROC)ConfigDlgProc); +} + +INT CALLBACK +_tWinMain(HINSTANCE hInst, + HINSTANCE hPrev, + LPTSTR lpCmdLine, + INT iCmdShow) +{ + HWND hwndParent = 0; + UCHAR chOption; + MSG Message; + + hInstance = hInst; + + ParseCommandLine(lpCmdLine, &chOption, &hwndParent); + + LoadSettings(); + + switch (chOption) + { + case _T('s'): + InitSaver(0); + break; + + case _T('p'): + InitSaver(hwndParent); + break; + + case _T('c'): + default: + Configure(); + return 0; + } + + while (GetMessage(&Message, 0, 0, 0)) + DispatchMessage(&Message); + + return Message.wParam; +} +
17 years
1
0
0
0
[akorotaev] 31541: Make cache_manager_rewrite compilable again (but not linkable yet): - Use ULONG_PTR for arithmetics - Use aspace.c, verifier and virtual.c from trunk (they have just slight difference from branched ones) - Cast Interlocked* functions to avoid warnings - Fix DPRINTs trying to show non-existent variables
by akorotaev@svn.reactos.org
Author: akorotaev Date: Wed Jan 2 00:25:47 2008 New Revision: 31541 URL:
http://svn.reactos.org/svn/reactos?rev=31541&view=rev
Log: Make cache_manager_rewrite compilable again (but not linkable yet): - Use ULONG_PTR for arithmetics - Use aspace.c, verifier and virtual.c from trunk (they have just slight difference from branched ones) - Cast Interlocked* functions to avoid warnings - Fix DPRINTs trying to show non-existent variables Modified: branches/cache_manager_rewrite/cc/cacheman.c branches/cache_manager_rewrite/cc/mdl.c branches/cache_manager_rewrite/cc/pin.c branches/cache_manager_rewrite/mm/anonmem.c branches/cache_manager_rewrite/mm/aspace.c branches/cache_manager_rewrite/mm/mminit.c branches/cache_manager_rewrite/mm/pagefile.c branches/cache_manager_rewrite/mm/pageop.c branches/cache_manager_rewrite/mm/rmap.c branches/cache_manager_rewrite/mm/section.c branches/cache_manager_rewrite/mm/verifier.c branches/cache_manager_rewrite/mm/virtual.c Modified: branches/cache_manager_rewrite/cc/cacheman.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/cc/cachem…
============================================================================== --- branches/cache_manager_rewrite/cc/cacheman.c (original) +++ branches/cache_manager_rewrite/cc/cacheman.c Wed Jan 2 00:25:47 2008 @@ -16,10 +16,11 @@ /* FUNCTIONS *****************************************************************/ -VOID NTAPI +BOOLEAN NTAPI CcInitializeCacheManager (VOID) { CcInitView (); + return TRUE; } /* Modified: branches/cache_manager_rewrite/cc/mdl.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/cc/mdl.c?…
============================================================================== --- branches/cache_manager_rewrite/cc/mdl.c (original) +++ branches/cache_manager_rewrite/cc/mdl.c Wed Jan 2 00:25:47 2008 @@ -122,13 +122,16 @@ } /* Use slow path */ - CcMdlWriteCompleteDev (FileOffset, MdlChain, FileObject); + CcMdlWriteCompleteDev (FileObject, FileOffset, MdlChain); } -VOID STDCALL -CcMdlWriteCompleteDev (IN PLARGE_INTEGER FileOffset, - IN PMDL MdlChain, - IN PFILE_OBJECT FileObject) +/* + * @unimplemented + */ +VOID NTAPI +CcMdlWriteCompleteDev (IN PFILE_OBJECT FileObject, + IN PLARGE_INTEGER FileOffset, + IN PMDL MdlChain) { UNIMPLEMENTED; } Modified: branches/cache_manager_rewrite/cc/pin.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/cc/pin.c?…
============================================================================== --- branches/cache_manager_rewrite/cc/pin.c (original) +++ branches/cache_manager_rewrite/cc/pin.c Wed Jan 2 00:25:47 2008 @@ -45,8 +45,8 @@ PLIST_ENTRY entry; PCACHE_VIEW current = NULL; - DPRINT ("CcMapData(FileObject 0x%p, FileOffset %I64x, Length %d, Wait %d," - " pBcb 0x%p, pBuffer 0x%p)\n", FileObject, FileOffset->QuadPart, Length, Wait, piBcb, pBuffer); + DPRINT ("CcMapData(FileObject 0x%p, FileOffset %I64x, Length %d," + " pBcb 0x%p, pBuffer 0x%p)\n", FileObject, FileOffset->QuadPart, Length, piBcb, pBuffer); ASSERT (FileObject); ASSERT (FileObject->SectionObjectPointer); Modified: branches/cache_manager_rewrite/mm/anonmem.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/anonme…
============================================================================== --- branches/cache_manager_rewrite/mm/anonmem.c (original) +++ branches/cache_manager_rewrite/mm/anonmem.c Wed Jan 2 00:25:47 2008 @@ -628,7 +628,7 @@ BoundaryAddressMultiple.QuadPart = 0; BaseAddress = (PVOID)PAGE_ROUND_DOWN(PBaseAddress); - RegionSize = PAGE_ROUND_UP(PBaseAddress + PRegionSize) - + RegionSize = PAGE_ROUND_UP((ULONG_PTR)PBaseAddress + PRegionSize) - PAGE_ROUND_DOWN(PBaseAddress); /* @@ -899,7 +899,7 @@ *PRegionSize,FreeType); BaseAddress = (PVOID)PAGE_ROUND_DOWN((*PBaseAddress)); - RegionSize = PAGE_ROUND_UP((*PBaseAddress) + (*PRegionSize)) - + RegionSize = PAGE_ROUND_UP((ULONG_PTR)(*PBaseAddress) + (*PRegionSize)) - PAGE_ROUND_DOWN((*PBaseAddress)); Status = ObReferenceObjectByHandle(ProcessHandle, Modified: branches/cache_manager_rewrite/mm/aspace.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/aspace…
============================================================================== --- branches/cache_manager_rewrite/mm/aspace.c (original) +++ branches/cache_manager_rewrite/mm/aspace.c Wed Jan 2 00:25:47 2008 @@ -21,7 +21,7 @@ /* GLOBALS ******************************************************************/ static MADDRESS_SPACE KernelAddressSpace; -FAST_MUTEX KernelAddressSpaceLock; +EX_PUSH_LOCK KernelAddressSpaceLock; /* FUNCTIONS *****************************************************************/ @@ -29,21 +29,13 @@ NTAPI MmLockAddressSpace(PMADDRESS_SPACE AddressSpace) { - /* - * Don't bother with locking if we are the first thread. - */ - if (KeGetCurrentThread() == NULL) - { - return; - } - if (AddressSpace->Process) { - ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&AddressSpace->Process->AddressCreationLock); + ExAcquirePushLockExclusive((PEX_PUSH_LOCK)&AddressSpace->Process->AddressCreationLock); } else { - ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&KernelAddressSpaceLock); + ExAcquirePushLockExclusive(&KernelAddressSpaceLock); } } @@ -51,20 +43,13 @@ NTAPI MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace) { - /* - * Don't bother locking if we are the first thread. - */ - if (KeGetCurrentThread() == NULL) - { - return; - } if (AddressSpace->Process) { - ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&AddressSpace->Process->AddressCreationLock); + ExReleasePushLock((PEX_PUSH_LOCK)&AddressSpace->Process->AddressCreationLock); } else { - ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&KernelAddressSpaceLock); + ExReleasePushLock(&KernelAddressSpaceLock); } } @@ -98,11 +83,11 @@ AddressSpace->MemoryAreaRoot = NULL; if (Process) { - ExInitializeFastMutex(&Process->AddressCreationLock); + ExInitializePushLock((PULONG_PTR)&Process->AddressCreationLock); } else { - ExInitializeFastMutex(&KernelAddressSpaceLock); + ExInitializePushLock((PULONG_PTR)&KernelAddressSpaceLock); } if (Process != NULL) { Modified: branches/cache_manager_rewrite/mm/mminit.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/mminit…
============================================================================== --- branches/cache_manager_rewrite/mm/mminit.c (original) +++ branches/cache_manager_rewrite/mm/mminit.c Wed Jan 2 00:25:47 2008 @@ -113,7 +113,7 @@ */ MiInitPageDirectoryMap(); - BaseAddress = (PVOID)KPCR_BASE; + BaseAddress = (PVOID)KIP0PCRADDRESS; MmCreateMemoryArea(MmGetKernelAddressSpace(), MEMORY_AREA_SYSTEM, &BaseAddress, Modified: branches/cache_manager_rewrite/mm/pagefile.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/pagefi…
============================================================================== --- branches/cache_manager_rewrite/mm/pagefile.c (original) +++ branches/cache_manager_rewrite/mm/pagefile.c Wed Jan 2 00:25:47 2008 @@ -35,6 +35,11 @@ #pragma alloc_text(INIT, MmInitPagingFile) #endif +PVOID +NTAPI +MiFindExportedRoutineByName(IN PVOID DllBase, + IN PANSI_STRING ExportName); + /* TYPES *********************************************************************/ @@ -740,16 +745,14 @@ } /* Load the diskdump driver. */ - ModuleObject = LdrGetModuleObject(&DiskDumpName); + Status = MmLoadSystemImage(&DiskDumpName, NULL, NULL, 0, (PVOID)&ModuleObject, NULL); if (ModuleObject == NULL) { return(STATUS_OBJECT_NAME_NOT_FOUND); } RtlInitAnsiString(&ProcName, "DiskDumpFunctions"); - Status = LdrGetProcedureAddress(ModuleObject->DllBase, - &ProcName, - 0, - (PVOID*)&MmCoreDumpFunctions); + MmCoreDumpFunctions = MiFindExportedRoutineByName(ModuleObject->DllBase, + &ProcName); if (!NT_SUCCESS(Status)) { ObDereferenceObject(PageFile); Modified: branches/cache_manager_rewrite/mm/pageop.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/pageop…
============================================================================== --- branches/cache_manager_rewrite/mm/pageop.c (original) +++ branches/cache_manager_rewrite/mm/pageop.c Wed Jan 2 00:25:47 2008 @@ -48,7 +48,7 @@ } if (PageOp->MArea) { - InterlockedDecrementUL(&PageOp->MArea->PageOpCount); + (void)InterlockedDecrementUL(&PageOp->MArea->PageOpCount); } PrevPageOp = MmPageOpHashTable[PageOp->Hash]; if (PrevPageOp == PageOp) @@ -258,7 +258,7 @@ MmPageOpHashTable[Hash] = PageOp; if (MArea) { - InterlockedIncrementUL(&MArea->PageOpCount); + (void)InterlockedIncrementUL(&MArea->PageOpCount); } KeReleaseSpinLock(&MmPageOpHashTableLock, oldIrql); Modified: branches/cache_manager_rewrite/mm/rmap.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/rmap.c…
============================================================================== --- branches/cache_manager_rewrite/mm/rmap.c (original) +++ branches/cache_manager_rewrite/mm/rmap.c Wed Jan 2 00:25:47 2008 @@ -528,7 +528,7 @@ } if (Process) { - InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE); + (void)InterlockedExchangeAddUL(&Process->Vm.WorkingSetSize, -PAGE_SIZE); } return; } Modified: branches/cache_manager_rewrite/mm/section.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/sectio…
============================================================================== --- branches/cache_manager_rewrite/mm/section.c (original) +++ branches/cache_manager_rewrite/mm/section.c Wed Jan 2 00:25:47 2008 @@ -1058,7 +1058,7 @@ &MemoryArea->Data.SectionData.RegionListHead, Address, &RegionBase); - DPRINT("SegmentOffset %x, SectionOffset %x, Address %x, StartingAddress %x\n", SegmentOffset, SectionOffset, Address, MemoryArea->StartingAddress); + DPRINT("SegmentOffset %x, Address %x, StartingAddress %x\n", SegmentOffset, Address, MemoryArea->StartingAddress); /* * Lock the segment */ @@ -1436,7 +1436,7 @@ PageOp[i]->Status = STATUS_SUCCESS; MmspCompleteAndReleasePageOp(PageOp[i]); } - DPRINT("%x %x %x %x Address 0x%.8X\n", *(PULONG)Address, Region->Protect, Attributes, MemoryArea->StartingAddress + SegmentOffset, Address); + DPRINT("%x %x %x %x Address 0x%.8X\n", *(PULONG)Address, Region->Protect, Attributes, (ULONG_PTR)MemoryArea->StartingAddress + SegmentOffset, Address); return(STATUS_SUCCESS); } else if (IS_SWAP_FROM_SSE(Entry)) Modified: branches/cache_manager_rewrite/mm/verifier.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/verifi…
============================================================================== --- branches/cache_manager_rewrite/mm/verifier.c (original) +++ branches/cache_manager_rewrite/mm/verifier.c Wed Jan 2 00:25:47 2008 @@ -19,7 +19,7 @@ KMUTANT MmSystemLoadLock; ULONG MiActiveVerifierThunks; -extern LIST_ENTRY ModuleListHead; +extern LIST_ENTRY PsLoadedModuleList; /* PRIVATE FUNCTIONS *********************************************************/ @@ -32,8 +32,8 @@ PAGED_CODE(); /* Loop entries */ - NextEntry = ModuleListHead.Flink; - do + NextEntry = PsLoadedModuleList.Flink; + do { /* Get the loader entry */ LdrEntry = CONTAINING_RECORD(NextEntry, @@ -51,7 +51,7 @@ /* Move on */ NextEntry = NextEntry->Flink; - } while(NextEntry != &ModuleListHead); + } while(NextEntry != &PsLoadedModuleList); /* Return the entry */ return FoundEntry; @@ -164,7 +164,7 @@ if (!LdrEntry) return FALSE; /* Check if we're verifying or not */ - return (LdrEntry->Flags & LDRP_DRIVER_VERIFYING) ? TRUE: FALSE; + return (LdrEntry->Flags & LDRP_IMAGE_VERIFYING) ? TRUE: FALSE; } /* Modified: branches/cache_manager_rewrite/mm/virtual.c URL:
http://svn.reactos.org/svn/reactos/branches/cache_manager_rewrite/mm/virtua…
============================================================================== --- branches/cache_manager_rewrite/mm/virtual.c (original) +++ branches/cache_manager_rewrite/mm/virtual.c Wed Jan 2 00:25:47 2008 @@ -19,9 +19,9 @@ NTSTATUS STDCALL NtFlushVirtualMemory(IN HANDLE ProcessHandle, - IN PVOID BaseAddress, - IN ULONG NumberOfBytesToFlush, - OUT PULONG NumberOfBytesFlushed OPTIONAL) + IN OUT PVOID *BaseAddress, + IN OUT PSIZE_T NumberOfBytesToFlush, + OUT PIO_STATUS_BLOCK IoStatusBlock) /* * FUNCTION: Flushes virtual memory to file * ARGUMENTS: @@ -33,241 +33,248 @@ * RETURNS: Status */ { - /* This should be implemented once we support network filesystems */ - DPRINT("NtFlushVirtualMemory is UNIMPLEMENTED\n"); - return(STATUS_SUCCESS); + /* This should be implemented once we support network filesystems */ + DPRINT("NtFlushVirtualMemory is UNIMPLEMENTED\n"); + return(STATUS_SUCCESS); } NTSTATUS STDCALL MiLockVirtualMemory(HANDLE ProcessHandle, - PVOID BaseAddress, - ULONG NumberOfBytesToLock, - PULONG NumberOfBytesLocked, - PObReferenceObjectByHandle pObReferenceObjectByHandle, - PMmCreateMdl pMmCreateMdl, - PObDereferenceObject pObDereferenceObject, - PMmProbeAndLockPages pMmProbeAndLockPages, - PExFreePool pExFreePool) -{ - PEPROCESS Process; - NTSTATUS Status; - PMDL Mdl; - - Status = pObReferenceObjectByHandle(ProcessHandle, - PROCESS_VM_WRITE, - NULL, - UserMode, - (PVOID*)(&Process), - NULL); - if (!NT_SUCCESS(Status)) - return(Status); - - Mdl = pMmCreateMdl(NULL, - BaseAddress, - NumberOfBytesToLock); - if (Mdl == NULL) - { - pObDereferenceObject(Process); - return(STATUS_NO_MEMORY); - } - - pMmProbeAndLockPages(Mdl, - UserMode, - IoWriteAccess); - - pExFreePool(Mdl); - - pObDereferenceObject(Process); - - *NumberOfBytesLocked = NumberOfBytesToLock; - return(STATUS_SUCCESS); + PVOID BaseAddress, + ULONG NumberOfBytesToLock, + PULONG NumberOfBytesLocked, + PObReferenceObjectByHandle pObReferenceObjectByHandle, + PMmCreateMdl pMmCreateMdl, + PObDereferenceObject pObDereferenceObject, + PMmProbeAndLockPages pMmProbeAndLockPages, + PExFreePool pExFreePool) +{ + PEPROCESS Process; + NTSTATUS Status; + PMDL Mdl; + + Status = pObReferenceObjectByHandle(ProcessHandle, + PROCESS_VM_WRITE, + NULL, + UserMode, + (PVOID*)(&Process), + NULL); + if (!NT_SUCCESS(Status)) + return(Status); + + Mdl = pMmCreateMdl(NULL, + BaseAddress, + NumberOfBytesToLock); + if (Mdl == NULL) + { + pObDereferenceObject(Process); + return(STATUS_NO_MEMORY); + } + + pMmProbeAndLockPages(Mdl, + UserMode, + IoWriteAccess); + + pExFreePool(Mdl); + + pObDereferenceObject(Process); + + *NumberOfBytesLocked = NumberOfBytesToLock; + return(STATUS_SUCCESS); } NTSTATUS STDCALL NtLockVirtualMemory(HANDLE ProcessHandle, - PVOID BaseAddress, - ULONG NumberOfBytesToLock, - PULONG NumberOfBytesLocked) -{ - DPRINT("NtLockVirtualMemory(ProcessHandle %x, BaseAddress %x, " - "NumberOfBytesToLock %d, NumberOfBytesLocked %x)\n", - ProcessHandle, - BaseAddress, - NumberOfBytesToLock, - NumberOfBytesLocked); - - return MiLockVirtualMemory(ProcessHandle, - BaseAddress, - NumberOfBytesToLock, - NumberOfBytesLocked, - ObReferenceObjectByHandle, - MmCreateMdl, - (PVOID)ObfDereferenceObject, - MmProbeAndLockPages, - ExFreePool); + PVOID BaseAddress, + ULONG NumberOfBytesToLock, + PULONG NumberOfBytesLocked) +{ + DPRINT("NtLockVirtualMemory(ProcessHandle %x, BaseAddress %x, " + "NumberOfBytesToLock %d, NumberOfBytesLocked %x)\n", + ProcessHandle, + BaseAddress, + NumberOfBytesToLock, + NumberOfBytesLocked); + + return MiLockVirtualMemory(ProcessHandle, + BaseAddress, + NumberOfBytesToLock, + NumberOfBytesLocked, + ObReferenceObjectByHandle, + MmCreateMdl, + (PVOID)ObfDereferenceObject, + MmProbeAndLockPages, + ExFreePool); } NTSTATUS FASTCALL -MiQueryVirtualMemory (IN HANDLE ProcessHandle, - IN PVOID Address, - IN MEMORY_INFORMATION_CLASS VirtualMemoryInformationClass, - OUT PVOID VirtualMemoryInformation, - IN ULONG Length, - OUT PULONG ResultLength) -{ - NTSTATUS Status; - PEPROCESS Process; - MEMORY_AREA* MemoryArea; - PMADDRESS_SPACE AddressSpace; - - if (Address < MmSystemRangeStart) - { - Status = ObReferenceObjectByHandle(ProcessHandle, - PROCESS_QUERY_INFORMATION, - NULL, - UserMode, - (PVOID*)(&Process), - NULL); - - if (!NT_SUCCESS(Status)) - { - DPRINT("NtQueryVirtualMemory() = %x\n",Status); - return(Status); - } - AddressSpace = (PMADDRESS_SPACE)&Process->VadRoot; - } - else - { - AddressSpace = MmGetKernelAddressSpace(); - } - MmLockAddressSpace(AddressSpace); - MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, Address); - switch(VirtualMemoryInformationClass) - { - case MemoryBasicInformation: - { - PMEMORY_BASIC_INFORMATION Info = - (PMEMORY_BASIC_INFORMATION)VirtualMemoryInformation; +MiQueryVirtualMemory(IN HANDLE ProcessHandle, + IN PVOID Address, + IN MEMORY_INFORMATION_CLASS VirtualMemoryInformationClass, + OUT PVOID VirtualMemoryInformation, + IN ULONG Length, + OUT PULONG ResultLength) +{ + NTSTATUS Status; + PEPROCESS Process; + MEMORY_AREA* MemoryArea; + PMADDRESS_SPACE AddressSpace; + + if (Address < MmSystemRangeStart) + { + Status = ObReferenceObjectByHandle(ProcessHandle, + PROCESS_QUERY_INFORMATION, + NULL, + UserMode, + (PVOID*)(&Process), + NULL); + + if (!NT_SUCCESS(Status)) + { + DPRINT("NtQueryVirtualMemory() = %x\n",Status); + return(Status); + } + AddressSpace = (PMADDRESS_SPACE)&Process->VadRoot; + } + else + { + AddressSpace = MmGetKernelAddressSpace(); + } + MmLockAddressSpace(AddressSpace); + MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, Address); + switch(VirtualMemoryInformationClass) + { + case MemoryBasicInformation: + { + PMEMORY_BASIC_INFORMATION Info = + (PMEMORY_BASIC_INFORMATION)VirtualMemoryInformation; if (Length != sizeof(MEMORY_BASIC_INFORMATION)) { - MmUnlockAddressSpace(AddressSpace); - ObDereferenceObject(Process); - return(STATUS_INFO_LENGTH_MISMATCH); + MmUnlockAddressSpace(AddressSpace); + ObDereferenceObject(Process); + return(STATUS_INFO_LENGTH_MISMATCH); } if (MemoryArea == NULL) { - Info->Type = 0; - Info->State = MEM_FREE; - Info->Protect = PAGE_NOACCESS; - Info->AllocationProtect = 0; - Info->BaseAddress = (PVOID)PAGE_ROUND_DOWN(Address); - Info->AllocationBase = NULL; - Info->RegionSize = MmFindGapAtAddress(AddressSpace, Info->BaseAddress); - Status = STATUS_SUCCESS; - *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); - } + Info->Type = 0; + Info->State = MEM_FREE; + Info->Protect = PAGE_NOACCESS; + Info->AllocationProtect = 0; + Info->BaseAddress = (PVOID)PAGE_ROUND_DOWN(Address); + Info->AllocationBase = NULL; + Info->RegionSize = MmFindGapAtAddress(AddressSpace, Info->BaseAddress); + Status = STATUS_SUCCESS; + *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); + } else - { - switch(MemoryArea->Type) - { - case MEMORY_AREA_VIRTUAL_MEMORY: - case MEMORY_AREA_PEB_OR_TEB: - Status = MmQueryAnonMem(MemoryArea, Address, Info, - ResultLength); - break; - case MEMORY_AREA_SECTION_VIEW: - Status = MmQuerySectionView(MemoryArea, Address, Info, - ResultLength); - break; - case MEMORY_AREA_NO_ACCESS: - Info->Type = MEM_PRIVATE; - Info->State = MEM_RESERVE; - Info->Protect = MemoryArea->Protect; - Info->AllocationProtect = MemoryArea->Protect; - Info->BaseAddress = MemoryArea->StartingAddress; - Info->AllocationBase = MemoryArea->StartingAddress; - Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - - (ULONG_PTR)MemoryArea->StartingAddress; - Status = STATUS_SUCCESS; - *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); - break; - case MEMORY_AREA_SHARED_DATA: - Info->Type = MEM_PRIVATE; - Info->State = MEM_COMMIT; - Info->Protect = MemoryArea->Protect; - Info->AllocationProtect = MemoryArea->Protect; - Info->BaseAddress = MemoryArea->StartingAddress; - Info->AllocationBase = MemoryArea->StartingAddress; - Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - - (ULONG_PTR)MemoryArea->StartingAddress; - Status = STATUS_SUCCESS; - *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); - break; - case MEMORY_AREA_SYSTEM: - Info->Type = 0; - Info->State = MEM_COMMIT; - Info->Protect = MemoryArea->Protect; - Info->AllocationProtect = MemoryArea->Protect; - Info->BaseAddress = MemoryArea->StartingAddress; - Info->AllocationBase = MemoryArea->StartingAddress; - Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - - (ULONG_PTR)MemoryArea->StartingAddress; - Status = STATUS_SUCCESS; - *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); - break; - case MEMORY_AREA_KERNEL_STACK: - Info->Type = 0; - Info->State = MEM_COMMIT; - Info->Protect = MemoryArea->Protect; - Info->AllocationProtect = MemoryArea->Protect; - Info->BaseAddress = MemoryArea->StartingAddress; - Info->AllocationBase = MemoryArea->StartingAddress; - Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - - (ULONG_PTR)MemoryArea->StartingAddress; - Status = STATUS_SUCCESS; - *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); - break; - case MEMORY_AREA_PAGED_POOL: - Info->Type = 0; - Info->State = MEM_COMMIT; - Info->Protect = MemoryArea->Protect; - Info->AllocationProtect = MemoryArea->Protect; - Info->BaseAddress = MemoryArea->StartingAddress; - Info->AllocationBase = MemoryArea->StartingAddress; - Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - - (ULONG_PTR)MemoryArea->StartingAddress; - Status = STATUS_SUCCESS; - *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); - break; - default: - DPRINT1("unhandled memory area type: 0x%x\n", MemoryArea->Type); - Status = STATUS_UNSUCCESSFUL; - *ResultLength = 0; - } - } + { + switch(MemoryArea->Type) + { + case MEMORY_AREA_VIRTUAL_MEMORY: + case MEMORY_AREA_PEB_OR_TEB: + Status = MmQueryAnonMem(MemoryArea, Address, Info, + ResultLength); + break; + + case MEMORY_AREA_SECTION_VIEW: + Status = MmQuerySectionView(MemoryArea, Address, Info, + ResultLength); + break; + + case MEMORY_AREA_NO_ACCESS: + Info->Type = MEM_PRIVATE; + Info->State = MEM_RESERVE; + Info->Protect = MemoryArea->Protect; + Info->AllocationProtect = MemoryArea->Protect; + Info->BaseAddress = MemoryArea->StartingAddress; + Info->AllocationBase = MemoryArea->StartingAddress; + Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - + (ULONG_PTR)MemoryArea->StartingAddress; + Status = STATUS_SUCCESS; + *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); + break; + + case MEMORY_AREA_SHARED_DATA: + Info->Type = MEM_PRIVATE; + Info->State = MEM_COMMIT; + Info->Protect = MemoryArea->Protect; + Info->AllocationProtect = MemoryArea->Protect; + Info->BaseAddress = MemoryArea->StartingAddress; + Info->AllocationBase = MemoryArea->StartingAddress; + Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - + (ULONG_PTR)MemoryArea->StartingAddress; + Status = STATUS_SUCCESS; + *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); + break; + + case MEMORY_AREA_SYSTEM: + Info->Type = 0; + Info->State = MEM_COMMIT; + Info->Protect = MemoryArea->Protect; + Info->AllocationProtect = MemoryArea->Protect; + Info->BaseAddress = MemoryArea->StartingAddress; + Info->AllocationBase = MemoryArea->StartingAddress; + Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - + (ULONG_PTR)MemoryArea->StartingAddress; + Status = STATUS_SUCCESS; + *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); + break; + + case MEMORY_AREA_KERNEL_STACK: + Info->Type = 0; + Info->State = MEM_COMMIT; + Info->Protect = MemoryArea->Protect; + Info->AllocationProtect = MemoryArea->Protect; + Info->BaseAddress = MemoryArea->StartingAddress; + Info->AllocationBase = MemoryArea->StartingAddress; + Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - + (ULONG_PTR)MemoryArea->StartingAddress; + Status = STATUS_SUCCESS; + *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); + break; + + case MEMORY_AREA_PAGED_POOL: + Info->Type = 0; + Info->State = MEM_COMMIT; + Info->Protect = MemoryArea->Protect; + Info->AllocationProtect = MemoryArea->Protect; + Info->BaseAddress = MemoryArea->StartingAddress; + Info->AllocationBase = MemoryArea->StartingAddress; + Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress - + (ULONG_PTR)MemoryArea->StartingAddress; + Status = STATUS_SUCCESS; + *ResultLength = sizeof(MEMORY_BASIC_INFORMATION); + break; + + default: + DPRINT1("unhandled memory area type: 0x%x\n", MemoryArea->Type); + Status = STATUS_UNSUCCESSFUL; + *ResultLength = 0; + } + } break; - } - - default: - { + } + + default: + { Status = STATUS_INVALID_INFO_CLASS; *ResultLength = 0; break; - } - } - - MmUnlockAddressSpace(AddressSpace); - if (Address < MmSystemRangeStart) - { - ASSERT(Process); - ObDereferenceObject(Process); - } - - return Status; + } + } + + MmUnlockAddressSpace(AddressSpace); + if (Address < MmSystemRangeStart) + { + ASSERT(Process); + ObDereferenceObject(Process); + } + + return Status; } /* (tMk 2004.II.4) @@ -276,102 +283,102 @@ * */ NTSTATUS STDCALL -NtQueryVirtualMemory (IN HANDLE ProcessHandle, - IN PVOID Address, - IN MEMORY_INFORMATION_CLASS VirtualMemoryInformationClass, - OUT PVOID VirtualMemoryInformation, - IN ULONG Length, - OUT PULONG UnsafeResultLength) -{ - NTSTATUS Status = STATUS_SUCCESS; - ULONG ResultLength = 0; - KPROCESSOR_MODE PreviousMode; - union - { - MEMORY_BASIC_INFORMATION BasicInfo; - } - VirtualMemoryInfo; - - DPRINT("NtQueryVirtualMemory(ProcessHandle %x, Address %x, " - "VirtualMemoryInformationClass %d, VirtualMemoryInformation %x, " - "Length %lu ResultLength %x)\n",ProcessHandle,Address, - VirtualMemoryInformationClass,VirtualMemoryInformation, - Length,ResultLength); - - PreviousMode = ExGetPreviousMode(); - - if (PreviousMode != KernelMode && UnsafeResultLength != NULL) - { - _SEH_TRY - { - ProbeForWriteUlong(UnsafeResultLength); - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - - if (!NT_SUCCESS(Status)) - { - return Status; - } - } - - if (Address >= MmSystemRangeStart) - { - DPRINT1("Invalid parameter\n"); - return STATUS_INVALID_PARAMETER; - } - - Status = MiQueryVirtualMemory ( ProcessHandle, - Address, - VirtualMemoryInformationClass, - &VirtualMemoryInfo, - Length, - &ResultLength ); - - if (NT_SUCCESS(Status)) - { - if (PreviousMode != KernelMode) - { - _SEH_TRY - { - if (ResultLength > 0) +NtQueryVirtualMemory(IN HANDLE ProcessHandle, + IN PVOID Address, + IN MEMORY_INFORMATION_CLASS VirtualMemoryInformationClass, + OUT PVOID VirtualMemoryInformation, + IN ULONG Length, + OUT PULONG UnsafeResultLength) +{ + NTSTATUS Status = STATUS_SUCCESS; + ULONG ResultLength = 0; + KPROCESSOR_MODE PreviousMode; + union + { + MEMORY_BASIC_INFORMATION BasicInfo; + } + VirtualMemoryInfo; + + DPRINT("NtQueryVirtualMemory(ProcessHandle %x, Address %x, " + "VirtualMemoryInformationClass %d, VirtualMemoryInformation %x, " + "Length %lu ResultLength %x)\n",ProcessHandle,Address, + VirtualMemoryInformationClass,VirtualMemoryInformation, + Length,ResultLength); + + PreviousMode = ExGetPreviousMode(); + + if (PreviousMode != KernelMode && UnsafeResultLength != NULL) + { + _SEH_TRY + { + ProbeForWriteUlong(UnsafeResultLength); + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + if (!NT_SUCCESS(Status)) + { + return Status; + } + } + + if (Address >= MmSystemRangeStart) + { + DPRINT1("Invalid parameter\n"); + return STATUS_INVALID_PARAMETER; + } + + Status = MiQueryVirtualMemory(ProcessHandle, + Address, + VirtualMemoryInformationClass, + &VirtualMemoryInfo, + Length, + &ResultLength ); + + if (NT_SUCCESS(Status)) + { + if (PreviousMode != KernelMode) + { + _SEH_TRY + { + if (ResultLength > 0) { - ProbeForWrite(VirtualMemoryInformation, - ResultLength, - 1); - RtlCopyMemory(VirtualMemoryInformation, - &VirtualMemoryInfo, - ResultLength); + ProbeForWrite(VirtualMemoryInformation, + ResultLength, + 1); + RtlCopyMemory(VirtualMemoryInformation, + &VirtualMemoryInfo, + ResultLength); } - if (UnsafeResultLength != NULL) + if (UnsafeResultLength != NULL) { - *UnsafeResultLength = ResultLength; + *UnsafeResultLength = ResultLength; } } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - } - else - { - if (ResultLength > 0) - { - RtlCopyMemory(VirtualMemoryInformation, - &VirtualMemoryInfo, - ResultLength); - } - - if (UnsafeResultLength != NULL) - { - *UnsafeResultLength = ResultLength; - } - } - } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + } + else + { + if (ResultLength > 0) + { + RtlCopyMemory(VirtualMemoryInformation, + &VirtualMemoryInfo, + ResultLength); + } + + if (UnsafeResultLength != NULL) + { + *UnsafeResultLength = ResultLength; + } + } + } return(Status); } @@ -384,51 +391,51 @@ IN ULONG NewAccessProtection, OUT PULONG OldAccessProtection OPTIONAL) { - PMEMORY_AREA MemoryArea; - PMADDRESS_SPACE AddressSpace; - ULONG OldAccessProtection_; - NTSTATUS Status; - - *NumberOfBytesToProtect = - PAGE_ROUND_UP((*BaseAddress) + (*NumberOfBytesToProtect)) - - PAGE_ROUND_DOWN(*BaseAddress); - *BaseAddress = (PVOID)PAGE_ROUND_DOWN(*BaseAddress); - - AddressSpace = (PMADDRESS_SPACE)&(Process)->VadRoot; - - MmLockAddressSpace(AddressSpace); - MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, *BaseAddress); - if (MemoryArea == NULL) - { - MmUnlockAddressSpace(AddressSpace); - return STATUS_UNSUCCESSFUL; - } - - if (OldAccessProtection == NULL) - OldAccessProtection = &OldAccessProtection_; - - if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY) - { - Status = MmProtectAnonMem(AddressSpace, MemoryArea, *BaseAddress, - *NumberOfBytesToProtect, NewAccessProtection, - OldAccessProtection); - } - else if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW) - { - Status = MmProtectSectionView(AddressSpace, MemoryArea, *BaseAddress, - *NumberOfBytesToProtect, - NewAccessProtection, - OldAccessProtection); - } - else - { - /* FIXME: Should we return failure or success in this case? */ - Status = STATUS_CONFLICTING_ADDRESSES; - } - - MmUnlockAddressSpace(AddressSpace); - - return Status; + PMEMORY_AREA MemoryArea; + PMADDRESS_SPACE AddressSpace; + ULONG OldAccessProtection_; + NTSTATUS Status; + + *NumberOfBytesToProtect = + PAGE_ROUND_UP((ULONG_PTR)(*BaseAddress) + (*NumberOfBytesToProtect)) - + PAGE_ROUND_DOWN(*BaseAddress); + *BaseAddress = (PVOID)PAGE_ROUND_DOWN(*BaseAddress); + + AddressSpace = (PMADDRESS_SPACE)&(Process)->VadRoot; + + MmLockAddressSpace(AddressSpace); + MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, *BaseAddress); + if (MemoryArea == NULL) + { + MmUnlockAddressSpace(AddressSpace); + return STATUS_UNSUCCESSFUL; + } + + if (OldAccessProtection == NULL) + OldAccessProtection = &OldAccessProtection_; + + if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY) + { + Status = MmProtectAnonMem(AddressSpace, MemoryArea, *BaseAddress, + *NumberOfBytesToProtect, NewAccessProtection, + OldAccessProtection); + } + else if (MemoryArea->Type == MEMORY_AREA_SECTION_VIEW) + { + Status = MmProtectSectionView(AddressSpace, MemoryArea, *BaseAddress, + *NumberOfBytesToProtect, + NewAccessProtection, + OldAccessProtection); + } + else + { + /* FIXME: Should we return failure or success in this case? */ + Status = STATUS_CONFLICTING_ADDRESSES; + } + + MmUnlockAddressSpace(AddressSpace); + + return Status; } @@ -444,100 +451,100 @@ IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection) { - PEPROCESS Process; - ULONG OldAccessProtection; - PVOID BaseAddress = NULL; - ULONG NumberOfBytesToProtect = 0; - KPROCESSOR_MODE PreviousMode; - NTSTATUS Status = STATUS_SUCCESS; - - PreviousMode = ExGetPreviousMode(); - - if (PreviousMode != KernelMode) - { - _SEH_TRY - { - ProbeForWritePointer(UnsafeBaseAddress); - ProbeForWriteUlong(UnsafeNumberOfBytesToProtect); - ProbeForWriteUlong(UnsafeOldAccessProtection); - - BaseAddress = *UnsafeBaseAddress; - NumberOfBytesToProtect = *UnsafeNumberOfBytesToProtect; - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - - if (!NT_SUCCESS(Status)) - { - return Status; - } - } - else - { - BaseAddress = *UnsafeBaseAddress; - NumberOfBytesToProtect = *UnsafeNumberOfBytesToProtect; - } - - if ((ULONG_PTR)BaseAddress + NumberOfBytesToProtect - 1 < (ULONG_PTR)BaseAddress || - (ULONG_PTR)BaseAddress + NumberOfBytesToProtect - 1 >= MmUserProbeAddress) - { - /* Don't allow to change the protection of a kernel mode address */ - return STATUS_INVALID_PARAMETER_2; - } - - /* (tMk 2004.II.5) in Microsoft SDK I read: - * 'if this parameter is NULL or does not point to a valid variable, the function fails' - */ - if(UnsafeOldAccessProtection == NULL) - { - return(STATUS_INVALID_PARAMETER); - } - - Status = ObReferenceObjectByHandle(ProcessHandle, - PROCESS_VM_OPERATION, - PsProcessType, - UserMode, - (PVOID*)(&Process), - NULL); - if (!NT_SUCCESS(Status)) - { - DPRINT("NtProtectVirtualMemory() = %x\n",Status); - return(Status); - } - - Status = MiProtectVirtualMemory(Process, - &BaseAddress, - &NumberOfBytesToProtect, - NewAccessProtection, - &OldAccessProtection); - - ObDereferenceObject(Process); - - if (PreviousMode != KernelMode) - { - _SEH_TRY - { - *UnsafeOldAccessProtection = OldAccessProtection; - *UnsafeBaseAddress = BaseAddress; - *UnsafeNumberOfBytesToProtect = NumberOfBytesToProtect; - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - } - else - { - *UnsafeOldAccessProtection = OldAccessProtection; - *UnsafeBaseAddress = BaseAddress; - *UnsafeNumberOfBytesToProtect = NumberOfBytesToProtect; - } - - return(Status); + PEPROCESS Process; + ULONG OldAccessProtection; + PVOID BaseAddress = NULL; + ULONG NumberOfBytesToProtect = 0; + KPROCESSOR_MODE PreviousMode; + NTSTATUS Status = STATUS_SUCCESS; + + PreviousMode = ExGetPreviousMode(); + + if (PreviousMode != KernelMode) + { + _SEH_TRY + { + ProbeForWritePointer(UnsafeBaseAddress); + ProbeForWriteUlong(UnsafeNumberOfBytesToProtect); + ProbeForWriteUlong(UnsafeOldAccessProtection); + + BaseAddress = *UnsafeBaseAddress; + NumberOfBytesToProtect = *UnsafeNumberOfBytesToProtect; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + if (!NT_SUCCESS(Status)) + { + return Status; + } + } + else + { + BaseAddress = *UnsafeBaseAddress; + NumberOfBytesToProtect = *UnsafeNumberOfBytesToProtect; + } + + if ((ULONG_PTR)BaseAddress + NumberOfBytesToProtect - 1 < (ULONG_PTR)BaseAddress || + (ULONG_PTR)BaseAddress + NumberOfBytesToProtect - 1 >= MmUserProbeAddress) + { + /* Don't allow to change the protection of a kernel mode address */ + return STATUS_INVALID_PARAMETER_2; + } + + /* (tMk 2004.II.5) in Microsoft SDK I read: + * 'if this parameter is NULL or does not point to a valid variable, the function fails' + */ + if(UnsafeOldAccessProtection == NULL) + { + return(STATUS_INVALID_PARAMETER); + } + + Status = ObReferenceObjectByHandle(ProcessHandle, + PROCESS_VM_OPERATION, + PsProcessType, + UserMode, + (PVOID*)(&Process), + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT("NtProtectVirtualMemory() = %x\n",Status); + return(Status); + } + + Status = MiProtectVirtualMemory(Process, + &BaseAddress, + &NumberOfBytesToProtect, + NewAccessProtection, + &OldAccessProtection); + + ObDereferenceObject(Process); + + if (PreviousMode != KernelMode) + { + _SEH_TRY + { + *UnsafeOldAccessProtection = OldAccessProtection; + *UnsafeBaseAddress = BaseAddress; + *UnsafeNumberOfBytesToProtect = NumberOfBytesToProtect; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + } + else + { + *UnsafeOldAccessProtection = OldAccessProtection; + *UnsafeBaseAddress = BaseAddress; + *UnsafeNumberOfBytesToProtect = NumberOfBytesToProtect; + } + + return(Status); } @@ -554,150 +561,153 @@ IN ULONG NumberOfBytesToRead, OUT PULONG NumberOfBytesRead OPTIONAL) { - PMDL Mdl; - PVOID SystemAddress; - KPROCESSOR_MODE PreviousMode; - PEPROCESS Process, CurrentProcess; - NTSTATUS Status = STATUS_SUCCESS; - - PAGED_CODE(); - - DPRINT("NtReadVirtualMemory(ProcessHandle %x, BaseAddress %x, " - "Buffer %x, NumberOfBytesToRead %d)\n",ProcessHandle,BaseAddress, - Buffer,NumberOfBytesToRead); - - if ((ULONG_PTR)BaseAddress + NumberOfBytesToRead - 1 < (ULONG_PTR)BaseAddress || - (ULONG_PTR)BaseAddress + NumberOfBytesToRead - 1 >= MmUserProbeAddress) - { - /* Don't allow to read from kernel space */ - return STATUS_ACCESS_VIOLATION; - } - - PreviousMode = ExGetPreviousMode(); - - if (PreviousMode != KernelMode) - { - if ((ULONG_PTR)Buffer + NumberOfBytesToRead - 1 < (ULONG_PTR)Buffer || - (ULONG_PTR)Buffer + NumberOfBytesToRead - 1 >= MmUserProbeAddress) - { - /* Don't allow to write into kernel space */ - return STATUS_ACCESS_VIOLATION; - } - } - - Status = ObReferenceObjectByHandle(ProcessHandle, - PROCESS_VM_READ, - NULL, - PreviousMode, - (PVOID*)(&Process), - NULL); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - CurrentProcess = PsGetCurrentProcess(); - - if(PreviousMode != KernelMode) - { - _SEH_TRY - { - if(NumberOfBytesRead != NULL) - { - ProbeForWriteUlong(NumberOfBytesRead); - } - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - - if(!NT_SUCCESS(Status)) - { - return Status; - } - } - - - if (Process == CurrentProcess) - { - _SEH_TRY - { - RtlCopyMemory(Buffer, BaseAddress, NumberOfBytesToRead); - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - } - else - { - Mdl = MmCreateMdl(NULL, - Buffer, - NumberOfBytesToRead); - if(Mdl == NULL) - { - ObDereferenceObject(Process); - return(STATUS_NO_MEMORY); - } - _SEH_TRY - { - MmProbeAndLockPages(Mdl, - PreviousMode, - IoWriteAccess); - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - - if(NT_SUCCESS(Status)) - { - KeAttachProcess(&Process->Pcb); - - SystemAddress = MmGetSystemAddressForMdl(Mdl); - - Status = STATUS_SUCCESS; - _SEH_TRY { - Status = STATUS_PARTIAL_COPY; - RtlCopyMemory(SystemAddress, BaseAddress, NumberOfBytesToRead); - Status = STATUS_SUCCESS; - } _SEH_HANDLE { - if(Status != STATUS_PARTIAL_COPY) - Status = _SEH_GetExceptionCode(); - } _SEH_END; - - KeDetachProcess(); - - if (Mdl->MappedSystemVa != NULL) - { - MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl); - } - MmUnlockPages(Mdl); - } - ExFreePool(Mdl); - } - - ObDereferenceObject(Process); - - if((NT_SUCCESS(Status) || Status == STATUS_PARTIAL_COPY) && - NumberOfBytesRead != NULL) - { - _SEH_TRY - { - *NumberOfBytesRead = NumberOfBytesToRead; - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - } - - return(Status); + PMDL Mdl; + PVOID SystemAddress; + KPROCESSOR_MODE PreviousMode; + PEPROCESS Process, CurrentProcess; + NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); + + DPRINT("NtReadVirtualMemory(ProcessHandle %x, BaseAddress %x, " + "Buffer %x, NumberOfBytesToRead %d)\n",ProcessHandle,BaseAddress, + Buffer,NumberOfBytesToRead); + + if ((ULONG_PTR)BaseAddress + NumberOfBytesToRead - 1 < (ULONG_PTR)BaseAddress || + (ULONG_PTR)BaseAddress + NumberOfBytesToRead - 1 >= MmUserProbeAddress) + { + /* Don't allow to read from kernel space */ + return STATUS_ACCESS_VIOLATION; + } + + PreviousMode = ExGetPreviousMode(); + + if (PreviousMode != KernelMode) + { + if ((ULONG_PTR)Buffer + NumberOfBytesToRead - 1 < (ULONG_PTR)Buffer || + (ULONG_PTR)Buffer + NumberOfBytesToRead - 1 >= MmUserProbeAddress) + { + /* Don't allow to write into kernel space */ + return STATUS_ACCESS_VIOLATION; + } + } + + Status = ObReferenceObjectByHandle(ProcessHandle, + PROCESS_VM_READ, + NULL, + PreviousMode, + (PVOID*)(&Process), + NULL); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + CurrentProcess = PsGetCurrentProcess(); + + if(PreviousMode != KernelMode) + { + _SEH_TRY + { + if(NumberOfBytesRead != NULL) + { + ProbeForWriteUlong(NumberOfBytesRead); + } + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + if(!NT_SUCCESS(Status)) + { + return Status; + } + } + + + if (Process == CurrentProcess) + { + _SEH_TRY + { + RtlCopyMemory(Buffer, BaseAddress, NumberOfBytesToRead); + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + } + else + { + Mdl = MmCreateMdl(NULL, + Buffer, + NumberOfBytesToRead); + if(Mdl == NULL) + { + ObDereferenceObject(Process); + return(STATUS_NO_MEMORY); + } + + _SEH_TRY + { + MmProbeAndLockPages(Mdl, PreviousMode, IoWriteAccess); + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + if(NT_SUCCESS(Status)) + { + KeAttachProcess(&Process->Pcb); + + SystemAddress = MmGetSystemAddressForMdl(Mdl); + + Status = STATUS_SUCCESS; + _SEH_TRY + { + Status = STATUS_PARTIAL_COPY; + RtlCopyMemory(SystemAddress, BaseAddress, NumberOfBytesToRead); + Status = STATUS_SUCCESS; + } + _SEH_HANDLE + { + if(Status != STATUS_PARTIAL_COPY) + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + KeDetachProcess(); + + if (Mdl->MappedSystemVa != NULL) + { + MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl); + } + MmUnlockPages(Mdl); + } + ExFreePool(Mdl); + } + + ObDereferenceObject(Process); + + if ((NT_SUCCESS(Status) || Status == STATUS_PARTIAL_COPY) && + NumberOfBytesRead != NULL) + { + _SEH_TRY + { + *NumberOfBytesRead = NumberOfBytesToRead; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + } + + return(Status); } /* (tMk 2004.II.05) @@ -710,49 +720,49 @@ ULONG NumberOfBytesToUnlock, PULONG NumberOfBytesUnlocked OPTIONAL) { - // AG [08-20-03] : I have *no* idea if this is correct, I just used the - // other functions as a template and made a few intelligent guesses... - - NTSTATUS Status; - PMDL Mdl; - PEPROCESS Process; - - DPRINT("NtUnlockVirtualMemory(ProcessHandle %x, BaseAddress %x, " - "NumberOfBytesToUnlock %d), NumberOfBytesUnlocked %x\n",ProcessHandle,BaseAddress, - NumberOfBytesToUnlock, NumberOfBytesUnlocked); - - Status = ObReferenceObjectByHandle(ProcessHandle, - PROCESS_VM_WRITE, - NULL, - UserMode, - (PVOID*)(&Process), - NULL); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - Mdl = MmCreateMdl(NULL, - BaseAddress, - NumberOfBytesToUnlock); - if(Mdl == NULL) - { - ObDereferenceObject(Process); - return(STATUS_NO_MEMORY); - } - - ObDereferenceObject(Process); - - if (Mdl->MappedSystemVa != NULL) - { - MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl); - } - MmUnlockPages(Mdl); - ExFreePool(Mdl); - - *NumberOfBytesUnlocked = NumberOfBytesToUnlock; - - return(STATUS_SUCCESS); + // AG [08-20-03] : I have *no* idea if this is correct, I just used the + // other functions as a template and made a few intelligent guesses... + + NTSTATUS Status; + PMDL Mdl; + PEPROCESS Process; + + DPRINT("NtUnlockVirtualMemory(ProcessHandle %x, BaseAddress %x, " + "NumberOfBytesToUnlock %d), NumberOfBytesUnlocked %x\n",ProcessHandle,BaseAddress, + NumberOfBytesToUnlock, NumberOfBytesUnlocked); + + Status = ObReferenceObjectByHandle(ProcessHandle, + PROCESS_VM_WRITE, + NULL, + UserMode, + (PVOID*)(&Process), + NULL); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + Mdl = MmCreateMdl(NULL, + BaseAddress, + NumberOfBytesToUnlock); + if(Mdl == NULL) + { + ObDereferenceObject(Process); + return(STATUS_NO_MEMORY); + } + + ObDereferenceObject(Process); + + if (Mdl->MappedSystemVa != NULL) + { + MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl); + } + MmUnlockPages(Mdl); + ExFreePool(Mdl); + + *NumberOfBytesUnlocked = NumberOfBytesToUnlock; + + return(STATUS_SUCCESS); } @@ -769,166 +779,164 @@ IN ULONG NumberOfBytesToWrite, OUT PULONG NumberOfBytesWritten OPTIONAL) { - PMDL Mdl; - PVOID SystemAddress; - PEPROCESS Process; - KPROCESSOR_MODE PreviousMode; - NTSTATUS CopyStatus, Status = STATUS_SUCCESS; - - DPRINT("NtWriteVirtualMemory(ProcessHandle %x, BaseAddress %x, " - "Buffer %x, NumberOfBytesToWrite %d)\n",ProcessHandle,BaseAddress, - Buffer,NumberOfBytesToWrite); - - if ((ULONG_PTR)BaseAddress + NumberOfBytesToWrite - 1 < (ULONG_PTR)BaseAddress || - (ULONG_PTR)BaseAddress + NumberOfBytesToWrite - 1 >= MmUserProbeAddress) - { - /* Don't allow to write into kernel space */ - return STATUS_ACCESS_VIOLATION; - } - - PreviousMode = ExGetPreviousMode(); - - if (PreviousMode != KernelMode) - { - if ((ULONG_PTR)Buffer + NumberOfBytesToWrite - 1 < (ULONG_PTR)Buffer || - (ULONG_PTR)Buffer + NumberOfBytesToWrite - 1 >= MmUserProbeAddress) - { - /* Don't allow to read from kernel space */ - return STATUS_ACCESS_VIOLATION; - } - if (NumberOfBytesWritten != NULL) - { - _SEH_TRY - { - ProbeForWriteUlong(NumberOfBytesWritten); - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - - if (!NT_SUCCESS(Status)) - { - return Status; - } - } - } - - Status = ObReferenceObjectByHandle(ProcessHandle, - PROCESS_VM_WRITE, - NULL, - UserMode, - (PVOID*)(&Process), - NULL); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - CopyStatus = STATUS_SUCCESS; - - /* Write memory */ - if (Process == PsGetCurrentProcess()) - { - if (PreviousMode != KernelMode) - { - _SEH_TRY - { - memcpy(BaseAddress, Buffer, NumberOfBytesToWrite); - } - _SEH_HANDLE - { - CopyStatus = _SEH_GetExceptionCode(); - } - _SEH_END; - } - else - { - memcpy(BaseAddress, Buffer, NumberOfBytesToWrite); - } - } - else - { - /* Create MDL describing the source buffer. */ - Mdl = MmCreateMdl(NULL, - Buffer, - NumberOfBytesToWrite); - if(Mdl == NULL) - { - ObDereferenceObject(Process); - return(STATUS_NO_MEMORY); - } - _SEH_TRY - { - /* Map the MDL. */ - MmProbeAndLockPages(Mdl, - UserMode, - IoReadAccess); - } - _SEH_HANDLE - { - CopyStatus = _SEH_GetExceptionCode(); - } - _SEH_END; - - if (NT_SUCCESS(CopyStatus)) - { - /* Copy memory from the mapped MDL into the target buffer. */ - KeAttachProcess(&Process->Pcb); - - SystemAddress = MmGetSystemAddressForMdl(Mdl); - if (PreviousMode != KernelMode) - { - _SEH_TRY + PMDL Mdl; + PVOID SystemAddress; + PEPROCESS Process; + KPROCESSOR_MODE PreviousMode; + NTSTATUS CopyStatus, Status = STATUS_SUCCESS; + + DPRINT("NtWriteVirtualMemory(ProcessHandle %x, BaseAddress %x, " + "Buffer %x, NumberOfBytesToWrite %d)\n",ProcessHandle,BaseAddress, + Buffer,NumberOfBytesToWrite); + + if ((ULONG_PTR)BaseAddress + NumberOfBytesToWrite - 1 < (ULONG_PTR)BaseAddress || + (ULONG_PTR)BaseAddress + NumberOfBytesToWrite - 1 >= MmUserProbeAddress) + { + /* Don't allow to write into kernel space */ + return STATUS_ACCESS_VIOLATION; + } + + PreviousMode = ExGetPreviousMode(); + + if (PreviousMode != KernelMode) + { + if ((ULONG_PTR)Buffer + NumberOfBytesToWrite - 1 < (ULONG_PTR)Buffer || + (ULONG_PTR)Buffer + NumberOfBytesToWrite - 1 >= MmUserProbeAddress) + { + /* Don't allow to read from kernel space */ + return STATUS_ACCESS_VIOLATION; + } + if (NumberOfBytesWritten != NULL) + { + _SEH_TRY + { + ProbeForWriteUlong(NumberOfBytesWritten); + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + if (!NT_SUCCESS(Status)) + { + return Status; + } + } + } + + Status = ObReferenceObjectByHandle(ProcessHandle, + PROCESS_VM_WRITE, + NULL, + UserMode, + (PVOID*)(&Process), + NULL); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + CopyStatus = STATUS_SUCCESS; + + /* Write memory */ + if (Process == PsGetCurrentProcess()) + { + if (PreviousMode != KernelMode) + { + _SEH_TRY + { + memcpy(BaseAddress, Buffer, NumberOfBytesToWrite); + } + _SEH_HANDLE + { + CopyStatus = _SEH_GetExceptionCode(); + } + _SEH_END; + } + else + { + memcpy(BaseAddress, Buffer, NumberOfBytesToWrite); + } + } + else + { + /* Create MDL describing the source buffer. */ + Mdl = MmCreateMdl(NULL, + Buffer, + NumberOfBytesToWrite); + if (Mdl == NULL) + { + ObDereferenceObject(Process); + return(STATUS_NO_MEMORY); + } + _SEH_TRY + { + /* Map the MDL. */ + MmProbeAndLockPages(Mdl, UserMode, IoReadAccess); + } + _SEH_HANDLE + { + CopyStatus = _SEH_GetExceptionCode(); + } + _SEH_END; + + if (NT_SUCCESS(CopyStatus)) + { + /* Copy memory from the mapped MDL into the target buffer. */ + KeAttachProcess(&Process->Pcb); + + SystemAddress = MmGetSystemAddressForMdl(Mdl); + if (PreviousMode != KernelMode) + { + _SEH_TRY { - memcpy(BaseAddress, SystemAddress, NumberOfBytesToWrite); + memcpy(BaseAddress, SystemAddress, NumberOfBytesToWrite); } - _SEH_HANDLE + _SEH_HANDLE { - CopyStatus = _SEH_GetExceptionCode(); + CopyStatus = _SEH_GetExceptionCode(); } - _SEH_END; - } - else - { - memcpy(BaseAddress, SystemAddress, NumberOfBytesToWrite); - } - - KeDetachProcess(); - } - - /* Free the MDL. */ - if (Mdl->MappedSystemVa != NULL) - { - MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl); - } - MmUnlockPages(Mdl); - ExFreePool(Mdl); - } - ObDereferenceObject(Process); - - if (NT_SUCCESS(CopyStatus) && NumberOfBytesWritten != NULL) - { - if (PreviousMode != KernelMode) - { - _SEH_TRY - { - *NumberOfBytesWritten = NumberOfBytesToWrite; - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - } - else - { - *NumberOfBytesWritten = NumberOfBytesToWrite; - } - } - - return(NT_SUCCESS(CopyStatus) ? Status : CopyStatus); + _SEH_END; + } + else + { + memcpy(BaseAddress, SystemAddress, NumberOfBytesToWrite); + } + + KeDetachProcess(); + } + + /* Free the MDL. */ + if (Mdl->MappedSystemVa != NULL) + { + MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl); + } + MmUnlockPages(Mdl); + ExFreePool(Mdl); + } + ObDereferenceObject(Process); + + if (NT_SUCCESS(CopyStatus) && NumberOfBytesWritten != NULL) + { + if (PreviousMode != KernelMode) + { + _SEH_TRY + { + *NumberOfBytesWritten = NumberOfBytesToWrite; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + } + else + { + *NumberOfBytesWritten = NumberOfBytesToWrite; + } + } + + return(NT_SUCCESS(CopyStatus) ? Status : CopyStatus); } /* @@ -937,12 +945,12 @@ PVOID STDCALL -MmGetVirtualForPhysical ( +MmGetVirtualForPhysical( IN PHYSICAL_ADDRESS PhysicalAddress ) { - UNIMPLEMENTED; - return 0; + UNIMPLEMENTED; + return 0; } /* FUNCTION: @@ -950,19 +958,19 @@ * @unimplemented */ PVOID STDCALL -MmSecureVirtualMemory (PVOID Address, - SIZE_T Length, - ULONG Mode) -{ - /* Only works for user space */ - if (MmHighestUserAddress < Address) - { - return NULL; - } - - UNIMPLEMENTED; - - return 0; +MmSecureVirtualMemory(PVOID Address, + SIZE_T Length, + ULONG Mode) +{ + /* Only works for user space */ + if (MmHighestUserAddress < Address) + { + return NULL; + } + + UNIMPLEMENTED; + + return 0; } @@ -973,12 +981,12 @@ VOID STDCALL MmUnsecureVirtualMemory(PVOID SecureMem) { - if (NULL == SecureMem) - { - return; - } - - UNIMPLEMENTED; + if (NULL == SecureMem) + { + return; + } + + UNIMPLEMENTED; } @@ -986,34 +994,34 @@ * @implemented */ VOID STDCALL -ProbeForRead (IN CONST VOID *Address, +ProbeForRead(IN CONST VOID *Address, + IN ULONG Length, + IN ULONG Alignment) +{ + if (Length != 0) + { + ASSERT(Alignment == 1 || Alignment == 2 || Alignment == 4 || Alignment == 8); + + if (((ULONG_PTR)Address & (Alignment - 1)) != 0) + { + ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT); + } + else if ((ULONG_PTR)Address + Length - 1 < (ULONG_PTR)Address || + (ULONG_PTR)Address + Length - 1 >= (ULONG_PTR)MmUserProbeAddress) + { + ExRaiseStatus (STATUS_ACCESS_VIOLATION); + } + } +} + + +/* + * @implemented + */ +VOID STDCALL +ProbeForWrite(IN PVOID Address, IN ULONG Length, IN ULONG Alignment) -{ - if (Length != 0) - { - ASSERT(Alignment == 1 || Alignment == 2 || Alignment == 4 || Alignment == 8); - - if (((ULONG_PTR)Address & (Alignment - 1)) != 0) - { - ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT); - } - else if ((ULONG_PTR)Address + Length - 1 < (ULONG_PTR)Address || - (ULONG_PTR)Address + Length - 1 >= (ULONG_PTR)MmUserProbeAddress) - { - ExRaiseStatus (STATUS_ACCESS_VIOLATION); - } - } -} - - -/* - * @implemented - */ -VOID STDCALL -ProbeForWrite (IN PVOID Address, - IN ULONG Length, - IN ULONG Alignment) { volatile CHAR *Current; PCHAR Last;
17 years
1
0
0
0
[fireball] 31540: - Implement a helper registry key opening function to reduce code size. - http://www.tech-archive.net/Archive/Development/microsoft.public.development.device.drivers/2004-10/1623.html
by fireball@svn.reactos.org
Author: fireball Date: Wed Jan 2 00:01:28 2008 New Revision: 31540 URL:
http://svn.reactos.org/svn/reactos?rev=31540&view=rev
Log: - Implement a helper registry key opening function to reduce code size. -
http://www.tech-archive.net/Archive/Development/microsoft.public.developmen…
Modified: trunk/reactos/ntoskrnl/include/internal/io.h trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c Modified: trunk/reactos/ntoskrnl/include/internal/io.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
============================================================================== --- trunk/reactos/ntoskrnl/include/internal/io.h (original) +++ trunk/reactos/ntoskrnl/include/internal/io.h Wed Jan 2 00:01:28 2008 @@ -556,8 +556,14 @@ NTSTATUS IopInitializePnpServices( IN PDEVICE_NODE DeviceNode, - IN BOOLEAN BootDrivers) -; + IN BOOLEAN BootDrivers); + +NTSTATUS +IopOpenRegistryKeyEx( + PHANDLE KeyHandle, + HANDLE ParentKey, + PUNICODE_STRING Name, + ACCESS_MASK DesiredAccess); // // Initialization Routines Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.…
============================================================================== --- trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c (original) +++ trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c Wed Jan 2 00:01:28 2008 @@ -3303,6 +3303,30 @@ } } +NTSTATUS +IopOpenRegistryKeyEx(PHANDLE KeyHandle, + HANDLE ParentKey, + PUNICODE_STRING Name, + ACCESS_MASK DesiredAccess) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + NTSTATUS Status; + + PAGED_CODE(); + + *KeyHandle = NULL; + + InitializeObjectAttributes(&ObjectAttributes, + Name, + OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, + ParentKey, + NULL); + + Status = ZwOpenKey(KeyHandle, DesiredAccess, &ObjectAttributes); + + return Status; +} + static NTSTATUS INIT_FUNCTION NTAPI PnpDriverInitializeEmpty(IN struct _DRIVER_OBJECT *DriverObject, IN PUNICODE_STRING RegistryPath)
17 years
1
0
0
0
[fireball] 31539: - Move ENUM_ROOT to internal/io.h, so that io/driver.c can use it too. - Rewrite IopAttachFilterDrivers() to get rid of dangerous strings operations.
by fireball@svn.reactos.org
Author: fireball Date: Tue Jan 1 23:44:09 2008 New Revision: 31539 URL:
http://svn.reactos.org/svn/reactos?rev=31539&view=rev
Log: - Move ENUM_ROOT to internal/io.h, so that io/driver.c can use it too. - Rewrite IopAttachFilterDrivers() to get rid of dangerous strings operations. Modified: trunk/reactos/ntoskrnl/include/internal/io.h trunk/reactos/ntoskrnl/io/iomgr/driver.c trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c Modified: trunk/reactos/ntoskrnl/include/internal/io.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
============================================================================== --- trunk/reactos/ntoskrnl/include/internal/io.h (original) +++ trunk/reactos/ntoskrnl/include/internal/io.h Tue Jan 1 23:44:09 2008 @@ -45,6 +45,11 @@ #else #define IOTRACE(x, ...) DPRINT(__VA_ARGS__); #endif + +// +// Registry path to the enumeration root key +// +#define ENUM_ROOT L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum" // // Returns the type of METHOD_ used in this IOCTL Modified: trunk/reactos/ntoskrnl/io/iomgr/driver.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/driver.c…
============================================================================== --- trunk/reactos/ntoskrnl/io/iomgr/driver.c (original) +++ trunk/reactos/ntoskrnl/io/iomgr/driver.c Tue Jan 1 23:44:09 2008 @@ -571,16 +571,45 @@ PDEVICE_NODE DeviceNode, BOOLEAN Lower) { - RTL_QUERY_REGISTRY_TABLE QueryTable[2] = {{0}}; - PWCHAR KeyBuffer; + RTL_QUERY_REGISTRY_TABLE QueryTable[2] = {{0}}; + OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING Class; WCHAR ClassBuffer[40]; + UNICODE_STRING EnumRoot = RTL_CONSTANT_STRING(ENUM_ROOT); + HANDLE EnumRootKey, SubKey; NTSTATUS Status; + /* Open enumeration root key */ + InitializeObjectAttributes(&ObjectAttributes, + &EnumRoot, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = ZwOpenKey(&EnumRootKey, KEY_READ, &ObjectAttributes); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwOpenKey() failed with Status %08X\n", Status); + return Status; + } + + /* Open subkey */ + InitializeObjectAttributes(&ObjectAttributes, + &DeviceNode->InstancePath, + OBJ_CASE_INSENSITIVE, + EnumRootKey, + NULL); + Status = ZwOpenKey(&SubKey, KEY_READ, &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwOpenKey() failed with Status %08X\n", Status); + ZwClose(EnumRootKey); + return Status; + } + /* * First load the device filters */ - QueryTable[0].QueryRoutine = IopAttachFilterDriversCallback; if (Lower) QueryTable[0].Name = L"LowerFilters"; @@ -588,15 +617,9 @@ QueryTable[0].Name = L"UpperFilters"; QueryTable[0].Flags = RTL_QUERY_REGISTRY_REQUIRED; - KeyBuffer = ExAllocatePool( - PagedPool, - (49 * sizeof(WCHAR)) + DeviceNode->InstancePath.Length); - wcscpy(KeyBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\"); - wcscat(KeyBuffer, DeviceNode->InstancePath.Buffer); - RtlQueryRegistryValues( - RTL_REGISTRY_ABSOLUTE, - KeyBuffer, + RTL_REGISTRY_HANDLE, + (PWSTR)SubKey, QueryTable, DeviceNode, NULL); @@ -604,7 +627,6 @@ /* * Now get the class GUID */ - Class.Length = 0; Class.MaximumLength = 40 * sizeof(WCHAR); Class.Buffer = ClassBuffer; @@ -614,13 +636,15 @@ QueryTable[0].Flags = RTL_QUERY_REGISTRY_REQUIRED | RTL_QUERY_REGISTRY_DIRECT; Status = RtlQueryRegistryValues( - RTL_REGISTRY_ABSOLUTE, - KeyBuffer, + RTL_REGISTRY_HANDLE, + (PWSTR)SubKey, QueryTable, DeviceNode, NULL); - ExFreePool(KeyBuffer); + /* Close handles */ + ZwClose(SubKey); + ZwClose(EnumRootKey); /* * Load the class filter driver @@ -628,6 +652,34 @@ if (NT_SUCCESS(Status)) { + UNICODE_STRING ControlClass = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class"); + InitializeObjectAttributes(&ObjectAttributes, + &ControlClass, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = ZwOpenKey(&EnumRootKey, KEY_READ, &ObjectAttributes); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwOpenKey() failed with Status %08X\n", Status); + return Status; + } + + /* Open subkey */ + InitializeObjectAttributes(&ObjectAttributes, + &Class, + OBJ_CASE_INSENSITIVE, + EnumRootKey, + NULL); + Status = ZwOpenKey(&SubKey, KEY_READ, &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwOpenKey() failed with Status %08X\n", Status); + ZwClose(EnumRootKey); + return Status; + } + QueryTable[0].QueryRoutine = IopAttachFilterDriversCallback; if (Lower) QueryTable[0].Name = L"LowerFilters"; @@ -636,18 +688,16 @@ QueryTable[0].EntryContext = NULL; QueryTable[0].Flags = RTL_QUERY_REGISTRY_REQUIRED; - KeyBuffer = ExAllocatePool(PagedPool, (58 * sizeof(WCHAR)) + Class.Length); - wcscpy(KeyBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class\\"); - wcscat(KeyBuffer, ClassBuffer); - RtlQueryRegistryValues( - RTL_REGISTRY_ABSOLUTE, - KeyBuffer, + RTL_REGISTRY_HANDLE, + (PWSTR)SubKey, QueryTable, DeviceNode, NULL); - ExFreePool(KeyBuffer); + /* Clean up */ + ZwClose(SubKey); + ZwClose(EnumRootKey); } return STATUS_SUCCESS; Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.…
============================================================================== --- trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c (original) +++ trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c Tue Jan 1 23:44:09 2008 @@ -18,8 +18,6 @@ //#define ENABLE_ACPI /* GLOBALS *******************************************************************/ - -#define ENUM_ROOT L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum" PDEVICE_NODE IopRootDeviceNode; KSPIN_LOCK IopDeviceTreeLock;
17 years
1
0
0
0
← Newer
1
...
50
51
52
53
54
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Results per page:
10
25
50
100
200