📄 serdmaplugin.cpp
字号:
//********************************************************************************************
// CSERDMAPlugIn::QueryContextMenu
//
// Purpose:
// Adds commands to a shortcut menu.
//
// Parameters:
// hmenu = INPUT - Handle to the menu.
// indexMenu = INPUT - Zero-based position at which to insert the first menu item.
// idCmdFirst = INPUT - Minimum value that the handler can specify for a menu item identifier.
// idCmdLast = INPUT - Maximum value that the handler can specify for a menu item identifier.
// uFlags = INPUT - Optional flags specifying how the shortcut menu can be changed.
//
// Returns:
// HRESULT indicating success
//********************************************************************************************
STDMETHODIMP CSERDMAPlugIn::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
WCHAR *szToolBar = (WCHAR*)LoadString (g_hInstance, IDS_SERDMASYNC_TOOLBAR, NULL, 0);
//Add the menu item
BOOL fSuccess = InsertMenu(hmenu, indexMenu, MF_BYPOSITION | MF_STRING, idCmdFirst, szToolBar);
HRESULT hr = E_FAIL;
if (fSuccess) {
hr = S_OK | 1; // Added 1 menu item.
}
return hr;
}
//********************************************************************************************
// CSERDMAPlugIn::InvokeCommand
//
// Purpose:
// Carries out the command associated with a shortcut menu item.
//
// Parameters:
// lpici = INPUT - Pointer to a CMINVOKECOMMANDINFO structure containing information
// about the command.
//
// Returns:
// HRESULT indicating success
//********************************************************************************************
STDMETHODIMP CSERDMAPlugIn::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
{
HRESULT hr = S_OK;
WCHAR wszCmdLine[64];
HWND hwndRna = NULL;
if(strcmp(c_szCommand, lpici->lpVerb))
{
hr = E_NOTIMPL;
goto Exit;
}
//Look for a running instance of RNAApp
EnumWindows(FindRNAAppWindow, (LPARAM)&hwndRna);
if ( !hwndRna ) //None found, so start it now
{
wsprintf( wszCmdLine, c_wszRnaCmdParam, c_wszSERDMAReplEntryName);
if ( !CreateProcess( c_wszRnaApp, wszCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL ) )
{
hr = E_FAIL;
goto Exit;
}
}
else //Found a previous instance
{
RASCONN RasConn[4];
DWORD dwSize = sizeof(RasConn);
DWORD dwConn = 0;
BOOL fSimConn = FALSE;
//Check to see if we are already connected
RasConn[0].dwSize = sizeof(RASCONN);
if ( !RasEnumConnections( RasConn, &dwSize, &dwConn ) )
{
DWORD i=0;
for (i=0;i<dwConn;i++)
{
RASCONNSTATUS RasConnStatus;
if ( !lstrcmp( RasConn[i].szEntryName, c_wszSERDMAReplEntryName ) )
{
if ( !RasGetConnectStatus( RasConn[i].hrasconn, &RasConnStatus ) )
{
if ( RasConnStatus.rasconnstate == RASCS_Connected )
{
fSimConn = TRUE;
HWND hwndRepllog = FindWindow(c_wszReplWnd, NULL); //Look for the active sync window
PostMessage( hwndRna, RNA_RASCMD, (WPARAM)RNA_GETINFO, (LPARAM)hwndRepllog );
}
}
break;
}
}
}
if ( !fSimConn )
hr = E_FAIL;
}
Exit:
return hr;
}
//********************************************************************************************
// CSERDMAPlugIn::GetCommandString
//
// Purpose:
// Retrieves information about a shortcut menu command, including the Help string and
// the language-independent, or canonical, name for the command.
//
// Parameters:
// idCmd = INPUT - Menu command identifier offset.
// uType = INPUT - Flags specifying the information to return
// pwReserved = INPUT - Reserved.
// pszName = INPUT - Address of the buffer to receive the null-terminated string
// being retrieved.
// cchMax = INPUT - Size of the buffer to receive the null-terminated string.
//
// Returns:
// HRESULT indicating success
//********************************************************************************************
STDMETHODIMP CSERDMAPlugIn::GetCommandString(UINT idCmd, UINT uType, UINT * pwReserved, LPSTR pszName, UINT cchMax)
{
if(cchMax < sizeof(c_szCommand))
{
return E_FAIL;
}
strcpy(pszName, c_szCommand);
return S_OK;;
}
//********************************************************************************************
// CSERDMAPlugSite::constructor
//********************************************************************************************
CSERDMAPlugSite::CSERDMAPlugSite() :
m_lRefCount(1)
{
DllAddRef();
}
//********************************************************************************************
// CSERDMAPlugSite::destructors
//********************************************************************************************
CSERDMAPlugSite::~CSERDMAPlugSite()
{
DllRelease();
};
//********************************************************************************************
// CSERDMAPlugSite::QueryInterface
//
// Purpose:
// Standard QI. We support IMassNotifyLayer and IUnknown.
//
// Parameters:
// riid = INPUT - IID of interface to QI for
// ppv = OUTPUT - where interface point is placed
//
// Returns:
// HRESULT indicating success
//********************************************************************************************
STDMETHODIMP CSERDMAPlugSite::QueryInterface(REFIID riid, LPVOID *ppv)
{
HRESULT hr = S_OK;
//
// Check parameters
//
if (ppv == NULL)
{
hr = E_INVALIDARG;
goto Exit;
}
//
// Initialize [out] parameters
//
*ppv = NULL;
//
// Find IID
//
if (riid == IID_IUnknown)
{
*ppv = static_cast<IUnknown*>(this);
}
else if (riid == IID_IObjectWithSite)
{
*ppv = static_cast<IObjectWithSite*>(this);
}
else
{
hr = E_NOINTERFACE;
goto Exit;
}
//
// AddRef the outgoing interface
//
static_cast<IUnknown *>(*ppv)->AddRef();
hr = S_OK;
Exit:
return hr;
}
//********************************************************************************************
// CSERDMAPlugSite::AddRef
//
// Purpose:
// Standard IUnknown::AddRef() implementation.
//
// Returns:
// ULONG indicating ref count
//********************************************************************************************
STDMETHODIMP_(ULONG) CSERDMAPlugSite::AddRef(void)
{
return ::InterlockedIncrement(&m_lRefCount);
}
//********************************************************************************************
// CSERDMAPlugSite::Release
//
// Purpose:
// Standard IUnknown::Release implementation.
//
// Returns:
// ULONG indicating current ref count
//********************************************************************************************
STDMETHODIMP_(ULONG) CSERDMAPlugSite::Release(void)
{
if (::InterlockedDecrement(&m_lRefCount) == 0)
{
delete this;
return 0;
}
return m_lRefCount;
}
//********************************************************************************************
// CSERDMAPlugIn::SetSite
//
// Purpose:
// Sets the site for the internal pointer to punkParent.
//
// Parameters:
// pUnkSite = Pointer to the IUnknown interface pointer of the site managing this object.
//
// Returns:
// HRESULT indicating success
//********************************************************************************************
STDMETHODIMP CSERDMAPlugSite::SetSite(IUnknown* pUnkSite)
{
return S_OK;
}
//********************************************************************************************
// CSERDMAPlugIn::GetSite
//
// Purpose:
// This method queries the site for a pointer to the interface identified by riid
//
// Parameters:
// riid = INPUT - The IID of the interface pointer that should be returned in ppvSite.
// ppvSite = OUTPUT - Address of pointer variable that receives the interface pointer
// requested in riid.
//
// Returns:
// HRESULT indicating success
//********************************************************************************************
STDMETHODIMP CSERDMAPlugSite::GetSite(REFIID riid, void** ppvSite)
{
return E_FAIL;
}
//********************************************************************************************
// DllRegisterServer
//
// Purpose:
// This function instructs an in-process server to create its registry entries for
// all classes supported in this server module. If this function fails, the state of
// the registry for all its classes is indeterminate.
//
// Returns:
// HRESULT indicating success
//********************************************************************************************
STDAPI DllRegisterServer()
{
LONG lRet;
HKEY hKey = NULL;
DWORD dwTrue = TRUE;
DWORD dwDisposition;
HRESULT hr = E_FAIL;
WCHAR *szToolBar = (WCHAR*)LoadString (g_hInstance, IDS_SERDMASYNC_TOOLBAR, NULL, 0);
//IContexMenu
lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, c_wszRegKey, 0, NULL, 0, 0, NULL, &hKey, &dwDisposition);
if(ERROR_SUCCESS != lRet)
{
goto Exit;
}
lRet = RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)szToolBar, (wcslen(szToolBar)+1)*sizeof(WCHAR));
if(ERROR_SUCCESS != lRet)
{
goto Exit;
}
lRet = RegSetValueEx(hKey, c_wszDelay, 0, REG_DWORD, (BYTE*)&dwTrue, sizeof(dwTrue));
if(ERROR_SUCCESS != lRet)
{
goto Exit;
}
RegCloseKey(hKey);
hKey = NULL;
//Com Dll
lRet = RegCreateKeyEx(HKEY_CLASSES_ROOT, c_wszCLSID, 0, NULL, 0, 0, NULL, &hKey, &dwDisposition);
if(ERROR_SUCCESS != lRet)
{
goto Exit;
}
lRet = RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)c_wszDll, sizeof(c_wszDll));
if(ERROR_SUCCESS != lRet)
{
goto Exit;
}
RegCloseKey(hKey);
hKey = NULL;
hr = S_OK;
Exit:
if(hKey)
{
RegCloseKey(hKey);
}
return hr;
}
//********************************************************************************************
// DllUnregisterServer
//
// Purpose:
// This function instructs an in-process server to create its registry entries for
// all classes supported in this server module. If this function fails, the state of
// the registry for all its classes is indeterminate.
//
// Returns:
// HRESULT indicating success
//********************************************************************************************
STDAPI DllUnregisterServer()
{
WCHAR wszSubKey[MAX_PATH];
LONG lRet;
//IContexMenu
lRet = RegDeleteKey(HKEY_LOCAL_MACHINE, c_wszRegKey);
ASSERT(ERROR_SUCCESS == lRet);
//Com Dll
lRet = RegDeleteKey(HKEY_CLASSES_ROOT, c_wszCLSID);
ASSERT(ERROR_SUCCESS == lRet);
//RAS connectoid created, if any
StringCchPrintf( wszSubKey, ARRAYSIZE(wszSubKey), TEXT("comm\\rasbook\\%s"), c_wszSERDMAReplEntryName);
lRet = RegDeleteKey(HKEY_CURRENT_USER, wszSubKey);
return S_OK;
}
//********************************************************************************************
// FindRNAAppWindow
//
// Purpose:
// This function is an application-defined callback function that receives top-level
// window handles as a result of a call to the EnumWindows function.
//
// Returns:
// TRUE continues enumeration. FALSE stops enumeration.
//********************************************************************************************
BOOL FindRNAAppWindow(HWND hWnd, LPARAM lParam)
{
TCHAR szClassName[32];
GetClassName(hWnd, szClassName, sizeof(szClassName)/sizeof(TCHAR));
//We are looking for a window with a classname that isn't dialog
//and has the window's user data set to RNAAPP_MAGIC_NUM
if ( !_tcscmp (szClassName, c_wszDialog ) &&
(RNAAPP_MAGIC_NUM == GetWindowLong(hWnd, DWL_USER)) )
{
*((HWND *)lParam) = hWnd;
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -