Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

trying to write simple print application

35 views
Skip to first unread message

Igor Golikov

unread,
Jun 16, 2009, 4:27:21 AM6/16/09
to
Hi
I am desperated - trying to write simple printing application for
windows ce 6 running on XScale processor.
The problem is that when I add "include "winddi.h"" to my project I am
getting a lot of compilation errors like:
error C2146: syntax error : missing ';' before identifier
'lfDefaultFont'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2146: syntax error : missing ';' before identifier
'lfAnsiVarFont'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2146: syntax error : missing ';' before identifier
'lfAnsiFixFont'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2146: syntax error : missing ';' before identifier
'BlendFunction'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2065: 'DEVMODEW' : undeclared identifier
error C2065: 'pdm' : undeclared identifier
error C2275: 'LPWSTR' : illegal use of this type as an expression
RMV4I\winnt.h(176) : see declaration of 'LPWSTR'
error C2146: syntax error : missing ')' before identifier
'pwszLogAddress'
warning C4229: anachronism used : modifiers on data are ignored
error C2078: too many initializers
error C2275: 'LPWSTR' : illegal use of this type as an expression
RMV4I\winnt.h(176) : see declaration of 'LPWSTR'
error C2059: syntax error : ')'
error C2061: syntax error : identifier 'DEVMODEW'
error C2061: syntax error : identifier 'TRIVERTEX'
error C2059: syntax error : ','
error C2061: syntax error : identifier 'DEVMODEW'
error C2061: syntax error : identifier 'TRIVERTEX'
error C2146: syntax error : missing ';' before identifier
'DrvEnablePDEV'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2378: 'DEVMODEW' : redefinition; symbol cannot be overloaded
with a typedef
error C2146: syntax error : missing ';' before identifier 'DEVMODE'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2378: 'DEVMODEW' : redefinition; symbol cannot be overloaded
with a typedef
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int


It seems to me like kind of incompatibility or my guess is wrong?
Please help me I am a newbier in develoing native applications since I
am .net programmer:)

I am looking for printing solution that will wotk with USB printer. I
have tryed a couple of libraries - they work fine with network
printers but not with USB:(. I have included USB printer driver to my
OS image and I have all th settings for printng in registry (according
to MSDN)
Maybe I am missing something ?

Thank you guys for your help

Paul G. Tobey [eMVP]

unread,
Jun 16, 2009, 11:14:37 AM6/16/09
to
Why are you including winddi.h? You shouldn't have to do that to print.

The PAGESETUPDLG is in commdlg.h. DOCINFO is in wingdi.h, but that should
be included when you include windows.h. You might need winx.h to get
MulDiv(), but I don't see the need for winddi.h. My print sample code all
just includes the pre-compiled header file set up by the new project wizard
in eVC or Visual Studio, commctrl.h, commdlg.h, and winx.h. No compile
problems.

Paul T.

"Igor Golikov" <sali...@gmail.com> wrote in message
news:bd5a1445-cdec-447f...@o5g2000prh.googlegroups.com...

Igor Golikov

unread,
Jun 17, 2009, 3:13:57 AM6/17/09
to
On Jun 16, 6:14 pm, "Paul G. Tobey [eMVP]" <p space tobey no spam AT

no instrument no spam DOT com> wrote:
> Why are you including winddi.h?  You shouldn't have to do that to print.
>
> The PAGESETUPDLG is in commdlg.h.  DOCINFO is in wingdi.h, but that should
> be included when you include windows.h.  You might need winx.h to get
> MulDiv(), but I don't see the need for winddi.h.  My print sample code all
> just includes the pre-compiled header file set up by the new project wizard
> in eVC or Visual Studio, commctrl.h, commdlg.h, and winx.h.  No compile
> problems.
>
> Paul T.
>
> "Igor Golikov" <salier...@gmail.com> wrote in message

Hi Paul
Well I have to include prnport.h to have PrinterOpen and PrinterSend,
haven't I?
And then I need to use DrvStartDocument - I understand it is in
winddi.h.
If you have some full printing example I willk be glad to learn from
it.
Thanks

Paul G. Tobey [eMVP]

unread,
Jun 17, 2009, 12:17:51 PM6/17/09
to
Igor,

It depends on your application architecture. If you use PrintDlg() or
PageSetupDlg() to show the user the printer settings, that returns the HDC
for the printer. You simply draw to that HDC, just as you would to the
screen, and the result is something on the printer. As mentioned, you have
to call StartDoc(), StartPage(), EndPage(), and EndDoc() to get the printer
driver to properly handle pagination and the whole job, but that's really
it. Here's some code from an application that uses the obsolete PrintDlg()
function, but should work:

// Show the print dialog.
PRINTDLG pd;
memset( &pd, 0, sizeof( pd ) );
pd.cbStruct = sizeof( pd );
pd.hwndOwner = hWnd;
pd.dwFlags = 0;

if ( PrintDlg( &pd ) )
{
// We have a DC for printing. Draw something to
// it.
DOCINFO di;
di.cbSize = sizeof( di );
di.fwType = 0;
di.lpszDatatype = 0;
di.lpszDocName = _T( "Test document" );
di.lpszOutput = NULL;

int jobid = StartDoc( pd.hdc, &di );

if ( jobid > 0 )
{
// Select a suitable font, pen, brush, or
// whatever.
LOGFONT lf;
lf.lfHeight = -(int)MulDiv( 20,
GetDeviceCaps( pd.hdc, LOGPIXELSY ), 72 );
lf.lfWidth = 0;
lf.lfEscapement = 10;
lf.lfOrientation = 10;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = CLEARTYPE_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH || FF_ROMAN;
_tcscpy( lf.lfFaceName, _T( "" ) ); // Allow the font mapper to pick.
HFONT hf = CreateFontIndirect( &lf );
HFONT oldhf = (HFONT)SelectObject( pd.hdc, hf );

// Start the next page.
StartPage( pd.hdc );

RECT r;
r.top = 0;
r.bottom = 500;
r.left = 0;
r.right = 2000;
DrawText( pd.hdc, _T( "This is a test string" ), -1,
&r, DT_LEFT );

EndPage( pd.hdc );

SelectObject( pd.hdc, oldhf );
DeleteObject( hf );

// End the document and release the printer
// to finish it.
EndDoc( pd.hdc );
}

// Clean up the DC created by the print dialog for
// us.
DeleteDC( pd.hdc );
}

You would certainly never ever call DrvStartDocument(). That's a function
directly in the printer driver. The OS is responsible for doing that.

Paul T.

0 new messages