@ -15,18 +15,18 @@
# include <string.h>
static LPMAPIALLOCATEBUFFER
MsOutlookAddrBookContactSourceService_ MAPI AllocateBuffer;
static LPMAPIFREEBUFFER MsOutlookAddrBookContactSourceService_ MAPI FreeBuffer;
static LPMAPIINITIALIZE MsOutlookAddrBookContactSourceService_ MAPI Initialize;
static LPMAPILOGONEX MsOutlookAddrBookContactSourceService_ MAPI LogonEx;
MsOutlookAddrBookContactSourceService_ mapi AllocateBuffer;
static LPMAPIFREEBUFFER MsOutlookAddrBookContactSourceService_ mapi FreeBuffer;
static LPMAPIINITIALIZE MsOutlookAddrBookContactSourceService_ mapi Initialize;
static LPMAPILOGONEX MsOutlookAddrBookContactSourceService_ mapi LogonEx;
static LPMAPIUNINITIALIZE
MsOutlookAddrBookContactSourceService_ MAPI Uninitialize;
MsOutlookAddrBookContactSourceService_ mapi Uninitialize;
JNIEXPORT void JNICALL
Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIInitialize
( JNIEnv * jniEnv , jclass clazz , jlong version , jlong flags )
{
HKEY office Key;
HKEY reg Key;
HRESULT hResult = MAPI_E_NO_SUPPORT ;
/*
@ -42,7 +42,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
_T ( " Software \\ Microsoft \\ Office " ) ,
0 ,
KEY_ENUMERATE_SUB_KEYS ,
& office Key) )
& reg Key) )
{
DWORD i = 0 ;
TCHAR installRootKeyName [
@ -61,7 +61,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
regEnumKeyEx
= RegEnumKeyEx (
office Key,
reg Key,
i ,
installRootKeyName , & subkeyNameLength ,
NULL ,
@ -79,7 +79,7 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
* ( str + 20 ) = 0 ;
if ( ERROR_SUCCESS
= = RegOpenKeyEx (
office Key,
reg Key,
installRootKeyName ,
0 ,
KEY_QUERY_VALUE ,
@ -147,7 +147,114 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
RegCloseKey ( installRootKey ) ;
}
}
RegCloseKey ( officeKey ) ;
RegCloseKey ( regKey ) ;
/*
* Make sure that Microsoft Outlook is the default mail client in order
* to prevent its dialog in the case of it not being the default mail
* client .
*/
if ( HR_SUCCEEDED ( hResult ) )
{
DWORD defaultValueType ;
/*
* The buffer installRootKeyName is long enough to receive
* " Microsoft Outlook " so use it in order to not have to allocate
* more memory .
*/
LPTSTR defaultValue = ( LPTSTR ) installRootKeyName ;
DWORD defaultValueCapacity = sizeof ( installRootKeyName ) ;
jboolean checkHKeyLocalMachine ;
hResult = MAPI_E_NO_SUPPORT ;
if ( ERROR_SUCCESS
= = RegOpenKeyEx (
HKEY_CURRENT_USER ,
_T ( " Software \\ Clients \\ Mail " ) ,
0 ,
KEY_QUERY_VALUE ,
& regKey ) )
{
DWORD defaultValueSize = defaultValueCapacity ;
LONG regQueryValueEx
= RegQueryValueEx (
regKey ,
NULL ,
NULL ,
& defaultValueType ,
( LPBYTE ) defaultValue , & defaultValueSize ) ;
switch ( regQueryValueEx )
{
case ERROR_SUCCESS :
{
if ( REG_SZ = = defaultValueType )
{
DWORD defaultValueLength
= defaultValueSize / sizeof ( TCHAR ) ;
if ( ( 0 = = defaultValueLength ) | | ( 0 = = defaultValue [ 0 ] ) )
checkHKeyLocalMachine = JNI_TRUE ;
else
{
checkHKeyLocalMachine = JNI_FALSE ;
if ( _tcsnicmp (
_T ( " Microsoft Outlook " ) , defaultValue ,
defaultValueLength )
= = 0 )
hResult = S_OK ;
}
}
else
checkHKeyLocalMachine = JNI_FALSE ;
break ;
}
case ERROR_FILE_NOT_FOUND :
checkHKeyLocalMachine = JNI_TRUE ;
break ;
case ERROR_MORE_DATA :
checkHKeyLocalMachine = JNI_FALSE ;
break ;
default :
checkHKeyLocalMachine = JNI_FALSE ;
break ;
}
RegCloseKey ( regKey ) ;
}
else
checkHKeyLocalMachine = JNI_TRUE ;
if ( ( JNI_TRUE = = checkHKeyLocalMachine )
& & ( ERROR_SUCCESS
= = RegOpenKeyEx (
HKEY_LOCAL_MACHINE ,
_T ( " Software \\ Clients \\ Mail " ) ,
0 ,
KEY_QUERY_VALUE ,
& regKey ) ) )
{
DWORD defaultValueSize = defaultValueCapacity ;
LONG regQueryValueEx
= RegQueryValueEx (
regKey ,
NULL ,
NULL ,
& defaultValueType ,
( LPBYTE ) defaultValue , & defaultValueSize ) ;
if ( ( ERROR_SUCCESS = = regQueryValueEx )
& & ( REG_SZ = = defaultValueType ) )
{
DWORD defaultValueLength = defaultValueSize / sizeof ( TCHAR ) ;
if ( _tcsnicmp (
_T ( " Microsoft Outlook " ) , defaultValue ,
defaultValueLength )
= = 0 )
hResult = S_OK ;
}
RegCloseKey ( regKey ) ;
}
}
}
/* If we've determined that we'd like to go on with MAPI, try to load it. */
@ -155,42 +262,40 @@ Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContac
{
HMODULE lib = LoadLibrary ( _T ( " mapi32.dll " ) ) ;
hResult = MAPI_E_NO_SUPPORT ;
if ( lib )
{
MsOutlookAddrBookContactSourceService_ MAPI Initialize
MsOutlookAddrBookContactSourceService_ mapi Initialize
= ( LPMAPIINITIALIZE ) GetProcAddress ( lib , " MAPIInitialize " ) ;
MsOutlookAddrBookContactSourceService_ MAPI Uninitialize
MsOutlookAddrBookContactSourceService_ mapi Uninitialize
= ( LPMAPIUNINITIALIZE ) GetProcAddress ( lib , " MAPIUninitialize " ) ;
if ( MsOutlookAddrBookContactSourceService_ MAPI Initialize
& & MsOutlookAddrBookContactSourceService_ MAPI Uninitialize)
if ( MsOutlookAddrBookContactSourceService_ mapi Initialize
& & MsOutlookAddrBookContactSourceService_ mapi Uninitialize)
{
MAPIINIT_0 mapiInit = { ( ULONG ) version , ( ULONG ) flags } ;
hResult
= MsOutlookAddrBookContactSourceService_ MAPI Initialize(
= MsOutlookAddrBookContactSourceService_ mapi Initialize(
& mapiInit ) ;
if ( HR_SUCCEEDED ( hResult ) )
{
MsOutlookAddrBookContactSourceService_ MAPI AllocateBuffer
MsOutlookAddrBookContactSourceService_ mapi AllocateBuffer
= ( LPMAPIALLOCATEBUFFER )
GetProcAddress ( lib , " MAPIAllocateBuffer " ) ;
MsOutlookAddrBookContactSourceService_ MAPI FreeBuffer
MsOutlookAddrBookContactSourceService_ mapi FreeBuffer
= ( LPMAPIFREEBUFFER )
GetProcAddress ( lib , " MAPIFreeBuffer " ) ;
MsOutlookAddrBookContactSourceService_ MAPI LogonEx
MsOutlookAddrBookContactSourceService_ mapi LogonEx
= ( LPMAPILOGONEX ) GetProcAddress ( lib , " MAPILogonEx " ) ;
if ( ! MsOutlookAddrBookContactSourceService_MAPIAllocateBuffer
| | ! MsOutlookAddrBookContactSourceService_MAPIFreeBuffer
| | ! MsOutlookAddrBookContactSourceService_MAPILogonEx )
{
MsOutlookAddrBookContactSourceService_MAPIUninitialize ( ) ;
hResult = MAPI_E_NOT_FOUND ;
}
if ( MsOutlookAddrBookContactSourceService_mapiAllocateBuffer
& & MsOutlookAddrBookContactSourceService_mapiFreeBuffer
& & MsOutlookAddrBookContactSourceService_mapiLogonEx )
hResult = S_OK ;
else
MsOutlookAddrBookContactSourceService_mapiUninitialize ( ) ;
}
}
else
hResult = MAPI_E_NOT_FOUND ;
if ( HR_FAILED ( hResult ) )
FreeLibrary ( lib ) ;
}
@ -210,31 +315,31 @@ JNIEXPORT void JNICALL
Java_net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService_MAPIUninitialize
( JNIEnv * jniEnv , jclass clazz )
{
MsOutlookAddrBookContactSourceService_ MAPI Uninitialize( ) ;
MsOutlookAddrBookContactSourceService_ mapi Uninitialize( ) ;
}
SCODE
MsOutlookAddrBook_ MAPI AllocateBuffer( ULONG size , LPVOID FAR * buffer )
MsOutlookAddrBook_ mapi AllocateBuffer( ULONG size , LPVOID FAR * buffer )
{
return
MsOutlookAddrBookContactSourceService_ MAPI AllocateBuffer( size , buffer ) ;
MsOutlookAddrBookContactSourceService_ mapi AllocateBuffer( size , buffer ) ;
}
ULONG
MsOutlookAddrBook_ MAPI FreeBuffer( LPVOID buffer )
MsOutlookAddrBook_ mapi FreeBuffer( LPVOID buffer )
{
return MsOutlookAddrBookContactSourceService_ MAPI FreeBuffer( buffer ) ;
return MsOutlookAddrBookContactSourceService_ mapi FreeBuffer( buffer ) ;
}
HRESULT
MsOutlookAddrBook_ MAPI LogonEx
MsOutlookAddrBook_ mapi LogonEx
( ULONG_PTR uiParam ,
LPSTR profileName , LPSTR password ,
FLAGS flags ,
LPMAPISESSION FAR * mapiSession )
{
return
MsOutlookAddrBookContactSourceService_ MAPI LogonEx(
MsOutlookAddrBookContactSourceService_ mapi LogonEx(
uiParam ,
profileName , password ,
flags ,