This is a VC++ source code example, this example does call ps2pdf.exe in a multiple threads and convert more PS files to PDF files concurrently,
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
DWORD WINAPI PS2PDF_Thread(LPVOID lpParameter)
{
int threadNum = (int)lpParameter;
printf("Thread %d started\n", threadNum);
PROCESS_INFORMATION pi = {0};
char commandLine[4096] = {0};
char threadNumStr[16] = {0};
STARTUPINFO StartupInfo = {0};
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = SW_HIDE;
_itoa(threadNum, threadNumStr, 10);
strcpy(commandLine, "ps2pdf.exe -debug");
strcat(commandLine, " \"pdftest");
strcat(commandLine, threadNumStr);
strcat(commandLine, ".ps\"");
printf("Thread %d process starting %S\n", threadNum, commandLine);
BOOL cpSuccess = CreateProcess(NULL, commandLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &StartupInfo, &pi);
if (cpSuccess == FALSE)
{
printf("Thread %d process failed to start\n", threadNum);
}
printf("Thread %d process started\n", threadNum);
DWORD waitResult = WaitForSingleObject(pi.hProcess, INFINITE);
printf("Thread %d process finished\n", threadNum);
if (waitResult != WAIT_OBJECT_0)
{
printf("Thread %d process wait = %d\n", threadNum, waitResult);
}
if (pi.hProcess != NULL)
{
CloseHandle (pi.hProcess);
pi.hProcess = NULL;
}
if (pi.hThread != NULL)
{
CloseHandle (pi.hThread);
pi.hThread = NULL;
}
printf("Thread %d finished\n", threadNum);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
int numThreads = 10;
HANDLE* hThread = NULL;
printf("Running %d threads\n", numThreads);
for (int i = 0; i < numThreads; i++)
{
wchar_t pdfFileName[32] = {0};
wchar_t threadNumStr[16] = {0};
_itow(0, threadNumStr, 10);
wcscpy(pdfFileName, L"pdftest");
wcscat(pdfFileName, threadNumStr);
wcscat(pdfFileName, L".pdf");
DeleteFileW(pdfFileName);
}
hThread = new HANDLE[numThreads];
for (i = 0; i < numThreads; i++)
{
hThread[i] = ::CreateThread(NULL, 0, PS2PDF_Thread, (LPVOID)i, CREATE_SUSPENDED, NULL);
}
for (int j = 0; j < numThreads; j++)
{
ResumeThread(hThread[j]);
}
WaitForMultipleObjects(numThreads, hThread, TRUE, INFINITE);
if (hThread != NULL)
{
delete []hThread;
hThread = NULL;
}
printf("Press [Enter] to exit.\n");
getchar();
return 0;
}