diff options
author | Vincent Lucas <lucas@Vincents-MacBook-Pro.local> | 2013-05-07 10:53:43 +0200 |
---|---|---|
committer | Vincent Lucas <lucas@Vincents-MacBook-Pro.local> | 2013-05-07 10:53:43 +0200 |
commit | bd11acf2b29a04dd59f287249748ac369c5caf7e (patch) | |
tree | c9dfd4126e825295d27d08aecf27368b5437f247 /src/native/addrbook/msoutlook/com/ComClient.cxx | |
parent | 30d591762bd8c52cb2154ff74035b5aef857780b (diff) | |
download | jitsi-bd11acf2b29a04dd59f287249748ac369c5caf7e.zip jitsi-bd11acf2b29a04dd59f287249748ac369c5caf7e.tar.gz jitsi-bd11acf2b29a04dd59f287249748ac369c5caf7e.tar.bz2 |
Creates a COM service to able Jitsi 32 bits to communicate with MAPI 64 bits (Outlook). And vice-versa.
Diffstat (limited to 'src/native/addrbook/msoutlook/com/ComClient.cxx')
-rw-r--r-- | src/native/addrbook/msoutlook/com/ComClient.cxx | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/native/addrbook/msoutlook/com/ComClient.cxx b/src/native/addrbook/msoutlook/com/ComClient.cxx new file mode 100644 index 0000000..b13dcf3 --- /dev/null +++ b/src/native/addrbook/msoutlook/com/ComClient.cxx @@ -0,0 +1,112 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +#include "ComClient.h" + +#include "../MAPIBitness.h" +#include "MsOutlookAddrBookServerClassFactory.h" +#include "MsOutlookAddrBookClientClassFactory.h" +#include "TypeLib.h" + +#include <process.h> +#include <stdio.h> + +/** + * Starts and stops registration for the COM client. + * + * @author Vincent Lucas + */ + +/** + * A pointer to the COM server interface to make remote MAPI requests. + */ +static IMsOutlookAddrBookServer * ComClient_iServer = NULL; + +/** + * The class factory of the COM client activated when the client type library is + * registered. + */ +static ClassFactory * ComClient_classFactory = NULL; + +/** + * The client type library. + */ +static LPTYPELIB ComClient_typeLib = NULL; + +/** + * Initializes the COM client. + */ +void ComClient_start(void) +{ + HRESULT hr = E_FAIL; + + if(CoInitializeEx(NULL, COINIT_MULTITHREADED) == S_OK) + { + // The server may be long to start, then retry 10 times with 1s pause + // between each try. + int retry = 10; + while(retry > 0) + { + if((hr = CoCreateInstance( + CLSID_MsOutlookAddrBookServer, + NULL, + CLSCTX_LOCAL_SERVER, + IID_IMsOutlookAddrBookServer, + (void**) &ComClient_iServer)) == S_OK) + { + WCHAR * path = (WCHAR*) L"IMsOutlookAddrBookClient.tlb"; + ComClient_typeLib = TypeLib_loadRegTypeLib(path); + + ClassFactory *ComClient_classFactory + = new MsOutlookAddrBookClientClassFactory(); + if(ComClient_classFactory->registerClassObject() != S_OK) + { + ComClient_classFactory->Release(); + ComClient_classFactory = NULL; + } + ::CoResumeClassObjects(); + + retry = 0; + } + Sleep(1000); + --retry; + } + } +} + + +/** + * Uninitializes the COM client. + */ +void ComClient_stop(void) +{ + if(ComClient_iServer) + { + ComClient_iServer->Release(); + ComClient_iServer = NULL; + } + + ::CoSuspendClassObjects(); + + if(ComClient_classFactory) + { + ComClient_classFactory->Release(); + ComClient_classFactory = NULL; + } + if(ComClient_typeLib) + { + TypeLib_releaseTypeLib(ComClient_typeLib); + ComClient_typeLib = NULL; + } +} + +/** + * A pointer to the COM server interface to make remote MAPI requests. + */ +IMsOutlookAddrBookServer * ComClient_getIServer() +{ + return ComClient_iServer; +} |