The code to access the printer and proceed with printing is in VC++. The code has been working fine since years and it still works when I try to print from Windows XP machine(Connect and print on the same printer connected to WIndows 7 machine mentioned above).
The error code I receive when tried to print from windows server 2008 is 2 which says File not found. But when i access the machine from windows server 2008, it is accessible.
Below is the code I use:
Expand|Select|Wrap|Line Numbers
- if( m_hPrinter != NULL )
- EndWriter();
- m_hPrinter = ::CreateFile(lpPrinterName,GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
- if( m_hPrinter == INVALID_HANDLE_VALUE )
- {
- CString strErrMsg = "";
- strErrMsg.Format("Could not open file %s(error %d) - CreateFile returned invalid handle",lpPrinterName, GetLastError());
- MessageBox(NULL,strErrMsg,"Error Info",1);
- printf("Could not open file %s(error %d)\n - CreateFile returned invalid handle", lpPrinterName, GetLastError());
- }