Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Gilt für: Outlook 2013 | Outlook 2016
Um ein Offlinezustands-Add-In zu implementieren, müssen Sie Verbindungs-, Initialisierungs- und andere Setupfunktionen implementieren. In diesem Thema werden diese Verbindungs-, Initialisierungs- und Setupfunktionen anhand von Codebeispielen aus dem Beispiel-Offlinezustands-Add-In veranschaulicht. Das Offlinestatus-Add-In-Beispiel ist ein COM-Add-In, das ein Offlinestatus-Menü zu Outlook hinzufügt und die Offlinestatus-API verwendet. Über das Menü Offlinezustand können Sie die Zustandsüberwachung aktivieren oder deaktivieren, den aktuellen Zustand überprüfen und den aktuellen Zustand ändern. Weitere Informationen zum Herunterladen und Installieren des Offlinestatus-Add-In-Beispiels finden Sie unter Installieren des Offlinestatus-Add-In-Beispiels. Weitere Informationen zur Offlinestatus-API finden Sie unter Informationen zur Offlinestatus-API.
Nachdem Sie ein Offlinezustands-Add-In eingerichtet haben, müssen Sie Funktionen zum Überwachen und Ändern von Verbindungsstatusänderungen implementieren. Weitere Informationen finden Sie unter Überwachen von Verbindungsstatusänderungen mithilfe eines Offlinestatus-Add-Ins.
Bei Verbindungsroutine
Die IDTExtensibility2.OnConnection-Methode wird jedes Mal aufgerufen, wenn ein Add-In geladen wird. Es ist der Einstiegspunkt für das Add-In, sodass der Code, den Sie in die OnConnection Funktion einfügen, beim Start des Add-Ins aufgerufen wird. Im folgenden Beispiel ruft die OnConnection Funktion die HrInitAddin -Funktion auf.
CMyAddin::OnConnection()-Beispiel
STDMETHODIMP CMyAddin::OnConnection(
IDispatch * Application,
ext_ConnectMode ConnectMode,
IDispatch * /*AddInInst*/,
SAFEARRAY * * /*custom*/)
{
Log(true,"OnConnection\n");
HRESULT hRes = S_OK;
m_spApp = Application;
m_ConnectMode = ConnectMode;
if (ConnectMode == ext_cm_AfterStartup)
hRes = HrInitAddin();
return hRes;
}
Initialisieren der Add-In-Routine
Die HrInitAddin Funktion ruft die LoadLibrariesFunktionen , HrCacheProfileNameund HrAddMenuItems auf, um die Einrichtung des Offlinezustands-Add-Ins abzuschließen.
CMyAddin::HrInitAddin()-Beispiel
HRESULT CMyAddin::HrInitAddin()
{
HRESULT hRes = S_OK;
LoadLibraries();
hRes = HrCacheProfileName();
Log(true,_T("HrCacheProfileName returned 0x%08X\n"),hRes);
hRes = HrAddMenuItems();
Log(true,_T("HrAddMenuItems returned 0x%08X\n"),hRes);
return hRes;
}
Routine zum Laden von Bibliotheken
Die LoadLibraries Funktion lädt die DLL-Dateien (Dynamic Link Library), die das Add-In benötigt.
LoadLibraries()-Beispiel
void LoadLibraries()
{
Log(true,_T("LoadLibraries - loading exports from DLLs\n"));
HRESULT hRes = S_OK;
UINT uiRet = 0;
LONG lRet = 0;
BOOL bRet = true;
CHAR szSystemDir[MAX_PATH+1] = {0};
// Get the system directory path
// (mapistub.dll and mapi32.dll reside here)
uiRet = GetSystemDirectoryA(szSystemDir, MAX_PATH);
if (uiRet > 0)
{
CHAR szDLLPath[MAX_PATH+1] = {0};
hRes = StringCchPrintfA(szDLLPath, MAX_PATH+1, "%s\\%s",
szSystemDir, "mapistub.dll");
if (SUCCEEDED(hRes))
{
LPFGETCOMPONENTPATH pfnFGetComponentPath = NULL;
// Load mapistub.dll
hModMAPIStub = LoadLibraryA(szDLLPath);
if (hModMAPIStub)
{
// Get the address of FGetComponentPath from the mapistub
pfnFGetComponentPath = (LPFGETCOMPONENTPATH)GetProcAddress(
hModMAPIStub, "FGetComponentPath");
}
// If there is no address for FGetComponentPath yet
// try getting it from mapi32.dll
if (!pfnFGetComponentPath)
{
hRes = StringCchPrintfA(szDLLPath, MAX_PATH+1, "%s\\%s",
szSystemDir, "mapi32.dll");
if (SUCCEEDED(hRes))
{
// Load mapi32.dll
hModMAPI = LoadLibraryA(szDLLPath);
if (hModMAPI)
{
// Get the address of FGetComponentPath from mapi32
pfnFGetComponentPath = (LPFGETCOMPONENTPATH)GetProcAddress(
hModMAPI, "FGetComponentPath");
}
}
}
if (pfnFGetComponentPath)
{
LPSTR szAppLCID = NULL;
LPSTR szOfficeLCID = NULL;
HKEY hMicrosoftOutlook = NULL;
lRet = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
_T("Software\\Clients\\Mail\\Microsoft Outlook"),
NULL,
KEY_READ,
&hMicrosoftOutlook);
if (ERROR_SUCCESS == lRet && hMicrosoftOutlook)
{
HrGetRegMultiSZValueA(hMicrosoftOutlook, "MSIApplicationLCID", (LPVOID*) &szAppLCID);
HrGetRegMultiSZValueA(hMicrosoftOutlook, "MSIOfficeLCID", (LPVOID*) &szOfficeLCID);
}
if (szAppLCID)
{
bRet = pfnFGetComponentPath(
"{FF1D0740-D227-11D1-A4B0-006008AF820E}", szAppLCID, szDLLPath, MAX_PATH, true);
}
if ((!bRet || szDLLPath[0] == _T('\0')) && szOfficeLCID)
{
bRet = pfnFGetComponentPath(
"{FF1D0740-D227-11D1-A4B0-006008AF820E}", szOfficeLCID, szDLLPath, MAX_PATH, true);
}
if (!bRet || szDLLPath[0] == _T('\0'))
{
bRet = pfnFGetComponentPath(
"{FF1D0740-D227-11D1-A4B0-006008AF820E}", NULL, szDLLPath, MAX_PATH, true);
}
delete[] szOfficeLCID;
delete[] szAppLCID;
if (hMicrosoftOutlook) RegCloseKey(hMicrosoftOutlook);
}
hModMSMAPI = LoadLibrary(szDLLPath);
if (hModMSMAPI)
{
pfnHrOpenOfflineObj = (HROPENOFFLINEOBJ*) GetProcAddress(
hModMSMAPI,
"HrOpenOfflineObj@20");
pfnMAPIFreeBuffer = (LPMAPIFREEBUFFER) GetProcAddress(
hModMSMAPI,
"MAPIFreeBuffer");
}
}
}
}
Routine für Cacheprofilnamen
Die HrCacheProfileName Funktion ruft die FUNKTION IMAPISupport::OpenProfileSection auf, um einen Profilabschnitt für die aktuelle Sitzung zu öffnen, und legt dann das Profil für die Schaltflächenhandler fest.
CMyAddin::HrCacheProfileName()-Beispiel
HRESULT CMyAddin::HrCacheProfileName()
{
HRESULT hRes = S_OK;
_NameSpacePtr spSession = m_spApp->GetNamespace("MAPI");
IUnknown* lpMAPIObject = NULL;
LPMAPISESSION lpMAPISession = NULL;
// use the raw accessor
hRes = spSession->get_MAPIOBJECT(&lpMAPIObject);
if (SUCCEEDED(hRes) && lpMAPIObject)
{
hRes = lpMAPIObject->QueryInterface(IID_IMAPISession,(LPVOID*)&lpMAPISession);
}
if (SUCCEEDED(hRes) && lpMAPISession)
{
LPPROFSECT lpPSGlobal = NULL;
hRes = lpMAPISession->OpenProfileSection((LPMAPIUID)pbGlobalProfileSectionGuid, NULL, 0, &lpPSGlobal);
if (SUCCEEDED(hRes) && lpPSGlobal)
{
LPSPropValue lpProfileName = NULL;
// Asking for PR_PROFILE_NAME_W here - this might not work with earlier versions of Outlook
SPropTagArray staga = {1,PR_PROFILE_NAME_W};
ULONG cVal = 0;
hRes = lpPSGlobal->GetProps(&staga,0,&cVal,&lpProfileName);
if (SUCCEEDED(hRes) && 1 == cVal && lpProfileName && PR_PROFILE_NAME_W == lpProfileName->ulPropTag)
{
m_InitButtonHandler.SetProfile(lpProfileName->Value.lpszW);
m_GetStateButtonHandler.SetProfile(lpProfileName->Value.lpszW);
m_SetStateButtonHandler.SetProfile(lpProfileName->Value.lpszW);
}
if (pfnMAPIFreeBuffer) pfnMAPIFreeBuffer(lpProfileName);
}
if (lpPSGlobal) lpPSGlobal->Release();
}
if (lpMAPISession) lpMAPISession->Release();
return hRes;
}
Routine zum Hinzufügen von Menüelementen
Die HrAddMenuItems Funktion definiert die Menüoptionen, die im Menü Offlinezustand angezeigt werden, das beim Laden des Add-Ins in Outlook erstellt wird, und ruft DispEventAdvise dann für jedes Menüelement auf.
CMyAddin::HrAddMenuItems()-Beispiel
HRESULT CMyAddin::HrAddMenuItems()
{
Log(true,"HrAddMenuItems\n");
HRESULT hRes = S_OK;
if (!m_fMenuItemsAdded)
{
try
{
_ExplorerPtr spExplorer = m_spApp->ActiveExplorer();
_CommandBarsPtr spCmdBars = spExplorer->__CommandBars;
CommandBarPtr spMainBar = spCmdBars->ActiveMenuBar;
CommandBarControlsPtr spMainCtrls = spMainBar->Controls;
try { m_spMyMenu = spMainCtrls->GetItem("Offline State"); } catch (_com_error) {}
if (m_spMyMenu == NULL)
{
m_spMyMenu = spMainCtrls->Add((long)msoControlPopup,vtMissing,vtMissing,vtMissing, true);
m_spMyMenu->Caption = "Offline State";
}
CommandBarControlsPtr spMyMenuCtrls = m_spMyMenu->Controls;
try { m_spInitButton = spMyMenuCtrls->GetItem("&Init Monitor"); } catch (_com_error) {}
if (m_spInitButton == NULL)
{
m_spInitButton = spMyMenuCtrls->Add((long)msoControlButton, vtMissing, vtMissing, vtMissing, true);
m_spInitButton->Caption = "&Init Monitor";
m_spInitButton->FaceId = MY_INIT_BUTTON;
}
try { m_spDeinitButton = spMyMenuCtrls->GetItem("&Deinit Monitor"); } catch (_com_error) {}
if (m_spDeinitButton == NULL)
{
m_spDeinitButton = spMyMenuCtrls->Add((long)msoControlButton, vtMissing, vtMissing, vtMissing, true);
m_spDeinitButton->Caption = "&Deinit Monitor";
m_spDeinitButton->FaceId = MY_DEINIT_BUTTON;
}
try { m_spGetStateButton = spMyMenuCtrls->GetItem("&GetCurrentState"); } catch (_com_error) {}
if (m_spGetStateButton == NULL)
{
m_spGetStateButton = spMyMenuCtrls->Add((long)msoControlButton, vtMissing, vtMissing, vtMissing, true);
m_spGetStateButton->Caption = "&GetCurrentState";
m_spGetStateButton->FaceId = MY_GETSTATE_BUTTON;
}
try { m_spSetStateButton = spMyMenuCtrls->GetItem("&SetCurrentState"); } catch (_com_error) {}
if (m_spSetStateButton == NULL)
{
m_spSetStateButton = spMyMenuCtrls->Add((long)msoControlButton, vtMissing, vtMissing, vtMissing, true);
m_spSetStateButton->Caption = "&SetCurrentState";
m_spSetStateButton->FaceId = MY_SETSTATE_BUTTON;
}
// Set up advise
_com_util::CheckError(m_InitButtonHandler.DispEventAdvise(m_spInitButton));
_com_util::CheckError(m_DeinitButtonHandler.DispEventAdvise(m_spDeinitButton));
_com_util::CheckError(m_GetStateButtonHandler.DispEventAdvise(m_spGetStateButton));
_com_util::CheckError(m_SetStateButtonHandler.DispEventAdvise(m_spSetStateButton));
}
catch (_com_error)
{
hRes = E_FAIL;
}
if (SUCCEEDED(hRes))
{
m_fMenuItemsAdded = true;
}
}
return hRes;
}