pdf to vector converter

testing pdf2vec_sdk.zip on windows 2008 64bit

Thanks for your message, if you wish use "AnyCpu" mode, you have to use "pdf2vector_com.exe" COM interface, because pdf2vec.dll is a Win32 DLL Library, we have to provide two DLL file to support both 32bit and 64bit, e.g.,

Pdf2vec32.dll   //for x86 platform
Pdf2vec64.dll   //for x64 platform

If you use Pdf2vec.dll, you need compile your project with x86 mode, if you use Pdf2vec64.dll, you need compule your project with x64 mode, you can't compile your project at "AnyCpu" mode, because Pdf2vec32.dll can't be run at x64 platform and Pdf2vec64.dll can't be run at x86 platform, you have to separate them on x86 and x64 platforms, please notice this matter.

DLL is linked into EXE process, so we can't use a DLL in both 32bit and 64bit application, this is a limitation of Windows!!!

So, there has another solution for you, it is "pdf2vector_com.exe" COM interface, "pdf2vector_com.exe" is based on Pdf2vec.dll (or Pdf2vec32.dll), "pdf2vector_com.exe" can be called from your project with "AnyCpu" mode, this is the ONLY solution to use "AnyCpu" mode. -  not a solution cause I explain to you your  current COM interface is not exposing an interface to PDF2VectorFromMemory()

Also, we can't provide a Pdf2vec64.dll at Sunday, the port work (re-compile all source code on 64bit platform) can't be done in a short time, please understand.

VeryPDF
==============================
I think you didn't understand me, although I keep explaining you in last 4-5 emails, again and again the same request.

So I will try my best, doing it for last time?

a. offcourse "AnyCPU" means that on 64bit project, it will compile to 64bit model. I don't really care about 32bit at all,
cause I'm using windows 2008 r264bit, so I don’t expect it will work for both platforms, that's ok, I just care for x64 (which is "AnyCPU" default mode),

b. I was asking your from my first email to make a new version -64 bit of the Pdf2vec.dll, I never ask you to wrap me a 64COM object. This was your idea, cause maybe you thought you can do it fast enough, and you didn't understand I want  to use PDF2VectorFromMemory?

c. the reason I asked for 64bit version of pdf2vec,like explained in my first email was  - because I want to use the PDF2VectorFromMemory() function and iterate page by page for conversation, because a lack of your "burst2" mode to do a perfect conversion on some files, like I demonstrate you in my first email.

d. using a new build of 64bit version of pdf2vec.dll (not 32bit!!!) + interop call of PDF2VectorFromMemory() function + iterate page by page, I can hopefully simulate a "burst" functionality, but also, can control it much better by monitoring input/output for each entire single page! And offcourse avoiding the exception crash prompt.

I hope this time, after 5-6 email I repeat myself  you understand me ?
Let me know if you are going to build a 64bit dll version soon, or not, cause my development team is just waiting for your response If you plan to do it on later date,

please let me know your deadline, so I can prepare my team! Thanks!
==============================
Thanks for your detailed explanation, we understand your meaning now, however, we can’t provide a 64bit version of pdf2vec.dll to you at the moment, because our source code can’t be compiled to 64bit DLL Library, we are planning release a 64bit pdf2vec.dll in the future, but we haven’t an approximate date for when will it be released at the moment, please understand.

VeryPDF
==============================
Ok thanks
Please contact me as soon as your release 64bit.
==============================
Thanks for your message, we will let you know after pdf2vec64.dll library is ready, thanks for your patience.

VeryPDF
==============================
How are you?
I hope everything is cool with you ?

Long time didn’t speak, I waited with log of patience ?
Did you finally build a 64bit version for pdf2vec.dll library (pdf2vec64.dll)?

If so I would like very much to test it before purchase.
==============================
Thanks for your message, we have a 64bit COM interface (pdf2vector_com.exe) for pdf2vec.dll library, but we haven't a native pdf2vec64.dll DLL Library, please understand.  pdf2vector_com.exe is a COM interface to pdf2vec.dll library, you can call pdf2vector_com.exe from both 32bit and 64bit EXE application, we hoping this Com interface will useful to you.

Also, we will release a pdf2vec64.dll pure 64bit DLL Library in the future, we will let you know as soon as it available.

VeryPDF

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

pdf2vec.exe crash on Windows Server 2003 R2 x64

Greetings,

I may have an application that require converting single and / or batches of pdf files to wmf images.  Basic specs are as follows.

Retain file name
Retain image size and resolution
Convert all files in a folder or by file name
Operate from the command line
No dialog or interface when running from the command line

Is this standard functionality or would customization be required?
====================================
Our PDF to Vector Converter product has this function, please download PDF to Vector Converter from following web page to try,

http://www.verydoc.com/pdf-to-vector.html

you can run following command line to convert your PDF file to WMF file,

pdf2vec.exe C:\test.pdf C:\out.wmf

you can also run following command line to batch convert all of your PDF files in D:\test folder and sub-folders to WMF files at one time,

for /r D:\test %F in (*.pdf) do "C:\pdf2vec.exe" "%F" "%~dpnF.wmf"

above command line can retain the filename during conversion.

VeryPDF
====================================
Greetings,

We have been working with your demo download and have established that it can be the solution for our image conversion project.  We are running into the obstacle that this program will not run from our server in the command line.   We are using Windows Server 2003 R2 x64.  We get the error failed to initialize application.

PDF to SWF Crash on Windows 2003 system
PDF to WMF Crash on Windows 2003 system

Any help or insight would be appreciated.
====================================
Please turn off DEP for "pdf2vec.exe" application to try again, please refer to following steps about how to turn off DEP in your system,

1. Click "Start"
2. Select "Control Panel"
3. Select "System"
4. Click the "Advanced" tab
5. In the "Performance" region select "Settings"
6. Click the "Data Execute" tab in the dialog box that opens
7. Select "Turn on DEP for all programs and services except for those I select"
8. Click "Add"
9. The open dialog box will open. Browse and select "pdf2vec.exe" application in your computer,
10. Click "Open"
11. Click "Apply"
12. Click "Ok"
13. Reboot

OK, you can run "pdf2vec.exe" without any problem now, please to try.

VeryPDF

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

Editing scanned PDF files in PDF Editor software

I downloaded VERYPDF for trial and tried to edit some content of PDF file but it failed to edit. When I tried to select particular word or amount in PDF document, it doesn't select.

PDF file was created by scanning a printed document.

Please advise.
=====================
Sorry, PDF Editor product is can only edit the normal text based PDF file, it can't edit scanned PDF document. If you wish edit scanned PDF files, you ca use our PDF to Image Converter or PDF Extract TIFF software to convert your PDF files to image files first, then you can edit the image files in Adobe Photoshop or other image editor applications.

VeryPDF
=====================
Also, you can use following solution to edit the scanned PDF file in PDF Editor application, please refer to following steps,

1. please run PDF Editor and open your PDF file first,
2. Please select "Edit Content"->"Draw Rectangle" buttons from toolbar,
3. Please draw a rectangle with white background overlay on original text content,
4. Please add a new text content on this rectangle,
5. Please save this modified PDF file,
6. Then it's fine.

VeryPDF

VN:F [1.9.20_1166]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
xps to pdf converter

Font issue during XPS to PDF Conversion

Dear Sir/Madam,

We are a software development company based in London, England. We have seen your XPS to PDF Converter (Product name: XPS to PDF Converter Command Line) from your website and now evaluating this tool, we have a little problems when converting file from XPS to PDF.

I have attached the source XPS file and the PDF output file.
Basically the title of the document couldn't be converted properly to PDF, and the space between some letters are narrower in some occasions.
eg.
The Title Execution Quality Report on the top of the document:
PDF is converted to "Execution" where the original in XPS is "Execution", also the letters Q and u for "Quality" were very close to each other

Can you please help with this before we decide to buy the product?

Many thanks
==========================
Thanks for your message, our engineers are working on the new version of XPS to PDF Converter product now, the new version will improve the font quality a lot during XPS to PDF conversion, we will let you know after new version is ready, thanks for your patience.

VeryPDF
==========================
Thank you very much for your quick response.

We think the font is not important to us, but we do need our current project to be finished as quickly as possible, so we would like to try some existing Windows Fonts instead of waiting a custom-build version, can you please suggest any Windows Fonts can might solve this problem?
==========================
Thank you for your help. We have found some other fonts and solved this problem with font 'Arial'. It now works perfect for us. We will contact you if we meet any more problems.
======================
Thank you for your message, if we can be of any other assistance, please feel free to let us know.

Thank you and have a nice day!

VeryPDF

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: -1 (from 1 vote)
verypdf blog

Call PCL to PDF Converter by CreateProcess() function

I like your program very much, but I don't see an option to run it in the background without being on the taskbar (that's the big space in the bottom of the screen). Is there any way to do that?

Thanks,
========================
Thanks for your message, can you please let us know what product are you using?

VeryPDF
========================
VeryPDF PCL Converter v2.0
Thanks,
========================
You can use CreateProcess() function to run PCL to PDF Converter EXE application, and use CreatePipe() to hide the DOS window, please refer to following web page for more information,

http://support.microsoft.com/kb/190351

Sample code
/*++

Copyright (c) 1998  Microsoft Corporation

Module Name:

Redirect.c

Description:
This sample illustrates how to spawn a child console based
application with redirected standard handles.

The following import libraries are required:
user32.lib

Dave McPherson (davemm)   11-March-98

--*/

#include<windows.h>
#pragma comment(lib, "User32.lib")
void DisplayError(char *pszAPI);
void ReadAndHandleOutput(HANDLE hPipeRead);
void PrepAndLaunchRedirectedChild(HANDLE hChildStdOut,
HANDLE hChildStdIn,
HANDLE hChildStdErr);
DWORD WINAPI GetAndSendInputThread(LPVOID lpvThreadParam);

HANDLE hChildProcess = NULL;
HANDLE hStdIn = NULL; // Handle to parents std input.
BOOL bRunThread = TRUE;

void main ()
{
HANDLE hOutputReadTmp,hOutputRead,hOutputWrite;
HANDLE hInputWriteTmp,hInputRead,hInputWrite;
HANDLE hErrorWrite;
HANDLE hThread;
DWORD ThreadId;
SECURITY_ATTRIBUTES sa;

// Set up the security attributes struct.
sa.nLength= sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;

// Create the child output pipe.
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0))
DisplayError("CreatePipe");

// Create a duplicate of the output write handle for the std error
// write handle. This is necessary in case the child application
// closes one of its std output handles.
if (!DuplicateHandle(GetCurrentProcess(),hOutputWrite,
GetCurrentProcess(),&hErrorWrite,0,
TRUE,DUPLICATE_SAME_ACCESS))
DisplayError("DuplicateHandle");

// Create the child input pipe.
if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0))
DisplayError("CreatePipe");

// Create new output read handle and the input write handles. Set
// the Properties to FALSE. Otherwise, the child inherits the
// properties and, as a result, non-closeable handles to the pipes
// are created.
if (!DuplicateHandle(GetCurrentProcess(),hOutputReadTmp,
GetCurrentProcess(),
&hOutputRead, // Address of new handle.
0,FALSE, // Make it uninheritable.
DUPLICATE_SAME_ACCESS))
DisplayError("DupliateHandle");

if (!DuplicateHandle(GetCurrentProcess(),hInputWriteTmp,
GetCurrentProcess(),
&hInputWrite, // Address of new handle.
0,FALSE, // Make it uninheritable.
DUPLICATE_SAME_ACCESS))
DisplayError("DupliateHandle");

// Close inheritable copies of the handles you do not want to be
// inherited.
if (!CloseHandle(hOutputReadTmp)) DisplayError("CloseHandle");
if (!CloseHandle(hInputWriteTmp)) DisplayError("CloseHandle");

// Get std input handle so you can close it and force the ReadFile to
// fail when you want the input thread to exit.
if ( (hStdIn = GetStdHandle(STD_INPUT_HANDLE)) ==
INVALID_HANDLE_VALUE )
DisplayError("GetStdHandle");

PrepAndLaunchRedirectedChild(hOutputWrite,hInputRead,hErrorWrite);

// Close pipe handles (do not continue to modify the parent).
// You need to make sure that no handles to the write end of the
// output pipe are maintained in this process or else the pipe will
// not close when the child process exits and the ReadFile will hang.
if (!CloseHandle(hOutputWrite)) DisplayError("CloseHandle");
if (!CloseHandle(hInputRead )) DisplayError("CloseHandle");
if (!CloseHandle(hErrorWrite)) DisplayError("CloseHandle");

// Launch the thread that gets the input and sends it to the child.
hThread = CreateThread(NULL,0,GetAndSendInputThread,
(LPVOID)hInputWrite,0,&ThreadId);
if (hThread == NULL) DisplayError("CreateThread");

// Read the child's output.
ReadAndHandleOutput(hOutputRead);
// Redirection is complete

// Force the read on the input to return by closing the stdin handle.
if (!CloseHandle(hStdIn)) DisplayError("CloseHandle");

// Tell the thread to exit and wait for thread to die.
bRunThread = FALSE;

if (WaitForSingleObject(hThread,INFINITE) == WAIT_FAILED)
DisplayError("WaitForSingleObject");

if (!CloseHandle(hOutputRead)) DisplayError("CloseHandle");
if (!CloseHandle(hInputWrite)) DisplayError("CloseHandle");
}

///////////////////////////////////////////////////////////////////////
// PrepAndLaunchRedirectedChild
// Sets up STARTUPINFO structure, and launches redirected child.
///////////////////////////////////////////////////////////////////////
void PrepAndLaunchRedirectedChild(HANDLE hChildStdOut,
HANDLE hChildStdIn,
HANDLE hChildStdErr)
{
PROCESS_INFORMATION pi;
STARTUPINFO si;

// Set up the start up info struct.
ZeroMemory(&si,sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput = hChildStdOut;
si.hStdInput  = hChildStdIn;
si.hStdError  = hChildStdErr;
// Use this if you want to hide the child:
//     si.wShowWindow = SW_HIDE;
// Note that dwFlags must include STARTF_USESHOWWINDOW if you want to
// use the wShowWindow flags.

// Launch the process that you want to redirect (in this case,
// Child.exe). Make sure Child.exe is in the same directory as
// redirect.c launch redirect from a command line to prevent location
// confusion.
if (!CreateProcess(NULL,"Child.EXE",NULL,NULL,TRUE,
CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi))
DisplayError("CreateProcess");

// Set global child process handle to cause threads to exit.
hChildProcess = pi.hProcess;

// Close any unnecessary handles.
if (!CloseHandle(pi.hThread)) DisplayError("CloseHandle");
}

///////////////////////////////////////////////////////////////////////
// ReadAndHandleOutput
// Monitors handle for input. Exits when child exits or pipe breaks.
///////////////////////////////////////////////////////////////////////
void ReadAndHandleOutput(HANDLE hPipeRead)
{
CHAR lpBuffer[256];
DWORD nBytesRead;
DWORD nCharsWritten;

while(TRUE)
{
if (!ReadFile(hPipeRead,lpBuffer,sizeof(lpBuffer),
&nBytesRead,NULL) || !nBytesRead)
{
if (GetLastError() == ERROR_BROKEN_PIPE)
break; // pipe done - normal exit path.
else
DisplayError("ReadFile"); // Something bad happened.
}

// Display the character read on the screen.
if (!WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),lpBuffer,
nBytesRead,&nCharsWritten,NULL))
DisplayError("WriteConsole");
}
}

///////////////////////////////////////////////////////////////////////
// GetAndSendInputThread
// Thread procedure that monitors the console for input and sends input
// to the child process through the input pipe.
// This thread ends when the child application exits.
///////////////////////////////////////////////////////////////////////
DWORD WINAPI GetAndSendInputThread(LPVOID lpvThreadParam)
{
CHAR read_buff[256];
DWORD nBytesRead,nBytesWrote;
HANDLE hPipeWrite = (HANDLE)lpvThreadParam;

// Get input from our console and send it to child through the pipe.
while (bRunThread)
{
if(!ReadConsole(hStdIn,read_buff,1,&nBytesRead,NULL))
DisplayError("ReadConsole");

read_buff[nBytesRead] = '\0'; // Follow input with a NULL.

if (!WriteFile(hPipeWrite,read_buff,nBytesRead,&nBytesWrote,NULL))
{
if (GetLastError() == ERROR_NO_DATA)
break; // Pipe was closed (normal exit path).
else
DisplayError("WriteFile");
}
}

return 1;
}

///////////////////////////////////////////////////////////////////////
// DisplayError
// Displays the error number and corresponding message.
///////////////////////////////////////////////////////////////////////
void DisplayError(char *pszAPI)
{
LPVOID lpvMessageBuffer;
CHAR szPrintBuffer[512];
DWORD nCharsWritten;

FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpvMessageBuffer, 0, NULL);

wsprintf(szPrintBuffer,
"ERROR: API    = %s.\n   error code = %d.\n   message    = %s.\n",
pszAPI, GetLastError(), (char *)lpvMessageBuffer);

WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),szPrintBuffer,
lstrlen(szPrintBuffer),&nCharsWritten,NULL);

LocalFree(lpvMessageBuffer);
ExitProcess(GetLastError());
}

//////////////////////////////////////////////////////////////////////
// child.c
// Echoes all input to stdout. This will be redirected by the redirect
// sample. Compile and build child.c as a Win32 Console application and
// put it in the same directory as the redirect sample.
//
#include<windows.h>
#include<stdio.h>
#include<string.h>

void main ()
{
FILE*    fp;
CHAR     szInput[1024];

// Open the console. By doing this, you can send output directly to
// the console that will not be redirected.

fp = fopen("CON", "w");
if (!fp) {
printf("Error opening child console - perhaps there is none.\n");
fflush(NULL);
}
else
{

// Write a message direct to the console (will not be redirected).

fprintf(fp,"This data is being printed directly to the\n");
fprintf(fp,"console and will not be redirected.\n\n");
fprintf(fp,"Since the standard input and output have been\n");
fprintf(fp,"redirected data sent to and from those handles\n");
fprintf(fp,"will be redirected.\n\n");
fprintf(fp,"To send data to the std input of this process.\n");
fprintf(fp,"Click on the console window of the parent process\n");
fprintf(fp,"(redirect), and enter data from it's console\n\n");
fprintf(fp,"To exit this process send the string 'exit' to\n");
fprintf(fp,"it's standard input\n");
fflush(fp);
}

ZeroMemory(szInput,1024);
while (TRUE)
{
gets(szInput);
printf("Child echoing [%s]\n",szInput);
fflush(NULL);  // Must flush output buffers or else redirection
// will be problematic.
if (!_stricmp(szInput,"Exit") )
break;

ZeroMemory(szInput,strlen(szInput) );

}
}

VeryPDF
========================

You can use CreateProcess() function to run PCL to PDF Converter EXE application, and use CreatePipe to hide the DOS window, please refer to following web page for more information,

 

http://support.microsoft.com/kb/190351

 

Sample code

/*++

Copyright (c) 1998  Microsoft Corporation

Module Name:

Redirect.c

Description:

This sample illustrates how to spawn a child console based

application with redirected standard handles.

The following import libraries are required:

user32.lib

Dave McPherson (davemm)   11-March-98

--*/

#include<windows.h>

#pragma comment(lib, "User32.lib")

void DisplayError(char *pszAPI);

void ReadAndHandleOutput(HANDLE hPipeRead);

void PrepAndLaunchRedirectedChild(HANDLE hChildStdOut,

HANDLE hChildStdIn,

HANDLE hChildStdErr);

DWORD WINAPI GetAndSendInputThread(LPVOID lpvThreadParam);

HANDLE hChildProcess = NULL;

HANDLE hStdIn = NULL; // Handle to parents std input.

BOOL bRunThread = TRUE;

void main ()

{

HANDLE hOutputReadTmp,hOutputRead,hOutputWrite;

HANDLE hInputWriteTmp,hInputRead,hInputWrite;

HANDLE hErrorWrite;

HANDLE hThread;

DWORD ThreadId;

SECURITY_ATTRIBUTES sa;

// Set up the security attributes struct.

sa.nLength= sizeof(SECURITY_ATTRIBUTES);

sa.lpSecurityDescriptor = NULL;

sa.bInheritHandle = TRUE;

// Create the child output pipe.

if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0))

DisplayError("CreatePipe");

// Create a duplicate of the output write handle for the std error

// write handle. This is necessary in case the child application

// closes one of its std output handles.

if (!DuplicateHandle(GetCurrentProcess(),hOutputWrite,

GetCurrentProcess(),&hErrorWrite,0,

TRUE,DUPLICATE_SAME_ACCESS))

DisplayError("DuplicateHandle");

// Create the child input pipe.

if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0))

DisplayError("CreatePipe");

// Create new output read handle and the input write handles. Set

// the Properties to FALSE. Otherwise, the child inherits the

// properties and, as a result, non-closeable handles to the pipes

// are created.

if (!DuplicateHandle(GetCurrentProcess(),hOutputReadTmp,

GetCurrentProcess(),

&hOutputRead, // Address of new handle.

0,FALSE, // Make it uninheritable.

DUPLICATE_SAME_ACCESS))

DisplayError("DupliateHandle");

if (!DuplicateHandle(GetCurrentProcess(),hInputWriteTmp,

GetCurrentProcess(),

&hInputWrite, // Address of new handle.

0,FALSE, // Make it uninheritable.

DUPLICATE_SAME_ACCESS))

DisplayError("DupliateHandle");

// Close inheritable copies of the handles you do not want to be

// inherited.

if (!CloseHandle(hOutputReadTmp)) DisplayError("CloseHandle");

if (!CloseHandle(hInputWriteTmp)) DisplayError("CloseHandle");

// Get std input handle so you can close it and force the ReadFile to

// fail when you want the input thread to exit.

if ( (hStdIn = GetStdHandle(STD_INPUT_HANDLE)) ==

INVALID_HANDLE_VALUE )

DisplayError("GetStdHandle");

PrepAndLaunchRedirectedChild(hOutputWrite,hInputRead,hErrorWrite);

// Close pipe handles (do not continue to modify the parent).

// You need to make sure that no handles to the write end of the

// output pipe are maintained in this process or else the pipe will

// not close when the child process exits and the ReadFile will hang.

if (!CloseHandle(hOutputWrite)) DisplayError("CloseHandle");

if (!CloseHandle(hInputRead )) DisplayError("CloseHandle");

if (!CloseHandle(hErrorWrite)) DisplayError("CloseHandle");

// Launch the thread that gets the input and sends it to the child.

hThread = CreateThread(NULL,0,GetAndSendInputThread,

(LPVOID)hInputWrite,0,&ThreadId);

if (hThread == NULL) DisplayError("CreateThread");

// Read the child's output.

ReadAndHandleOutput(hOutputRead);

// Redirection is complete

// Force the read on the input to return by closing the stdin handle.

if (!CloseHandle(hStdIn)) DisplayError("CloseHandle");

// Tell the thread to exit and wait for thread to die.

bRunThread = FALSE;

if (WaitForSingleObject(hThread,INFINITE) == WAIT_FAILED)

DisplayError("WaitForSingleObject");

if (!CloseHandle(hOutputRead)) DisplayError("CloseHandle");

if (!CloseHandle(hInputWrite)) DisplayError("CloseHandle");

}

///////////////////////////////////////////////////////////////////////

// PrepAndLaunchRedirectedChild

// Sets up STARTUPINFO structure, and launches redirected child.

///////////////////////////////////////////////////////////////////////

void PrepAndLaunchRedirectedChild(HANDLE hChildStdOut,

HANDLE hChildStdIn,

HANDLE hChildStdErr)

{

PROCESS_INFORMATION pi;

STARTUPINFO si;

// Set up the start up info struct.

ZeroMemory(&si,sizeof(STARTUPINFO));

si.cb = sizeof(STARTUPINFO);

si.dwFlags = STARTF_USESTDHANDLES;

si.hStdOutput = hChildStdOut;

si.hStdInput  = hChildStdIn;

si.hStdError  = hChildStdErr;

// Use this if you want to hide the child:

//     si.wShowWindow = SW_HIDE;

// Note that dwFlags must include STARTF_USESHOWWINDOW if you want to

// use the wShowWindow flags.

// Launch the process that you want to redirect (in this case,

// Child.exe). Make sure Child.exe is in the same directory as

// redirect.c launch redirect from a command line to prevent location

// confusion.

if (!CreateProcess(NULL,"Child.EXE",NULL,NULL,TRUE,

CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi))

DisplayError("CreateProcess");

// Set global child process handle to cause threads to exit.

hChildProcess = pi.hProcess;

// Close any unnecessary handles.

if (!CloseHandle(pi.hThread)) DisplayError("CloseHandle");

}

///////////////////////////////////////////////////////////////////////

// ReadAndHandleOutput

// Monitors handle for input. Exits when child exits or pipe breaks.

///////////////////////////////////////////////////////////////////////

void ReadAndHandleOutput(HANDLE hPipeRead)

{

CHAR lpBuffer[256];

DWORD nBytesRead;

DWORD nCharsWritten;

while(TRUE)

{

if (!ReadFile(hPipeRead,lpBuffer,sizeof(lpBuffer),

&nBytesRead,NULL) || !nBytesRead)

{

if (GetLastError() == ERROR_BROKEN_PIPE)

break; // pipe done - normal exit path.

else

DisplayError("ReadFile"); // Something bad happened.

}

// Display the character read on the screen.

if (!WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),lpBuffer,

nBytesRead,&nCharsWritten,NULL))

DisplayError("WriteConsole");

}

}

///////////////////////////////////////////////////////////////////////

// GetAndSendInputThread

// Thread procedure that monitors the console for input and sends input

// to the child process through the input pipe.

// This thread ends when the child application exits.

///////////////////////////////////////////////////////////////////////

DWORD WINAPI GetAndSendInputThread(LPVOID lpvThreadParam)

{

CHAR read_buff[256];

DWORD nBytesRead,nBytesWrote;

HANDLE hPipeWrite = (HANDLE)lpvThreadParam;

// Get input from our console and send it to child through the pipe.

while (bRunThread)

{

if(!ReadConsole(hStdIn,read_buff,1,&nBytesRead,NULL))

DisplayError("ReadConsole");

read_buff[nBytesRead] = '\0'; // Follow input with a NULL.

if (!WriteFile(hPipeWrite,read_buff,nBytesRead,&nBytesWrote,NULL))

{

if (GetLastError() == ERROR_NO_DATA)

break; // Pipe was closed (normal exit path).

else

DisplayError("WriteFile");

}

}

return 1;

}

///////////////////////////////////////////////////////////////////////

// DisplayError

// Displays the error number and corresponding message.

///////////////////////////////////////////////////////////////////////

void DisplayError(char *pszAPI)

{

LPVOID lpvMessageBuffer;

CHAR szPrintBuffer[512];

DWORD nCharsWritten;

FormatMessage(

FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,

NULL, GetLastError(),

MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

(LPTSTR)&lpvMessageBuffer, 0, NULL);

wsprintf(szPrintBuffer,

"ERROR: API    = %s.\n   error code = %d.\n   message    = %s.\n",

pszAPI, GetLastError(), (char *)lpvMessageBuffer);

WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),szPrintBuffer,

lstrlen(szPrintBuffer),&nCharsWritten,NULL);

LocalFree(lpvMessageBuffer);

ExitProcess(GetLastError());

}

//////////////////////////////////////////////////////////////////////

// child.c

// Echoes all input to stdout. This will be redirected by the redirect

// sample. Compile and build child.c as a Win32 Console application and

// put it in the same directory as the redirect sample.

//

#include<windows.h>

#include<stdio.h>

#include<string.h>

void main ()

{

FILE*    fp;

CHAR     szInput[1024];

// Open the console. By doing this, you can send output directly to

// the console that will not be redirected.

fp = fopen("CON", "w");

if (!fp) {

printf("Error opening child console - perhaps there is none.\n");

fflush(NULL);

}

else

{

// Write a message direct to the console (will not be redirected).

fprintf(fp,"This data is being printed directly to the\n");

fprintf(fp,"console and will not be redirected.\n\n");

fprintf(fp,"Since the standard input and output have been\n");

fprintf(fp,"redirected data sent to and from those handles\n");

fprintf(fp,"will be redirected.\n\n");

fprintf(fp,"To send data to the std input of this process.\n");

fprintf(fp,"Click on the console window of the parent process\n");

fprintf(fp,"(redirect), and enter data from it's console\n\n");

fprintf(fp,"To exit this process send the string 'exit' to\n");

fprintf(fp,"it's standard input\n");

fflush(fp);

}

ZeroMemory(szInput,1024);

while (TRUE)

{

gets(szInput);

printf("Child echoing [%s]\n",szInput);

fflush(NULL);  // Must flush output buffers or else redirection

// will be problematic.

if (!_stricmp(szInput,"Exit") )

break;

ZeroMemory(szInput,strlen(szInput) );

}

}

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