From 6035f9236c20f92c959593d424d3e26c77cc0af4 Mon Sep 17 00:00:00 2001 From: Vincent Lucas Date: Tue, 7 May 2013 16:17:07 +0200 Subject: Modifies path tried to load the external executable COM server and the type libraries: test several paths in order to work for as well for the build as for the git source version. --- .../MsOutlookAddrBookContactSourceService.cxx | 79 ++++++++++++++-------- src/native/addrbook/msoutlook/com/TypeLib.cxx | 33 +++++---- 2 files changed, 70 insertions(+), 42 deletions(-) (limited to 'src/native/addrbook/msoutlook') diff --git a/src/native/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.cxx b/src/native/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.cxx index aacbeff..09b1b84 100644 --- a/src/native/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.cxx +++ b/src/native/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.cxx @@ -38,6 +38,7 @@ static HMODULE MsOutlookAddrBookContactSourceService_hMapiLib = NULL; static jboolean MsOutlookAddrBookContactSourceService_isValidDefaultMailClient (LPCTSTR name, DWORD nameLength); +HRESULT MsOutlookAddrBookContactSourceService_startComServer(void); HRESULT MsOutlookAddrBookContactSourceService_MAPIInitialize (jlong version, jlong flags) @@ -451,35 +452,7 @@ HRESULT MsOutlookAddrBookContactSourceService_MAPIInitializeCOMServer() MAPISession_lock(); // Start COM service - char applicationName[] = "native/jmsoutlookaddrbookcomserver.exe"; - int applicationNameLength = strlen(applicationName); - char currentDirectory[FILENAME_MAX - applicationNameLength]; - GetCurrentDirectory( - FILENAME_MAX - applicationNameLength, - currentDirectory); - char comServer[FILENAME_MAX]; - sprintf(comServer, "%s/%s", currentDirectory, applicationName); - - STARTUPINFO startupInfo; - PROCESS_INFORMATION processInfo; - memset(&startupInfo, 0, sizeof(startupInfo)); - memset(&processInfo, 0, sizeof(processInfo)); - startupInfo.dwFlags = STARTF_USESHOWWINDOW; - startupInfo.wShowWindow = SW_HIDE; - - // Create the COM server - if(CreateProcess( - NULL, - comServer, - NULL, NULL, false, 0, NULL, NULL, - &startupInfo, - &processInfo)) - { - MsOutlookAddrBookContactSourceService_comServerHandle - = processInfo.hProcess; - hr = S_OK; - } - + hr = MsOutlookAddrBookContactSourceService_startComServer(); // Start COM client ComClient_start(); @@ -607,6 +580,54 @@ MsOutlookAddrBookContactSourceService_isValidDefaultMailClient return validDefaultMailClient; } +/** + * Starts the COM server. + * + * @param S_OK if the server started correctly. E_FAIL otherwise. + */ +HRESULT MsOutlookAddrBookContactSourceService_startComServer(void) +{ + // Start COM service + char applicationName[] = "jmsoutlookaddrbookcomserver.exe"; + int applicationNameLength = strlen(applicationName); + char currentDirectory[FILENAME_MAX - applicationNameLength - 8]; + GetCurrentDirectory( + FILENAME_MAX - applicationNameLength - 8, + currentDirectory); + char comServer[FILENAME_MAX]; + sprintf(comServer, "%s/native/%s", currentDirectory, applicationName); + + STARTUPINFO startupInfo; + PROCESS_INFORMATION processInfo; + memset(&startupInfo, 0, sizeof(startupInfo)); + memset(&processInfo, 0, sizeof(processInfo)); + startupInfo.dwFlags = STARTF_USESHOWWINDOW; + startupInfo.wShowWindow = SW_HIDE; + + // Test 2 files: 0 for the build version, 1 for the git source version. + char * serverExec[2]; + serverExec[0] = comServer; + serverExec[1] = applicationName; + for(int i = 0; i < 2; ++i) + { + // Create the COM server + if(CreateProcess( + NULL, + serverExec[i], + NULL, NULL, false, 0, NULL, NULL, + &startupInfo, + &processInfo)) + { + MsOutlookAddrBookContactSourceService_comServerHandle + = processInfo.hProcess; + + return S_OK; + } + } + + return E_FAIL; +} + BOOL MsOutlookAddrBook_fBinFromHex(LPSTR lpsz, LPBYTE lpb) { return MsOutlookAddrBookContactSourceService_fBinFromHex(lpsz, lpb); diff --git a/src/native/addrbook/msoutlook/com/TypeLib.cxx b/src/native/addrbook/msoutlook/com/TypeLib.cxx index cb1a10f..60e445e 100644 --- a/src/native/addrbook/msoutlook/com/TypeLib.cxx +++ b/src/native/addrbook/msoutlook/com/TypeLib.cxx @@ -38,29 +38,36 @@ LPTYPELIB TypeLib_loadRegTypeLib(WCHAR* path) free(applicationName); LPWSTR libPathW = StringUtils::MultiByteToWideChar(libPath); - if(SUCCEEDED(::LoadTypeLibEx(libPathW, REGKIND_NONE, &iTypeLib))) + // Test 2 files: 0 for the build version, 1 for the git source version. + LPWSTR libPathList[2]; + libPathList[0] = libPathW; + libPathList[1] = path; + for(int i = 0; i < 2 && iTypeLib == NULL; ++i) { - HMODULE oleaut32 = ::GetModuleHandle(_T("oleaut32.dll")); - - if (oleaut32) + if(SUCCEEDED(::LoadTypeLibEx(libPathList[i], REGKIND_NONE, &iTypeLib))) { - typedef HRESULT (WINAPI *RTLFU)(LPTYPELIB,LPOLESTR,LPOLESTR); - RTLFU registerTypeLibForUser - = (RTLFU) ::GetProcAddress(oleaut32, "RegisterTypeLibForUser"); + HMODULE oleaut32 = ::GetModuleHandle(_T("oleaut32.dll")); - if (registerTypeLibForUser) + if (oleaut32) { - registerTypeLibForUser(iTypeLib, libPathW, NULL); + typedef HRESULT (WINAPI *RTLFU)(LPTYPELIB,LPOLESTR,LPOLESTR); + RTLFU registerTypeLibForUser = (RTLFU) + ::GetProcAddress(oleaut32, "RegisterTypeLibForUser"); + + if (registerTypeLibForUser) + { + registerTypeLibForUser(iTypeLib, libPathList[i], NULL); + } + else + { + iTypeLib = NULL; + } } else { iTypeLib = NULL; } } - else - { - iTypeLib = NULL; - } } free(libPathW); -- cgit v1.1