From dcc0a8d477c65282b458e5ceef316e91c699a409 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Mon, 10 Jan 2011 23:25:24 +0000 Subject: Delays the linking to the Microsoft Outlook API from compile to run time as much as possible in order to fix a crash on Windows XP without Microsoft Outlook (privately) reported by Damian Minkov. --- src/native/addrbook/msoutlook/Makefile | 2 +- src/native/addrbook/msoutlook/MsOutlookMAPI.h | 12 +++ ...tlook_MsOutlookAddrBookContactSourceService.cxx | 100 ++++++++++++++++++--- 3 files changed, 102 insertions(+), 12 deletions(-) (limited to 'src/native/addrbook/msoutlook') diff --git a/src/native/addrbook/msoutlook/Makefile b/src/native/addrbook/msoutlook/Makefile index 2f5362d..a971bbe 100644 --- a/src/native/addrbook/msoutlook/Makefile +++ b/src/native/addrbook/msoutlook/Makefile @@ -11,7 +11,7 @@ endif CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32 -I$(OUTLOOK_MAPI_HEADERS) -I.. LDFLAGS = -shared -Wl,--kill-at -LIBS = -lmapi32 -luuid -ladvapi32 +LIBS = -luuid -ladvapi32 TARGET = ../../../../lib/native/windows$(ARCH)/$(TARGET_BASENAME).dll $(TARGET): \ diff --git a/src/native/addrbook/msoutlook/MsOutlookMAPI.h b/src/native/addrbook/msoutlook/MsOutlookMAPI.h index 1fcba92..6dcc0b0 100644 --- a/src/native/addrbook/msoutlook/MsOutlookMAPI.h +++ b/src/native/addrbook/msoutlook/MsOutlookMAPI.h @@ -18,4 +18,16 @@ #define WIN32_LEAN_AND_MEAN #include + +SCODE MsOutlookAddrBook_MAPIAllocateBuffer(ULONG size, LPVOID FAR *buffer); +#define MAPIAllocateBuffer MsOutlookAddrBook_MAPIAllocateBuffer +ULONG MsOutlookAddrBook_MAPIFreeBuffer(LPVOID buffer); +#define MAPIFreeBuffer MsOutlookAddrBook_MAPIFreeBuffer +HRESULT MsOutlookAddrBook_MAPILogonEx + (ULONG_PTR uiParam, + LPSTR profileName, LPSTR password, + FLAGS flags, + LPMAPISESSION FAR *mapiSession); +#define MAPILogonEx MsOutlookAddrBook_MAPILogonEx + #endif /* #ifndef _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_MSOUTLOOKMAPI_H_ */ diff --git a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx index 14446b0..3db6812 100644 --- a/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx +++ b/src/native/addrbook/msoutlook/net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.cxx @@ -14,6 +14,14 @@ #include #include +static LPMAPIALLOCATEBUFFER + MsOutlookAddrBookContactSourceService_MAPIAllocateBuffer; +static LPMAPIFREEBUFFER MsOutlookAddrBookContactSourceService_MAPIFreeBuffer; +static LPMAPIINITIALIZE MsOutlookAddrBookContactSourceService_MAPIInitialize; +static LPMAPILOGONEX MsOutlookAddrBookContactSourceService_MAPILogonEx; +static LPMAPIUNINITIALIZE + MsOutlookAddrBookContactSourceService_MAPIUninitialize; + JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIInitialize (JNIEnv *jniEnv, jclass clazz, jlong version, jlong flags) @@ -31,7 +39,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac if (ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE, - _TEXT("Software\\Microsoft\\Office"), + _T("Software\\Microsoft\\Office"), 0, KEY_ENUMERATE_SUB_KEYS, &officeKey)) @@ -67,7 +75,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac continue; str = installRootKeyName + subkeyNameLength; - memcpy(str, _TEXT("\\Outlook\\InstallRoot"), 20 * sizeof(TCHAR)); + memcpy(str, _T("\\Outlook\\InstallRoot"), 20 * sizeof(TCHAR)); *(str + 20) = 0; if ((ERROR_SUCCESS == RegOpenKeyEx( @@ -79,7 +87,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac && (ERROR_SUCCESS == RegQueryValueEx( installRootKey, - _TEXT("Path"), + _T("Path"), NULL, &pathValueType, NULL, &pathValueSize)) @@ -109,7 +117,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac if (ERROR_SUCCESS == RegQueryValueEx( installRootKey, - _TEXT("Path"), + _T("Path"), NULL, NULL, (LPBYTE) pathValue, &pathValueSize)) @@ -128,12 +136,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac fileAttributes = GetFileAttributes(pathValue); if (INVALID_FILE_ATTRIBUTES != fileAttributes) - { - MAPIINIT_0 mapiInit - = { (ULONG) version, (ULONG) flags }; - - hResult = MAPIInitialize(&mapiInit); - } + hResult = S_OK; } } @@ -143,6 +146,53 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac } } + /* If we've determined that we'd like to go on with MAPI, try to load it. */ + if (HR_SUCCEEDED(hResult)) + { + HMODULE lib = LoadLibrary(_T("mapi32.dll")); + + if (lib) + { + MsOutlookAddrBookContactSourceService_MAPIInitialize + = (LPMAPIINITIALIZE) GetProcAddress(lib, "MAPIInitialize"); + MsOutlookAddrBookContactSourceService_MAPIUninitialize + = (LPMAPIUNINITIALIZE) GetProcAddress(lib, "MAPIUninitialize"); + + if (MsOutlookAddrBookContactSourceService_MAPIInitialize + && MsOutlookAddrBookContactSourceService_MAPIUninitialize) + { + MAPIINIT_0 mapiInit = { (ULONG) version, (ULONG) flags }; + + hResult + = MsOutlookAddrBookContactSourceService_MAPIInitialize( + &mapiInit); + if (HR_SUCCEEDED(hResult)) + { + MsOutlookAddrBookContactSourceService_MAPIAllocateBuffer + = (LPMAPIALLOCATEBUFFER) + GetProcAddress(lib, "MAPIAllocateBuffer"); + MsOutlookAddrBookContactSourceService_MAPIFreeBuffer + = (LPMAPIFREEBUFFER) + GetProcAddress(lib, "MAPIFreeBuffer"); + MsOutlookAddrBookContactSourceService_MAPILogonEx + = (LPMAPILOGONEX) GetProcAddress(lib, "MAPILogonEx"); + if (!MsOutlookAddrBookContactSourceService_MAPIAllocateBuffer + || !MsOutlookAddrBookContactSourceService_MAPIFreeBuffer + || !MsOutlookAddrBookContactSourceService_MAPILogonEx) + { + MsOutlookAddrBookContactSourceService_MAPIUninitialize(); + hResult = MAPI_E_NOT_FOUND; + } + } + } + else + hResult = MAPI_E_NOT_FOUND; + if (HR_FAILED(hResult)) + FreeLibrary(lib); + } + } + + /* Report any possible error regardless of where it has come from. */ if (HR_FAILED(hResult)) { MsOutlookMAPIHResultException_throwNew( @@ -156,5 +206,33 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIUninitialize (JNIEnv *jniEnv, jclass clazz) { - MAPIUninitialize(); + MsOutlookAddrBookContactSourceService_MAPIUninitialize(); +} + +SCODE +MsOutlookAddrBook_MAPIAllocateBuffer(ULONG size, LPVOID FAR *buffer) +{ + return + MsOutlookAddrBookContactSourceService_MAPIAllocateBuffer(size, buffer); +} + +ULONG +MsOutlookAddrBook_MAPIFreeBuffer(LPVOID buffer) +{ + return MsOutlookAddrBookContactSourceService_MAPIFreeBuffer(buffer); +} + +HRESULT +MsOutlookAddrBook_MAPILogonEx + (ULONG_PTR uiParam, + LPSTR profileName, LPSTR password, + FLAGS flags, + LPMAPISESSION FAR *mapiSession) +{ + return + MsOutlookAddrBookContactSourceService_MAPILogonEx( + uiParam, + profileName, password, + flags, + mapiSession); } -- cgit v1.1