#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);
}
}
}