📄 memplug.cpp
字号:
seiUpdateXIP.cbSize = sizeof(seiUpdateXIP);
seiUpdateXIP.fMask = SEE_MASK_NOCLOSEPROCESS;
seiUpdateXIP.hwnd = 0;
seiUpdateXIP.lpVerb = 0;
//wcscpy(fileWithDir,progName[g_focusIconIndex]);
seiUpdateXIP.lpFile = L"\\Storage\\Application Data\\Home\\hop_test.exe";
seiUpdateXIP.lpDirectory = 0;
seiUpdateXIP.lpParameters = L"hopper";
seiUpdateXIP.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&seiUpdateXIP);
UpdateWindow(FindWindow(L"DesktopExplorerWindow",NULL));
}
return(S_FALSE);
}
HRESULT hr = S_OK;
PluginFactory *pFactory = NULL;
if(rclsid == CLSID_PLUGMEM)
{
pFactory = new PluginFactory;
if(!pFactory)
{
hr = E_OUTOFMEMORY;
goto Error;
}
if(FAILED(pFactory->QueryInterface(riid, ppObject)))
{
hr = E_NOINTERFACE;
goto Error;
}
}
else
{
hr = CLASS_E_CLASSNOTAVAILABLE;
goto Error;
}
Error:
if(pFactory)
{
pFactory->Release();
}
return(hr);
}
STDAPI DllCanUnloadNow()
{
CreateLogFile_CallStack("DllCanUnloadNow");
if(g_dwDLLRefCount)
{
return S_FALSE;
}
else
{
return S_OK;
}
}
STDAPI DllRegisterServer(void)
{
CreateLogFile_CallStack("DllRegisterServer");
HRESULT hr = S_OK;
HKEY hKeyCLSID = NULL;
HKEY hKeyInproc32 = NULL;
DWORD dwDisposition;
HMODULE hModule;
TCHAR szName[MAX_PATH+1];
UINT index=0;
if(ERROR_SUCCESS != RegCreateKeyEx(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{") CLSIDTEXT__PLUGMEM TEXT("}"),
NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKeyCLSID, &dwDisposition))
{
hr = E_FAIL;
goto Error;
}
if(ERROR_SUCCESS != RegSetValueEx(hKeyCLSID, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("Demo Plugin"), sizeof(TEXT("Demo Plugin"))))
{
hr = E_FAIL;
goto Error;
}
if(ERROR_SUCCESS != RegCreateKeyEx(hKeyCLSID, TEXT("InprocServer32"),
NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKeyInproc32, &dwDisposition))
{
hr = E_FAIL;
goto Error;
}
hModule = GetModuleHandle(IMAGENAME);
if(!hModule)
{
hr = E_FAIL;
goto Error;
}
if(GetModuleFileName(hModule, szName, sizeof(szName))==0)
{
hr = E_FAIL;
goto Error;
}
if(ERROR_SUCCESS != RegSetValueEx(hKeyInproc32, TEXT(""), NULL, REG_SZ, (BYTE*) szName, sizeof(TCHAR)*(lstrlen(szName)+1)))
{
hr = E_FAIL;
goto Error;
}
#if 0
if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("IndexOfFocusIcon1"),
NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKeyIndexOfFocusIcon, &dwDisposition))
{
//wcscpy(szName,L"left");
UINT index=0;
RegSetValueEx(hKeyIndexOfFocusIcon, TEXT("Index"), NULL, REG_DWORD, (const BYTE *)&index, sizeof(index));
}
#else
if(ERROR_SUCCESS != RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("IndexOfFocusIcon1"),
NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKeyIndexOfFocusIcon, &dwDisposition))
{
hr = E_FAIL;
goto Error;
}
if(ERROR_SUCCESS !=RegSetValueEx(hKeyIndexOfFocusIcon, TEXT("Index"), NULL, REG_DWORD, (const BYTE *)&index, sizeof(index)))
{
hr = E_FAIL;
goto Error;
}
#endif
Error:
if(hKeyIndexOfFocusIcon)
{
RegCloseKey(hKeyIndexOfFocusIcon);
}
if(hKeyInproc32)
{
RegCloseKey(hKeyInproc32);
}
if(hKeyCLSID)
{
RegCloseKey(hKeyCLSID);
}
return(hr);
}
STDAPI DllUnregisterServer(void)
{
CreateLogFile_CallStack("DllUnregisterServer");
HRESULT hr = S_OK;
//andy
if(ERROR_SUCCESS != RegDeleteKey(HKEY_CLASSES_ROOT,
TEXT("IndexOfFocusIcon1\\Index")))
{
hr = E_FAIL;
goto Error;
}
if(ERROR_SUCCESS != RegDeleteKey(HKEY_CLASSES_ROOT,
TEXT("IndexOfFocusIcon1")))
{
hr = E_FAIL;
goto Error;
}
//end andylz
if(ERROR_SUCCESS != RegDeleteKey(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{") CLSIDTEXT__PLUGMEM TEXT("}\\InprocServer32")))
{
hr = E_FAIL;
goto Error;
}
if(ERROR_SUCCESS != RegDeleteKey(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{") CLSIDTEXT__PLUGMEM TEXT("}")))
{
hr = E_FAIL;
goto Error;
}
Error:
return(hr);
}
// ************************************************************
//
// Implementation of class PluginMem
//
// ************************************************************
PluginMem::PluginMem() :
m_cRef(1),
m_ppe(NULL),
m_bstrTitle(NULL),
m_cbStrBytes(0)
{
CreateLogFile_CallStack("PluginMem");
g_dwDLLRefCount++;
}
PluginMem::~PluginMem()
{
CreateLogFile_CallStack("~PluginMem");
g_dwDLLRefCount--;
if (m_bstrTitle)
{
SysFreeString(m_bstrTitle);
}
VariantClear(&m_varTitle);
}
HRESULT PluginMem::QueryInterface(
REFIID riid, void** ppObject
)
{
CreateLogFile_CallStack("QueryInterface");
HRESULT hr = S_OK;
if(IID_IUnknown == riid || IID_IObjectWithSite == riid || IID_IHomePlugin == riid)
{
*ppObject = (IHomePlugin*)this;
}
else if(IID_IPersist == riid || IID_IPersistStream == riid)
{
*ppObject = (IPersistStream*)this;
}
else
{
hr = E_NOINTERFACE;
goto Error;
}
AddRef();
Error:
return(hr);
}
// **********************************************************************
// Function Name: SetSite
//
// Description: Implements IObjectWithSite::SetSite method. This is
// called by the system to set a local reference to an
// IHomePluginEnvironment pointer, which can be used to force a redraw
// of the plugin, or set a one-time timer callback.
//
// See the SDK docs on IHomePluginEnvironment for more information
HRESULT PluginMem::SetSite(
IUnknown* pSite
)
{
CreateLogFile_CallStack("SetSite");
HRESULT hr = S_OK;
if(m_ppe)
{
m_ppe->Release();
m_ppe = NULL;
}
if(pSite)
{
if(FAILED(hr = pSite->QueryInterface(IID_IHomePluginEnvironment2, (void**)&m_ppe)))
{
goto Error;
}
}
Error:
return(hr);
}
// **********************************************************************
// Function Name: GetSite
//
// Description: Implementation of IObjectWithSite::GetSite
//
// See SDK documentation for more information
HRESULT PluginMem::GetSite(
REFIID riid,
void** ppvSite
)
{
CreateLogFile_CallStack("GetSite");
HRESULT hr = S_OK;
if(!m_ppe)
{
hr = E_FAIL;
goto Error;
}
if(FAILED(hr = m_ppe->QueryInterface(riid, ppvSite)))
{
goto Error;
}
Error:
return(hr);
}
// **********************************************************************
// Function Name: Initialize
//
// Purpose: Called from the Plugin Manager to provide data for the
// intermediate config file
//
// Arguments:
// IN HPLUGIN hPlugin - handle to plugin. Used for calls to
// IHomePluginEnvironment.
// IN IXMLDOMNode* pnodeParams - XML DOM node representing specific
// plugin configuration
// IN IXMLDOMNode* pnodeDefault - XML DOM node representing global
// plugin configuration (applying to all plugins)
//
// Return Values:
//
// HRESULT - S_OK if parsing operations succeed, E_FAIL otherwise
//
// Side effects:
// Data parsed and stored as member data in this function can only be
// used in the Save method below, as the other member functions are
// only called in seperate instance of this class (created by home.exe)
// instead of the Plugin Manager.
//
// Description:
// This function is called by the Plugin Manager exclusively when the
// plugin is FIRST LOADED from the Home Screen settings menu.
// Configuration data should be saved as member data to be written
// to an intermediate file via the Save method below
//
// See the ReadMe notes for more information
HRESULT PluginMem::Initialize(
HPLUGIN hPlugin,
IXMLDOMNode* pnodeParams,
IXMLDOMNode* pnodeDefault
)
{
CreateLogFile_CallStack("Initialize");
HRESULT hr = S_OK;
BSTR bstrVal = NULL;
IXMLDOMNode* pFoundNode = NULL;
IXMLDOMNamedNodeMap * DOMNamedNodeMapPtr = NULL;
DebugOut(TEXT("PluginMem::Initialize called \r\n"));
//Attribute of our XML plugin node to look for
bstrVal = SysAllocString(L"name");
if (bstrVal == NULL)
{
return E_OUTOFMEMORY;
}
if (FAILED(pnodeParams->get_attributes(&DOMNamedNodeMapPtr)))
{
return E_FAIL;
}
if (FAILED(DOMNamedNodeMapPtr->getNamedItem(bstrVal, &pFoundNode)))
{
return E_FAIL;
}
// store the string so we can write it out when Save is called
if (FAILED(pFoundNode->get_nodeValue(&m_varTitle)))
{
return E_FAIL;
}
if (m_varTitle.bstrVal != NULL)
{
// store the length of the string in bytes
m_cbStrBytes = SysStringByteLen(m_varTitle.bstrVal)+sizeof(WCHAR);
}
if (pFoundNode)
pFoundNode->Release();
if (DOMNamedNodeMapPtr)
DOMNamedNodeMapPtr->Release();
::SysFreeString(bstrVal);
m_hPlugin = hPlugin;
return(hr);
}
// **********************************************************************
// Function Name: GetHeight
//
// Purpose: Called from the home.exe process to ascertain plugin height.
// For this sample, we set the plugin height to be hard coded at 40
// pixels
//
// See SDK documentation for details
HRESULT PluginMem::GetHeight(
int* pdyPlugin
)
{
CreateLogFile_CallStack("GetHeight");
DebugOut(TEXT("PluginMem::GetHeight called \r\n"));
// hard-coded height for plugin. This could optionally be set with
// an XML attribute
if(COMPILE_FLAG==0)
{
*pdyPlugin = 50;
}
else if(COMPILE_FLAG==1)
{
*pdyPlugin = 60;
}
else
{
*pdyPlugin = 50;
}
return S_OK;
}
// **********************************************************************
// Function Name: GetSelectability
//
// Purpose: Called from the home.exe process to determine if plugin can
// be selected. For this sample, we want our plugin to be selectable
// spo we set the OUT param to TRUE
//
// See SDK documentation for details
HRESULT PluginMem::GetSelectability(BOOL* pfSelectable)
{
CreateLogFile_CallStack("GetSelectability");
HRESULT hr = S_OK;
DebugOut(TEXT("PluginMem::GetSelectability called \r\n"));
*pfSelectable = TRUE;
return(hr);
}
// **********************************************************************
// Function Name: OnEvent
//
// Purpose: Called from the home.exe process when a plugin event occurs.
//
// Arguments:
//
// PluginEvent * ppe - pointer to a Plugin Event struct
// Return Values:
//
// HRESULT - S_OK
//
// Side effects:
// Any member configuration data originating from the XML and used in
// this function MUST have been read from the Load method first, as
// the XML parsing in Initialize occured in a different object
// instance (and process!)
//
// Description:
// This function behaves like a watered down 'WndProc' callback. The
// system (home.exe) calls this function any time a relevant plugin
// event occurs. Of particular interest to us are the events PE_ACTION
// (plugin selected and clicked) and PE_PAINT (analogous to WM_PAINT)
//
// See SDK documentation for more details
HRESULT PluginMem::OnEvent(
PluginEvent* ppe
)
{
CreateLogFile_CallStack("OnEvent");
HRESULT hr = S_OK;
HDC hdc;
static PROCESS_INFORMATION pi;
HWND hCalendarWnd=NULL;
//TCHAR szName[MAX_PATH+1];
UINT index=0;
HKEY hKey=NULL;
UINT data=0;
DWORD dataSize=sizeof(data);
DWORD dataType;
//FILE *fw=NULL;
bool bEnd=false;
switch(ppe->idEvent)
{
case PE_KEYDOWN:
bEnd=false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -