How to call doc2any.exe from C++ source code

#include "stdAfx.h"

#pragma hdrstop

#pragma warning(disable:4311)

#pragma warning(disable:4312)

void SilentSpawnVeryPDFAndWait( const CString fileNameIn , const CString fileNameOut) // launch excel to PDF converter

{

    LONG rc;

 

    HKEY keyToPdf;

    DWORD valueType;

    DWORD sizeOfFile = 256;

    char targetDirectory[256];

    char finalDirectory[256];

    char fileToOpen[256];

 

    sprintf(fileToOpen, " -wtext \"Page %%PageNumber%% of %%PageCount%%\" -wpagebegin 2 -wpageend 500 -wpageoffset -1 \"%s\"  \"%s\" ",

              fileNameIn, fileNameOut);

 

       // set up the exe location

       sprintf(finalDirectory, "%s", "C:\\_VeryPdfDoc2AnyCLTool\\doc2any_cmd\\doc2any.exe");

 

       CWnd *wnd = (CWnd *)AfxGetMainWnd();

 

    STARTUPINFO si;

    PROCESS_INFORMATION pi;

 

    // initialize structures

    ZeroMemory(&si, sizeof(STARTUPINFO));

    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));

    si.cb = sizeof(STARTUPINFO);

    si.dwFlags = STARTF_USESHOWWINDOW;

       si.wShowWindow = SW_HIDE;

 

    //CreateProcess...

    SetCursorWait();

    CreateProcess(finalDirectory, fileToOpen, NULL, NULL, false, 0, NULL, NULL, &si, &pi);

 

    //CreateProcess( NULL, commandLine, NULL, NULL, false,    0, NULL, NULL, &si, &pi );

    //CreateProcess( commandLine,NULL, NULL, NULL, false,     0, NULL, NULL, &si, &pi );

    //WaitForInputIdle(GetCurrentProcess(), INFINITE);

 

    // loop until process terminates

    HWND hWnd = GetActiveWindow();

 

    if( pi.hProcess )

        {

        DWORD dwExitCode = STILL_ACTIVE;

 

        while( dwExitCode == STILL_ACTIVE )

            {

            WaitForSingleObject(pi.hProcess, 1000);

            GetExitCodeProcess(pi.hProcess, &dwExitCode);

            }

        }

}

 

 

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!