Black Ice Software
September Developer News
Volume 12, Issue 9 - September, 2007
The BLACK ICE NEWSLETTER is published by Black Ice Software, LLC. The contents of this newsletter in its entirety are Copyright © 2007 by Black Ice Software, LLC. 292 Route 101, Salzburg Square, Amherst, NH 03031, USA. Black Ice Software, LLC. does hereby give permission to reproduce material contained in this newsletter, provided credit is given to the source, and a copy of the publication that the material appears in is sent to Black Ice Software at the above address. Phone: (603) 673-1019 Fax: (603) 672-4112

Printing Documents Programmatically


If you want to print a document programmatically you can try using the ShellExecute windows API function. The ShellExecute function tries to print the document using the application that is assigned to the specified file type in the system registry. If an application is assigned to the file type and it supports the “print” or “printto” feature from the command line you can print the document easily.


The following example demonstrates how to print a bitmap programmatically in C++:




// Initialixe structure

ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));

sei.cbSize = sizeof(SHELLEXECUTEINFO );


sei.lpFile = _T("C:\\Test\\picture.bmp");



sei.lpVerb = TEXT("printto");

sei.nShow = SW_HIDE;

sei.lpParameters = _T("\"Black Ice Color\""); // Printer name

sei.hProcess = hProcess;




// Error occurred. See GetLastError

DWORD dwError = GetLastError();

return ;