src/native/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.cxx
/**
 * Starts the COM server.
 *
 * @param S_OK if the server started correctly. E_FAIL otherwise.
 */
Starts the COM server.
@param S_OK if the server started correctly.
Starts the COM server . @param S_OK if the server started correctly .
HRESULT MsOutlookAddrBookContactSourceService_startComServer(void)
{
    int bitness = MAPIBitness_getOutlookBitnessVersion();
    if(bitness != -1)
    {
        char applicationName32[] = "jmsoutlookaddrbookcomserver32.exe";
        char applicationName64[] = "jmsoutlookaddrbookcomserver64.exe";
        char * applicationName = applicationName32;
        if(bitness == 64)
        {
            applicationName = applicationName64;
        }
        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;
        char* loggerPath = MsOutlookUtils_getLoggerPath();
        int loggerPathLenght = 0;
        char* comServerWithLogger;
        char* appNameWithLogger;
        char* loggerPathEscaped = NULL;
        if(loggerPath != NULL)
        {
        	int loggerLevel = MsOutlookUtils_getLoggerLevel();
        	char* loggerPathEscaped = (char* ) malloc(strlen(loggerPath) *
        			sizeof(char) * 2);
        	int i = 0;
        	while(*loggerPath != '\0')
        	{
        		*(loggerPathEscaped + i) = *loggerPath;
        		i++;
        		if(*loggerPath == '\\')
        		{
        			*(loggerPathEscaped + i) = '\\';
					i++;
        		}
        		loggerPath++;
        	}
        	*(loggerPathEscaped + i) = '\0';
        	loggerPathLenght = strlen(loggerPathEscaped);
			comServerWithLogger
				= (char*) malloc(
						(FILENAME_MAX + loggerPathLenght) * sizeof(char));
			appNameWithLogger
				= (char*) malloc(
						(FILENAME_MAX + loggerPathLenght) * sizeof(char));
        	sprintf(comServerWithLogger, "%s \"%s\" %d", comServer,
        			loggerPathEscaped, loggerLevel);
        	sprintf(appNameWithLogger, "%s \"%s\" %d", applicationName
        			, loggerPathEscaped, loggerLevel);
        }
        else
        {
        	comServerWithLogger = comServer;
        	appNameWithLogger = applicationName;
        }
        char * serverExec[2];
        serverExec[0] = comServerWithLogger;
        serverExec[1] = appNameWithLogger;
        for(int i = 0; i < 2; ++i)
        {
            if(CreateProcess(
                        NULL,
                        serverExec[i],
                        NULL, NULL, false, 0, NULL, NULL,
                        &startupInfo,
                        &processInfo))
            {
                MsOutlookAddrBookContactSourceService_comServerHandle
                    = processInfo.hProcess;
                MsOutlookUtils_logInfo(serverExec[i]);
                MsOutlookUtils_logInfo("COM Server started successful.[1]");
                if(loggerPath != NULL)
				{
                	free(comServerWithLogger);
                	free(appNameWithLogger);
				}
                MsOutlookUtils_logInfo("COM Server started successful.[2]");
                return S_OK;
            }
        }
        if(loggerPath != NULL)
		{
			free(comServerWithLogger);
			free(appNameWithLogger);
			free(loggerPathEscaped);
		}
    }
    return E_FAIL;
}
HRESULT MsOutlookAddrBookContactSourceService_startComServer ( void ) { int bitness = MAPIBitness_getOutlookBitnessVersion ( ) ; if ( bitness != -1 ) { char applicationName32 [ ] = " " ; char applicationName64 [ ] = " " ; char * applicationName = applicationName32 ; if ( bitness == 64 ) { applicationName = applicationName64 ; } int applicationNameLength = strlen ( applicationName ) ; char currentDirectory [ FILENAME_MAX - applicationNameLength - 8 ] ; GetCurrentDirectory ( FILENAME_MAX - applicationNameLength - 8 , currentDirectory ) ; char comServer [ FILENAME_MAX ] ; sprintf ( comServer , " " , 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 ; char * loggerPath = MsOutlookUtils_getLoggerPath ( ) ; int loggerPathLenght = 0 ; char * comServerWithLogger ; char * appNameWithLogger ; char * loggerPathEscaped = NULL ; if ( loggerPath != NULL ) { int loggerLevel = MsOutlookUtils_getLoggerLevel ( ) ; char * loggerPathEscaped = ( char * ) malloc ( strlen ( loggerPath ) * sizeof ( char ) * 2 ) ; int i = 0 ; while ( * loggerPath != ' \0 ' ) { * ( loggerPathEscaped + i ) = * loggerPath ; i ++ ; if ( * loggerPath == ' \\ ' ) { * ( loggerPathEscaped + i ) = ' \\ ' ; i ++ ; } loggerPath ++ ; } * ( loggerPathEscaped + i ) = ' \0 ' ; loggerPathLenght = strlen ( loggerPathEscaped ) ; comServerWithLogger = ( char * ) malloc ( ( FILENAME_MAX + loggerPathLenght ) * sizeof ( char ) ) ; appNameWithLogger = ( char * ) malloc ( ( FILENAME_MAX + loggerPathLenght ) * sizeof ( char ) ) ; sprintf ( comServerWithLogger , " \" \" " , comServer , loggerPathEscaped , loggerLevel ) ; sprintf ( appNameWithLogger , " \" \" " , applicationName , loggerPathEscaped , loggerLevel ) ; } else { comServerWithLogger = comServer ; appNameWithLogger = applicationName ; } char * serverExec [ 2 ] ; serverExec [ 0 ] = comServerWithLogger ; serverExec [ 1 ] = appNameWithLogger ; for ( int i = 0 ; i < 2 ; ++ i ) { if ( CreateProcess ( NULL , serverExec [ i ] , NULL , NULL , false , 0 , NULL , NULL , & startupInfo , & processInfo ) ) { MsOutlookAddrBookContactSourceService_comServerHandle = processInfo . hProcess ; MsOutlookUtils_logInfo ( serverExec [ i ] ) ; MsOutlookUtils_logInfo ( " " ) ; if ( loggerPath != NULL ) { free ( comServerWithLogger ) ; free ( appNameWithLogger ) ; } MsOutlookUtils_logInfo ( " " ) ; return S_OK ; } } if ( loggerPath != NULL ) { free ( comServerWithLogger ) ; free ( appNameWithLogger ) ; free ( loggerPathEscaped ) ; } } return E_FAIL ; }
Starts the COM server.
Starts the COM server .
// Start COM service // Test 2 files: 0 for the build version, 1 for the git source version. // Create the COM server