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

HELP! CDC::StartDoc() problems

368 views
Skip to first unread message

Cqwerv

unread,
Dec 21, 1998, 3:00:00 AM12/21/98
to
I am trying to print a document that may be more than one page long, so I'm
calling StartDoc before printing begins and EndDoc after printing is complete.

My problem is when I call pDC->StartDoc( &stDocInfo ), I get the error "The
parameter is incorrect." This happens for both printing and previewing
printing.

Following the only examples I could find, I created a new DOCINFO structure and
set everything to NULL except for stDocInfo.lpszDocName which I set to a
character string.

I traced through the code and found that CDC::StartDoc() is expecting a long
pointer to a character string and not a DOCINFO pointer, as the documentation
led me to believe. I changed my call to pDC->StartDoc( "Name" ) but I still
got the parameter error. I traced as far as I could into the program execution
but could get only as far as a call to ::StartDoc(m_hDC, lpDocInfo) in
Afxwin1.inl. I could not trace into this. I ran it again and checked to make
sure m_hDC was not NULL and it was not. I watched the lpDocInfo parameter
passed to this function get created in CDC::StartDoc(), so it should be valid
also.

I am using Visual C++ 5 with Service Pack 3 loaded.

I am going crazy.

David Lowndes

unread,
Dec 22, 1998, 3:00:00 AM12/22/98
to
>My problem is when I call pDC->StartDoc( &stDocInfo ), I get the error "The
>parameter is incorrect." This happens for both printing and previewing
>printing.
>
>Following the only examples I could find, I created a new DOCINFO structure and
>set everything to NULL except for stDocInfo.lpszDocName which I set to a
>character string.

You need to set cbSize to sizeof( DOCINFO ).

>I traced through the code and found that CDC::StartDoc() is expecting a long
>pointer to a character string and not a DOCINFO pointer, as the documentation
>led me to believe.

No, CDC::StartDoc is defined as:

int StartDoc( LPDOCINFO lpDocInfo );

>I traced as far as I could into the program execution
>but could get only as far as a call to ::StartDoc(m_hDC, lpDocInfo) in
>Afxwin1.inl. I could not trace into this.

::StartDoc is the Win32 API, you don't have source for this, so it
wouldn't make much sense to debug it.

Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.

Cqwerv

unread,
Dec 22, 1998, 3:00:00 AM12/22/98
to
>>My problem is when I call pDC->StartDoc( &stDocInfo ), I get the error "The
>>parameter is incorrect." This happens for both printing and previewing
>>printing.
>>
>>Following the only examples I could find, I created a new DOCINFO structure
>and
>>set everything to NULL except for stDocInfo.lpszDocName which I set to a
>>character string.
>
>You need to set cbSize to sizeof( DOCINFO ).

Sorry, I forgot to say I set that one, too:

DOCINFO stDocInfo;
memset( &stDocInfo, 0, sizeof( stDocInfo ) );
stDocInfo.cbSize = sizeof( stDocInfo );
stDocInfo.lpszDocName = "Document Name";

>>I traced through the code and found that CDC::StartDoc() is expecting a long
>>pointer to a character string and not a DOCINFO pointer, as the
>documentation
>>led me to believe.
>
>No, CDC::StartDoc is defined as:
>
>int StartDoc( LPDOCINFO lpDocInfo );

I know. However, I (just) found that CDC::StartDoc is overloaded to accept
either a pointer to a DOCINFO structure or a string. When given a pointer to a
string it creates a DOCINFO structure and fills it exactly as I have above and
calls the Win32 API function. It does not seem to matter which I call, I get
the "incorrect parameter" message.

>>I traced as far as I could into the program execution
>>but could get only as far as a call to ::StartDoc(m_hDC, lpDocInfo) in
>>Afxwin1.inl. I could not trace into this.
>
> ::StartDoc is the Win32 API, you don't have source for this, so it
>wouldn't make much sense to debug it.

Thanks for your response, but unfortunately I'm still at square one here.

David Lowndes

unread,
Dec 22, 1998, 3:00:00 AM12/22/98
to
>>You need to set cbSize to sizeof( DOCINFO ).
>
>Sorry, I forgot to say I set that one, too:

In that case, the only other "parameter" is your device context. How
do you get that set-up?

Cqwerv

unread,
Dec 24, 1998, 3:00:00 AM12/24/98
to
>>>You need to set cbSize to sizeof( DOCINFO ).
>>
>>Sorry, I forgot to say I set that one, too:
>
>In that case, the only other "parameter" is your device context. How
>do you get that set-up?

The device context is coming from MFC/Visual C++. I'm using the one passed to
the "OnPrint" function parameters: CDC *pDC, CPrintInfo *pInfo (I'm naming
these from memory--I'm on vacation and my Visual C++ stuff is all at work) that
are supplied by Class Wizard. Shouldn't that be the correct device context?

David Lowndes

unread,
Dec 24, 1998, 3:00:00 AM12/24/98
to
>>In that case, the only other "parameter" is your device context. How
>>do you get that set-up?
>
>The device context is coming from MFC/Visual C++. I'm using the one passed to
>the "OnPrint" function parameters: CDC *pDC, CPrintInfo *pInfo (I'm naming
>these from memory--I'm on vacation and my Visual C++ stuff is all at work) that
>are supplied by Class Wizard. Shouldn't that be the correct device context?

I guess it should be, but as there's obviously something wrong, and
it's not a particularly involved API, the problem's not far away!

Merry Christmas
Dave
----
Address is altered to discourage junk mail.


Please post responses to the newsgroup thread,

there's no need for follow up email copies.
http://www.bj.co.uk

0 new messages