diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-01-10 23:25:24 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-01-10 23:25:24 +0000 |
commit | dcc0a8d477c65282b458e5ceef316e91c699a409 (patch) | |
tree | 90cf89d3216265cff34f67464726ba2620ae0aab /src/native/addrbook/msoutlook | |
parent | 9d464588742490137cd67b82e35a89d4592df8c0 (diff) | |
download | jitsi-dcc0a8d477c65282b458e5ceef316e91c699a409.zip jitsi-dcc0a8d477c65282b458e5ceef316e91c699a409.tar.gz jitsi-dcc0a8d477c65282b458e5ceef316e91c699a409.tar.bz2 |
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.
Diffstat (limited to 'src/native/addrbook/msoutlook')
3 files changed, 102 insertions, 12 deletions
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 <windows.h>
+
+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 <stdlib.h>
#include <string.h>
+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);
}
|