Ejemplo n.º 1
0
extern "C" int PASCAL EXPORT Convert( const char* strFile_In , const char* strFile_Out )
{
	AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
	int bRet = 0;

	TCHAR strFile_In_T[MAX_PATH] = { _T( "" ) };
	TCHAR strFile_Out_T[MAX_PATH] = { _T( "" ) };

	UTF8_TO_WIDE( strFile_In_T , strFile_In );
	UTF8_TO_WIDE( strFile_Out_T , strFile_Out );

	CoInitialize( NULL );
	PPT_Application pApp;
	COleException cErr;
	TCHAR strErr[256] = { _T( "" ) };
	cErr.GetErrorMessage( strErr , 256 );


	vector<int> vPIDs;
	GetPptPID( vPIDs , PROCESS_FACT::INIT );
	int nRet = pApp.CreateDispatch( _T( "Powerpoint.Application" ) , &cErr );
	if( nRet > 0 )
	{
		int nPID = GetPptPID( vPIDs , PROCESS_FACT::FIND );
		pApp.put_Visible( 1 );
		PPT_Presentations pPresentations = pApp.get_Presentations( );
		COleVariant vTrue( ( short ) TRUE ) , vFalse( ( short ) FALSE ) , vOptional( ( long ) DISP_E_PARAMNOTFOUND , VT_ERROR ) , vZ( ( short ) 0 ) ;

		try
		{
			//Open Workbook
			CString strBookPath( strFile_In_T );
			strBookPath.Replace( _T( "//" ) , _T( "\\" ) );
			PPT_Presentation pPresentation = pPresentations.Open( strBookPath , 0 , 0 , 0 );
			if( pPresentation.m_lpDispatch )
			{
				try
				{
					//Convert
					CString strPdfPath( strFile_Out_T );
					strPdfPath.Replace( _T( "//" ) , _T( "\\" ) );
					pPresentation.ExportAsFixedFormat( strPdfPath , ppFixedFormatTypePDF , 0 , 0 , ppPrintHandoutHorizontalFirst
						, ppPrintOutputSlides , 0 , NULL , ppPrintAll , NULL , false , false , true , true , false , vOptional );
					bRet = TASK_STATE::TASK_STATE_SUC;
					pPresentation.Close( );
				}
				catch( ... )
				{
					bRet = TASK_STATE::TASK_STATE_FILE_CONVERT_FAIL;
					pPresentation.Close( );
				}
				pPresentation.ReleaseDispatch( );
			}
		}
		catch( ... )
		{
			bRet = TASK_STATE::TASK_STATE_FILE_OPEN_FAIL;
		}
		pPresentations.ReleaseDispatch( );
		pApp.Quit( );
		pApp.ReleaseDispatch( );
		GetPptPID( vPIDs , PROCESS_FACT::TERMINATE , nPID );
		Sleep( 1000 );
	}
	CoUninitialize( );

	return bRet;
}
Ejemplo n.º 2
0
/** Constructor for Roper driver; most parameters are simply passed to ADDriver::ADDriver.
  * After calling the base class constructor this method creates a thread to collect the detector data, 
  * and sets reasonable default values for the parameters defined in this class, asynNDArrayDriver and
  * ADDriver.
  * \param[in] portName The name of the asyn port driver to be created.
  * \param[in] maxBuffers The maximum number of NDArray buffers that the NDArrayPool for this driver is 
  *            allowed to allocate. Set this to -1 to allow an unlimited number of buffers.
  * \param[in] maxMemory The maximum amount of memory that the NDArrayPool for this driver is 
  *            allowed to allocate. Set this to -1 to allow an unlimited amount of memory.
  * \param[in] priority The thread priority for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags.
  * \param[in] stackSize The stack size for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags.
  */
roper::roper(const char *portName,
             int maxBuffers, size_t maxMemory,
             int priority, int stackSize)

    : ADDriver(portName, 1, NUM_ROPER_PARAMS, maxBuffers, maxMemory, 
               0, 0,             /* No interfaces beyond those set in ADDriver.cpp */
               ASYN_CANBLOCK, 1, /* ASYN_CANBLOCK=1, ASYN_MULTIDEVICE=0, autoConnect=1 */
               priority, stackSize)

{
    int status = asynSuccess;
    const char *functionName = "roper";
    VARIANT varResult;
    HRESULT hr;
    COleException COleExcept;
    short result;
    const char *controllerName;
    int controllerNum;
    IDispatch *pDocFileDispatch;

    createParam(RoperShutterModeString,            asynParamInt32,   &RoperShutterMode);
    createParam(RoperNumAcquisitionsString,        asynParamInt32,   &RoperNumAcquisitions);
    createParam(RoperNumAcquisitionsCounterString, asynParamInt32,   &RoperNumAcquisitionsCounter);
    createParam(RoperAutoDataTypeString,           asynParamInt32,   &RoperAutoDataType);
    createParam(RoperComment1String,               asynParamOctet,   &RoperComment1);
    createParam(RoperComment2String,               asynParamOctet,   &RoperComment2);
    createParam(RoperComment3String,               asynParamOctet,   &RoperComment3);
    createParam(RoperComment4String,               asynParamOctet,   &RoperComment4);
    createParam(RoperComment5String,               asynParamOctet,   &RoperComment5);
 
    /* Initialize the COM system for this thread */
    hr = INITIALIZE_COM;
    if (hr != S_OK) {
        printf("%s:%s: error initializing COM\n",
            driverName, functionName);
    }

    /* Create the COleDispatchDriver objects used to communicate with COM */
    VariantInit(&varResult);
    this->pWinx32App = new(CWinx32App20);
    this->pExpSetup  = new(CExpSetup20);
    this->pDocFile   = new(CDocFile40);
    this->pROIRect   = new(CROIRect0);

    /* Connect to the WinX32App and ExpSetup COM objects */
    if (!pWinx32App->CreateDispatch("WinX32.Winx32App.2", &COleExcept)) {
        COleExcept.GetErrorMessage(this->errorMessage, sizeof(this->errorMessage));
        printf("%s:%s: error creating WinX32App COM object = %s\n",
            driverName, functionName, this->errorMessage);
        return;
    }
    if (!pExpSetup->CreateDispatch("WinX32.ExpSetup.2", &COleExcept)) {
        COleExcept.GetErrorMessage(this->errorMessage, sizeof(this->errorMessage));
        printf("%s:%s: error creating ExpSetup COM object = %s\n",
            driverName, functionName, this->errorMessage);
        return;
    }
    if (!pROIRect->CreateDispatch("WinX32.ROIRect", &COleExcept)) {
        COleExcept.GetErrorMessage(this->errorMessage, sizeof(this->errorMessage));
        printf("%s:%s: error creating ROIRect COM object = %s\n",
            driverName, functionName, this->errorMessage);
        return;
    }

    try {
        varResult = this->pExpSetup->GetParam(EXP_CONTROLLER_NAME, &result);
        controllerNum = varResult.lVal;
        if (controllerNum < 0) controllerNum = 0;
        if (controllerNum >= numControllerNames) controllerNum = 0;
        controllerName = controllerNames[controllerNum];
        varResult = pExpSetup->GetParam(EXP_XDIMDET, &result);
        setIntegerParam(ADMaxSizeX, varResult.lVal);
        varResult = pExpSetup->GetParam(EXP_YDIMDET, &result);
        setIntegerParam(ADMaxSizeY, varResult.lVal);
        pDocFileDispatch = pExpSetup->GetDocument();
        if (pDocFileDispatch) {
            pDocFile->AttachDispatch(pDocFileDispatch);
            getData();
        } else {
            setIntegerParam(NDArraySizeX, 0);
            setIntegerParam(NDArraySizeY, 0);
            setIntegerParam(NDArraySize, 0);
            setIntegerParam(NDDataType, NDUInt16);
        }
    }
    catch(CException *pEx) {
        pEx->GetErrorMessage(this->errorMessage, sizeof(this->errorMessage));
        printf("%s:%s: exception = %s\n", 
            driverName, functionName, this->errorMessage);
        pEx->Delete();
        return;
    }

    /* Read the state of the detector */
    status = this->getStatus();
    if (status) {
        printf("%s:%s: unable to read detector status\n", driverName, functionName);
        return;
    }

   /* Create the epicsEvents for signaling to the acquisition task when acquisition starts and stops */
    this->startEventId = epicsEventCreate(epicsEventEmpty);
    if (!this->startEventId) {
        printf("%s:%s: epicsEventCreate failure for start event\n", 
            driverName, functionName);
        return;
    }
    this->stopEventId = epicsEventCreate(epicsEventEmpty);
    if (!this->stopEventId) {
        printf("%s:%s: epicsEventCreate failure for stop event\n", 
            driverName, functionName);
        return;
    }
    
    /* Set some default values for parameters */
    status =  setStringParam (ADManufacturer, "Roper Scientific");
    status |= setStringParam (ADModel, controllerName);
    status |= setIntegerParam(ADImageMode, ADImageSingle);
    status |= setDoubleParam (ADAcquireTime, .1);
    status |= setDoubleParam (ADAcquirePeriod, .5);
    status |= setIntegerParam(ADNumImages, 1);
    status |= setIntegerParam(RoperNumAcquisitions, 1);
    status |= setIntegerParam(RoperNumAcquisitionsCounter, 0);
    status |= setIntegerParam(RoperAutoDataType, 1);
    if (status) {
        printf("%s:%s: unable to set camera parameters\n", driverName, functionName);
        return;
    }
    
    /* Create the thread that updates the images */
    status = (epicsThreadCreate("roperTask",
                                epicsThreadPriorityMedium,
                                epicsThreadGetStackSize(epicsThreadStackMedium),
                                (EPICSTHREADFUNC)roperTaskC,
                                this) == NULL);
    if (status) {
        printf("%s:%s: epicsThreadCreate failure for Roper task\n", 
            driverName, functionName);
        return;
    }
}