Author: dquintana Date: Mon Sep 29 16:22:21 2014 New Revision: 64395
URL: http://svn.reactos.org/svn/reactos?rev=64395&view=rev Log: [RSHELL] * Implement skeleton shell dde parser.
[SHELL32] * Copy over the skeleton from rshell, and fill in the handlers for ViewFolder and ExploreFolder, with rudimentary implementations.
CORE-7552
Modified: branches/shell-experiments/base/shell/rshell/ShellDDE.cpp branches/shell-experiments/dll/win32/shell32/dde.cpp
Modified: branches/shell-experiments/base/shell/rshell/ShellDDE.cpp URL: http://svn.reactos.org/svn/reactos/branches/shell-experiments/base/shell/rsh... ============================================================================== --- branches/shell-experiments/base/shell/rshell/ShellDDE.cpp [iso-8859-1] (original) +++ branches/shell-experiments/base/shell/rshell/ShellDDE.cpp [iso-8859-1] Mon Sep 29 16:22:21 2014 @@ -21,8 +21,20 @@ #include "precomp.h" #include <ddeml.h> #include <strsafe.h> +#include <shlwapi_undoc.h>
WINE_DEFAULT_DEBUG_CHANNEL(shelldde); + +typedef DWORD(CALLBACK * pfnCommandHandler)(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS); + +struct DDECommandHandler +{ + WCHAR Command[32]; + pfnCommandHandler Handler; +}; + +extern DDECommandHandler HandlerList []; +extern const int HandlerListLength;
/* DDE Instance ID */ static DWORD dwDDEInst; @@ -34,6 +46,8 @@ static HSZ hszAppProperties; static HSZ hszFolders;
+static BOOL bInitialized; + static BOOL Dde_OnConnect(HSZ hszTopic, HSZ hszService) { WCHAR szTopic[MAX_PATH]; @@ -54,7 +68,7 @@
DdeQueryStringW(dwDDEInst, hszTopic, szTopic, _countof(szTopic), CP_WINUNICODE); DdeQueryStringW(dwDDEInst, hszService, szService, _countof(szService), CP_WINUNICODE); - + DbgPrint("Dde_OnConnectConfirm: hconv=%p, topic=%S, service=%S\n", hconv, szTopic, szService); }
@@ -82,6 +96,32 @@ DbgPrint("Dde_OnRequest: uFmt=%d, hconv=%p, topic=%S, item=%S\n", hconv, szTopic, szItem);
return NULL; +} + +static LPITEMIDLIST _ILReadFromSharedMemory(PCWSTR strField) +{ + LPITEMIDLIST ret = NULL; + + // Ensure it really is an IDLIST-formatted parameter + // Format for IDLIST params: ":pid:shared" + if (*strField != L':') + return NULL; + + HANDLE hData = (HANDLE) StrToIntW(strField + 1); + PWSTR strSecond = StrChrW(strField + 1, L':'); + + if (strSecond) + { + int pid = StrToIntW(strSecond + 1); + void* pvShared = SHLockShared(hData, pid); + if (pvShared) + { + ret = ILClone((LPCITEMIDLIST) pvShared); + SHUnlockShared(pvShared); + SHFreeShared(hData, pid); + } + } + return ret; }
static DWORD Dde_OnExecute(HCONV hconv, HSZ hszTopic, HDDEDATA hdata) @@ -92,7 +132,7 @@
DdeQueryStringW(dwDDEInst, hszTopic, szTopic, _countof(szTopic), CP_WINUNICODE);
- pszCommand = (WCHAR*)DdeAccessData(hdata, NULL); + pszCommand = (WCHAR*) DdeAccessData(hdata, NULL); if (!pszCommand) return DDE_FNOTPROCESSED;
@@ -103,15 +143,139 @@ DbgPrint("Dde_OnExecute: hconv=%p, topic=%S, command=%S\n", hconv, szTopic, pszCommand);
/* - [ViewFolder("%l", %I, %S)] -- Open a folder in standard mode [ExploreFolder("%l", %I, %S)] -- Open a folder in "explore" mode (file tree is shown to the left by default) [FindFolder("%l", %I)] -- Open a folder in "find" mode (search panel is shown to the left by default) [ShellFile("%1","%1",%S)] -- Execute the contents of the specified .SCF file - + + Approximate grammar (Upper names define rules, <lower> names define terminals, single-quotes are literals): + + Rules + Command = ('[' Function ']') | Function + Function = <identifier> '(' Parameters ')' + Parameters = (<quoted-string> (',' <idlist> (',' <number>)?)?)? + + Terminals + <identifier> = [a-zA-Z]+ + <quoted-string> = "([^"]|\.)" + <idlist> = :[0-9]+:[0-9]+ + <number> = [0-9]+ */
- return DDE_FACK; + WCHAR Command[MAX_PATH] = L""; + WCHAR Path[MAX_PATH] = L""; + LPITEMIDLIST IdList = NULL; + INT UnknownParameter = 0; + + // Simplified parsing (assumes the command will not be TOO broken): + + PWSTR cmd = szCommand; + // 1. if starts with [, skip first char + if (*cmd == L'[') + cmd++; + + if (*cmd == L']') + { + ERR("Empty command. Nothing to run.\n"); + return DDE_FNOTPROCESSED; + } + + // Read until first (, and take text before ( as command name + { + PWSTR cmdEnd = StrChrW(cmd, L'('); + + if (!cmdEnd) + { + ERR("Could not find '('. Invalid command.\n"); + return DDE_FNOTPROCESSED; + } + + *cmdEnd = 0; + + StringCchCopy(Command, _countof(Command), cmd); + + cmd = cmdEnd + 1; + } + + // Read first param after (, expecting quoted string + if (*cmd != L')') + { + // Copy unescaped string + PWSTR dst = Path; + BOOL isQuote = FALSE; + + PWSTR arg = cmd; + + while (*arg && (isQuote || *arg != L',')) + { + if (*arg == L'"') + { + isQuote = !isQuote; + if (isQuote && arg != cmd) // do not copy the " at the beginning of the string + { + *(dst++) = L'"'; + } + } + else + { + *(dst++) = *arg; + } + + arg++; + } + + cmd = arg + 1; + + while (*cmd == L' ') + cmd++; + } + + // Read second param, expecting an idlist in shared memory + if (*cmd != L')') + { + if (*cmd != ':') + { + ERR("Expected ':'. Invalid command.\n"); + return DDE_FNOTPROCESSED; + } + + PWSTR idlistEnd = StrChrW(cmd, L','); + + if (!idlistEnd) + idlistEnd = StrChrW(cmd, L')'); + + if (!idlistEnd) + { + ERR("Expected ',' or ')'. Invalid command.\n"); + return DDE_FNOTPROCESSED; + } + + IdList = _ILReadFromSharedMemory(cmd); + + cmd = idlistEnd + 1; + } + + // Read third param, expecting an integer + if (*cmd != L')') + { + UnknownParameter = StrToIntW(cmd); + } + + DbgPrint("Parse end: cmd=%S, S=%d, pidl=%p, path=%S\n", Command, UnknownParameter, IdList, Path); + + // Find handler in list + for (int i = 0; i < HandlerListLength; i++) + { + DDECommandHandler & handler = HandlerList[i]; + if (StrCmpW(handler.Command, Command) == 0) + { + return handler.Handler(Command, Path, IdList, UnknownParameter); + } + } + + // No handler found + ERR("Unknown command %S\n", Command); + return DDE_FNOTPROCESSED; }
static void Dde_OnDisconnect(HCONV hconv) @@ -132,26 +296,26 @@ switch (uType) { case XTYP_CONNECT: - return (HDDEDATA)(DWORD_PTR)Dde_OnConnect(hsz1, hsz2); + return (HDDEDATA) (DWORD_PTR) Dde_OnConnect(hsz1, hsz2); case XTYP_CONNECT_CONFIRM: Dde_OnConnectConfirm(hconv, hsz1, hsz2); return NULL; case XTYP_WILDCONNECT: - return (HDDEDATA)(DWORD_PTR)Dde_OnWildConnect(hsz1, hsz2); + return (HDDEDATA) (DWORD_PTR) Dde_OnWildConnect(hsz1, hsz2); case XTYP_REQUEST: return Dde_OnRequest(uFmt, hconv, hsz1, hsz2); case XTYP_EXECUTE: - return (HDDEDATA)(DWORD_PTR)Dde_OnExecute(hconv, hsz1, hdata); + return (HDDEDATA) (DWORD_PTR) Dde_OnExecute(hconv, hsz1, hdata); case XTYP_DISCONNECT: Dde_OnDisconnect(hconv); return NULL; + case XTYP_REGISTER: + return NULL; default: DbgPrint("DdeCallback: unknown uType=%d\n", uType); - case XTYP_REGISTER: return NULL; } } - /************************************************************************* * ShellDDEInit (SHELL32.@) * @@ -168,7 +332,7 @@ { DbgPrint("ShellDDEInit bInit = %s\n", bInit ? "TRUE" : "FALSE");
- if (bInit) + if (bInit && !bInitialized) { DdeInitializeW(&dwDDEInst, DdeCallback, CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
@@ -178,19 +342,67 @@ hszAppProperties = DdeCreateStringHandleW(dwDDEInst, L"AppProperties", CP_WINUNICODE); hszFolders = DdeCreateStringHandleW(dwDDEInst, L"Folders", CP_WINUNICODE);
- DdeNameService(dwDDEInst, hszFolders, 0, DNS_FILTEROFF); - } - else + if (hszProgmanTopic && hszProgmanService && + hszShell && hszAppProperties && hszFolders && + DdeNameService(dwDDEInst, hszFolders, 0, DNS_REGISTER) && + DdeNameService(dwDDEInst, hszProgmanService, 0, DNS_REGISTER) && + DdeNameService(dwDDEInst, hszShell, 0, DNS_REGISTER)) + { + bInitialized = TRUE; + } + } + else if (!bInit && bInitialized) { /* unregister all services */ DdeNameService(dwDDEInst, 0, 0, DNS_UNREGISTER);
- DdeFreeStringHandle(dwDDEInst, hszFolders); - DdeFreeStringHandle(dwDDEInst, hszAppProperties); - DdeFreeStringHandle(dwDDEInst, hszShell); - DdeFreeStringHandle(dwDDEInst, hszProgmanService); - DdeFreeStringHandle(dwDDEInst, hszProgmanTopic); + if (hszFolders) + DdeFreeStringHandle(dwDDEInst, hszFolders); + if (hszAppProperties) + DdeFreeStringHandle(dwDDEInst, hszAppProperties); + if (hszShell) + DdeFreeStringHandle(dwDDEInst, hszShell); + if (hszProgmanService) + DdeFreeStringHandle(dwDDEInst, hszProgmanService); + if (hszProgmanTopic) + DdeFreeStringHandle(dwDDEInst, hszProgmanTopic);
DdeUninitialize(dwDDEInst); - } -} + + bInitialized = FALSE; + } +} + +static DWORD CALLBACK DDE_OnViewFolder(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) +{ + UNIMPLEMENTED; + return DDE_FACK; +} + +static DWORD CALLBACK DDW_OnExploreFolder(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) +{ + UNIMPLEMENTED; + return DDE_FACK; +} + +static DWORD CALLBACK DDE_OnFindFolder(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) +{ + UNIMPLEMENTED; + return DDE_FNOTPROCESSED; +} + +static DWORD CALLBACK DDE_OnShellFile(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) +{ + UNIMPLEMENTED; + return DDE_FNOTPROCESSED; +} + +DDECommandHandler HandlerList [] = { + + { L"ViewFolder", DDE_OnViewFolder }, + { L"ExploreFolder", DDW_OnExploreFolder }, + { L"FindFolder", DDE_OnFindFolder }, + { L"ShellFile", DDE_OnShellFile } +}; + +const int HandlerListLength = _countof(HandlerList);
Modified: branches/shell-experiments/dll/win32/shell32/dde.cpp URL: http://svn.reactos.org/svn/reactos/branches/shell-experiments/dll/win32/shel... ============================================================================== --- branches/shell-experiments/dll/win32/shell32/dde.cpp [iso-8859-1] (original) +++ branches/shell-experiments/dll/win32/shell32/dde.cpp [iso-8859-1] Mon Sep 29 16:22:21 2014 @@ -19,69 +19,268 @@ */
#include "precomp.h" - -WINE_DEFAULT_DEBUG_CHANNEL(shell); +#include <ddeml.h> +#include <strsafe.h> +#include <shlwapi_undoc.h> + +WINE_DEFAULT_DEBUG_CHANNEL(shelldde); + +typedef DWORD(CALLBACK * pfnCommandHandler)(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS); + +struct DDECommandHandler +{ + WCHAR Command[32]; + pfnCommandHandler Handler; +}; + +extern DDECommandHandler HandlerList []; +extern const int HandlerListLength; + +/* DDE Instance ID */ +static DWORD dwDDEInst;
/* String handles */ static HSZ hszProgmanTopic; static HSZ hszProgmanService; -static HSZ hszAsterisk; static HSZ hszShell; static HSZ hszAppProperties; static HSZ hszFolders; -/* DDE Instance ID */ -static DWORD dwDDEInst; - - -static BOOL __inline Dde_OnConnect(HSZ hszTopic, HSZ hszService) -{ - if ((hszTopic == hszProgmanTopic) && (hszService == hszProgmanService)) - return TRUE; - if ((hszTopic == hszProgmanTopic) && (hszService == hszAppProperties)) - return TRUE; - if ((hszTopic == hszShell) && (hszService == hszFolders)) - return TRUE; - if ((hszTopic == hszShell) && (hszService == hszAppProperties)) - return TRUE; + +static BOOL bInitialized; + +static BOOL Dde_OnConnect(HSZ hszTopic, HSZ hszService) +{ + WCHAR szTopic[MAX_PATH]; + WCHAR szService[MAX_PATH]; + + DdeQueryStringW(dwDDEInst, hszTopic, szTopic, _countof(szTopic), CP_WINUNICODE); + DdeQueryStringW(dwDDEInst, hszService, szService, _countof(szService), CP_WINUNICODE); + + DbgPrint("Dde_OnConnect: topic=%S, service=%S\n", szTopic, szService); + + return TRUE; +} + +static void Dde_OnConnectConfirm(HCONV hconv, HSZ hszTopic, HSZ hszService) +{ + WCHAR szTopic[MAX_PATH]; + WCHAR szService[MAX_PATH]; + + DdeQueryStringW(dwDDEInst, hszTopic, szTopic, _countof(szTopic), CP_WINUNICODE); + DdeQueryStringW(dwDDEInst, hszService, szService, _countof(szService), CP_WINUNICODE); + + DbgPrint("Dde_OnConnectConfirm: hconv=%p, topic=%S, service=%S\n", hconv, szTopic, szService); +} + +static BOOL Dde_OnWildConnect(HSZ hszTopic, HSZ hszService) +{ + WCHAR szTopic[MAX_PATH]; + WCHAR szService[MAX_PATH]; + + DdeQueryStringW(dwDDEInst, hszTopic, szTopic, _countof(szTopic), CP_WINUNICODE); + DdeQueryStringW(dwDDEInst, hszService, szService, _countof(szService), CP_WINUNICODE); + + DbgPrint("Dde_OnWildConnect: topic=%S, service=%S\n", szTopic, szService); + return FALSE; }
-static void __inline Dde_OnConnectConfirm(HCONV hconv, HSZ hszTopic, HSZ hszService) -{ - FIXME("stub\n"); -} - -static BOOL __inline Dde_OnWildConnect(HSZ hszTopic, HSZ hszService) -{ - FIXME("stub\n"); - return FALSE; -} - -static HDDEDATA __inline Dde_OnRequest(UINT uFmt, HCONV hconv, HSZ hszTopic, - HSZ hszItem) -{ - FIXME("stub\n"); +static HDDEDATA Dde_OnRequest(UINT uFmt, HCONV hconv, HSZ hszTopic, HSZ hszItem) +{ + WCHAR szTopic[MAX_PATH]; + WCHAR szItem[MAX_PATH]; + + DdeQueryStringW(dwDDEInst, hszTopic, szTopic, _countof(szTopic), CP_WINUNICODE); + DdeQueryStringW(dwDDEInst, hszItem, szItem, _countof(szItem), CP_WINUNICODE); + + DbgPrint("Dde_OnRequest: uFmt=%d, hconv=%p, topic=%S, item=%S\n", hconv, szTopic, szItem); + return NULL; }
-static DWORD __inline Dde_OnExecute(HCONV hconv, HSZ hszTopic, HDDEDATA hdata) -{ - BYTE * pszCommand; - - pszCommand = DdeAccessData(hdata, NULL); +static LPITEMIDLIST _ILReadFromSharedMemory(PCWSTR strField) +{ + LPITEMIDLIST ret = NULL; + + // Ensure it really is an IDLIST-formatted parameter + // Format for IDLIST params: ":pid:shared" + if (*strField != L':') + return NULL; + + HANDLE hData = (HANDLE) StrToIntW(strField + 1); + PWSTR strSecond = StrChrW(strField + 1, L':'); + + if (strSecond) + { + int pid = StrToIntW(strSecond + 1); + void* pvShared = SHLockShared(hData, pid); + if (pvShared) + { + ret = ILClone((LPCITEMIDLIST) pvShared); + SHUnlockShared(pvShared); + SHFreeShared(hData, pid); + } + } + return ret; +} + +static DWORD Dde_OnExecute(HCONV hconv, HSZ hszTopic, HDDEDATA hdata) +{ + WCHAR szTopic[MAX_PATH]; + WCHAR szCommand[MAX_PATH]; + WCHAR *pszCommand; + + DdeQueryStringW(dwDDEInst, hszTopic, szTopic, _countof(szTopic), CP_WINUNICODE); + + pszCommand = (WCHAR*) DdeAccessData(hdata, NULL); if (!pszCommand) return DDE_FNOTPROCESSED;
- FIXME("stub: %s\n", pszCommand); + StringCchCopyW(szCommand, _countof(szCommand), pszCommand);
DdeUnaccessData(hdata);
+ DbgPrint("Dde_OnExecute: hconv=%p, topic=%S, command=%S\n", hconv, szTopic, pszCommand); + + /* + [ViewFolder("%l", %I, %S)] -- Open a folder in standard mode + [ExploreFolder("%l", %I, %S)] -- Open a folder in "explore" mode (file tree is shown to the left by default) + [FindFolder("%l", %I)] -- Open a folder in "find" mode (search panel is shown to the left by default) + [ShellFile("%1","%1",%S)] -- Execute the contents of the specified .SCF file + + Approximate grammar (Upper names define rules, <lower> names define terminals, single-quotes are literals): + + Rules + Command = ('[' Function ']') | Function + Function = <identifier> '(' Parameters ')' + Parameters = (<quoted-string> (',' <idlist> (',' <number>)?)?)? + + Terminals + <identifier> = [a-zA-Z]+ + <quoted-string> = "([^"]|\.)" + <idlist> = :[0-9]+:[0-9]+ + <number> = [0-9]+ + */ + + WCHAR Command[MAX_PATH] = L""; + WCHAR Path[MAX_PATH] = L""; + LPITEMIDLIST IdList = NULL; + INT UnknownParameter = 0; + + // Simplified parsing (assumes the command will not be TOO broken): + + PWSTR cmd = szCommand; + // 1. if starts with [, skip first char + if (*cmd == L'[') + cmd++; + + if (*cmd == L']') + { + ERR("Empty command. Nothing to run.\n"); + return DDE_FNOTPROCESSED; + } + + // Read until first (, and take text before ( as command name + { + PWSTR cmdEnd = StrChrW(cmd, L'('); + + if (!cmdEnd) + { + ERR("Could not find '('. Invalid command.\n"); + return DDE_FNOTPROCESSED; + } + + *cmdEnd = 0; + + StringCchCopy(Command, _countof(Command), cmd); + + cmd = cmdEnd + 1; + } + + // Read first param after (, expecting quoted string + if (*cmd != L')') + { + // Copy unescaped string + PWSTR dst = Path; + BOOL isQuote = FALSE; + + PWSTR arg = cmd; + + while (*arg && (isQuote || *arg != L',')) + { + if (*arg == L'"') + { + isQuote = !isQuote; + if (isQuote && arg != cmd) // do not copy the " at the beginning of the string + { + *(dst++) = L'"'; + } + } + else + { + *(dst++) = *arg; + } + + arg++; + } + + cmd = arg + 1; + + while (*cmd == L' ') + cmd++; + } + + // Read second param, expecting an idlist in shared memory + if (*cmd != L')') + { + if (*cmd != ':') + { + ERR("Expected ':'. Invalid command.\n"); + return DDE_FNOTPROCESSED; + } + + PWSTR idlistEnd = StrChrW(cmd, L','); + + if (!idlistEnd) + idlistEnd = StrChrW(cmd, L')'); + + if (!idlistEnd) + { + ERR("Expected ',' or ')'. Invalid command.\n"); + return DDE_FNOTPROCESSED; + } + + IdList = _ILReadFromSharedMemory(cmd); + + cmd = idlistEnd + 1; + } + + // Read third param, expecting an integer + if (*cmd != L')') + { + UnknownParameter = StrToIntW(cmd); + } + + DbgPrint("Parse end: cmd=%S, S=%d, pidl=%p, path=%S\n", Command, UnknownParameter, IdList, Path); + + // Find handler in list + for (int i = 0; i < HandlerListLength; i++) + { + DDECommandHandler & handler = HandlerList[i]; + if (StrCmpW(handler.Command, Command) == 0) + { + return handler.Handler(Command, Path, IdList, UnknownParameter); + } + } + + // No handler found + ERR("Unknown command %S\n", Command); return DDE_FNOTPROCESSED; }
-static void __inline Dde_OnDisconnect(HCONV hconv) -{ - FIXME("stub\n"); +static void Dde_OnDisconnect(HCONV hconv) +{ + DbgPrint("Dde_OnDisconnect: hconv=%p\n", hconv); }
static HDDEDATA CALLBACK DdeCallback( @@ -97,24 +296,26 @@ switch (uType) { case XTYP_CONNECT: - return (HDDEDATA)(DWORD_PTR)Dde_OnConnect(hsz1, hsz2); + return (HDDEDATA) (DWORD_PTR) Dde_OnConnect(hsz1, hsz2); case XTYP_CONNECT_CONFIRM: Dde_OnConnectConfirm(hconv, hsz1, hsz2); return NULL; case XTYP_WILDCONNECT: - return (HDDEDATA)(DWORD_PTR)Dde_OnWildConnect(hsz1, hsz2); + return (HDDEDATA) (DWORD_PTR) Dde_OnWildConnect(hsz1, hsz2); case XTYP_REQUEST: return Dde_OnRequest(uFmt, hconv, hsz1, hsz2); case XTYP_EXECUTE: - return (HDDEDATA)(DWORD_PTR)Dde_OnExecute(hconv, hsz1, hdata); + return (HDDEDATA) (DWORD_PTR) Dde_OnExecute(hconv, hsz1, hdata); case XTYP_DISCONNECT: Dde_OnDisconnect(hconv); return NULL; + case XTYP_REGISTER: + return NULL; default: + DbgPrint("DdeCallback: unknown uType=%d\n", uType); return NULL; } } - /************************************************************************* * ShellDDEInit (SHELL32.@) * @@ -129,42 +330,95 @@ */ EXTERN_C void WINAPI ShellDDEInit(BOOL bInit) { - TRACE("bInit = %s\n", bInit ? "TRUE" : "FALSE"); - - if (bInit) - { - static const WCHAR wszProgman[] = {'P','r','o','g','m','a','n',0}; - static const WCHAR wszAsterisk[] = {'*',0}; - static const WCHAR wszShell[] = {'S','h','e','l','l',0}; - static const WCHAR wszAppProperties[] = - {'A','p','p','P','r','o','p','e','r','t','i','e','s',0}; - static const WCHAR wszFolders[] = {'F','o','l','d','e','r','s',0}; - + DbgPrint("ShellDDEInit bInit = %s\n", bInit ? "TRUE" : "FALSE"); + + if (bInit && !bInitialized) + { DdeInitializeW(&dwDDEInst, DdeCallback, CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
- hszProgmanTopic = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE); - hszProgmanService = DdeCreateStringHandleW(dwDDEInst, wszProgman, CP_WINUNICODE); - hszAsterisk = DdeCreateStringHandleW(dwDDEInst, wszAsterisk, CP_WINUNICODE); - hszShell = DdeCreateStringHandleW(dwDDEInst, wszShell, CP_WINUNICODE); - hszAppProperties = DdeCreateStringHandleW(dwDDEInst, wszAppProperties, CP_WINUNICODE); - hszFolders = DdeCreateStringHandleW(dwDDEInst, wszFolders, CP_WINUNICODE); - - DdeNameService(dwDDEInst, hszFolders, 0, DNS_REGISTER); - DdeNameService(dwDDEInst, hszProgmanService, 0, DNS_REGISTER); - DdeNameService(dwDDEInst, hszShell, 0, DNS_REGISTER); - } - else + hszProgmanTopic = DdeCreateStringHandleW(dwDDEInst, L"Progman", CP_WINUNICODE); + hszProgmanService = DdeCreateStringHandleW(dwDDEInst, L"Progman", CP_WINUNICODE); + hszShell = DdeCreateStringHandleW(dwDDEInst, L"Shell", CP_WINUNICODE); + hszAppProperties = DdeCreateStringHandleW(dwDDEInst, L"AppProperties", CP_WINUNICODE); + hszFolders = DdeCreateStringHandleW(dwDDEInst, L"Folders", CP_WINUNICODE); + + if (hszProgmanTopic && hszProgmanService && + hszShell && hszAppProperties && hszFolders && + DdeNameService(dwDDEInst, hszFolders, 0, DNS_REGISTER) && + DdeNameService(dwDDEInst, hszProgmanService, 0, DNS_REGISTER) && + DdeNameService(dwDDEInst, hszShell, 0, DNS_REGISTER)) + { + bInitialized = TRUE; + } + } + else if (!bInit && bInitialized) { /* unregister all services */ DdeNameService(dwDDEInst, 0, 0, DNS_UNREGISTER);
- DdeFreeStringHandle(dwDDEInst, hszFolders); - DdeFreeStringHandle(dwDDEInst, hszAppProperties); - DdeFreeStringHandle(dwDDEInst, hszShell); - DdeFreeStringHandle(dwDDEInst, hszAsterisk); - DdeFreeStringHandle(dwDDEInst, hszProgmanService); - DdeFreeStringHandle(dwDDEInst, hszProgmanTopic); + if (hszFolders) + DdeFreeStringHandle(dwDDEInst, hszFolders); + if (hszAppProperties) + DdeFreeStringHandle(dwDDEInst, hszAppProperties); + if (hszShell) + DdeFreeStringHandle(dwDDEInst, hszShell); + if (hszProgmanService) + DdeFreeStringHandle(dwDDEInst, hszProgmanService); + if (hszProgmanTopic) + DdeFreeStringHandle(dwDDEInst, hszProgmanTopic);
DdeUninitialize(dwDDEInst); - } -} + + bInitialized = FALSE; + } +} + +static DWORD CALLBACK DDE_OnViewFolder(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) +{ + if (!pidl) + pidl = ILCreateFromPathW(strPath); + + if (!pidl) + return DDE_FNOTPROCESSED; + + if (FAILED(SHOpenNewFrame(pidl, NULL, 0, 0))) + return DDE_FNOTPROCESSED; + + return DDE_FACK; +} + +static DWORD CALLBACK DDW_OnExploreFolder(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) +{ + if (!pidl) + pidl = ILCreateFromPathW(strPath); + + if (!pidl) + return DDE_FNOTPROCESSED; + + if (FAILED(SHOpenNewFrame(pidl, NULL, 0, SH_EXPLORER_CMDLINE_FLAG_E))) + return DDE_FNOTPROCESSED; + + return DDE_FACK; +} + +static DWORD CALLBACK DDE_OnFindFolder(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) +{ + UNIMPLEMENTED; + return DDE_FNOTPROCESSED; +} + +static DWORD CALLBACK DDE_OnShellFile(PWSTR strCommand, PWSTR strPath, LPITEMIDLIST pidl, INT unkS) +{ + UNIMPLEMENTED; + return DDE_FNOTPROCESSED; +} + +DDECommandHandler HandlerList [] = { + + { L"ViewFolder", DDE_OnViewFolder }, + { L"ExploreFolder", DDW_OnExploreFolder }, + { L"FindFolder", DDE_OnFindFolder }, + { L"ShellFile", DDE_OnShellFile } +}; + +const int HandlerListLength = _countof(HandlerList);