Lack of continuity between Office Apps Printing Automation and problems with Word::Document PrintOut

N

NickP

Hi there,

First thing I wanted to mention, just an observation, is how different
the COM automation is between applications in MS Office. I am making a
shared add-in which requires printing and it really shows to lack of
continuity between the applications. The worst of which is Word which has 3
Print methods, PrintOutOld, PrintOut2000 and PrintOut. The closest app is
Excel which accepts a load of Variants but it also accepts BSTR arguments,
which Word does not, it uses VARIANT type instead. Anyway...

Unfortunately Word refuses to print.

If I just call PrintOut with no arguments it crashes with an unhelpful
error message. If I use the following parameters

//cDPPPrinter->getOutputFileName() == CString "c:\myfile.tmp"

VARIANT pVarAppend; pVarAppend.boolVal = FALSE;
VARIANT pVarPrintToFile; pVarPrintToFile.boolVal = TRUE;
VARIANT pVarOutputFileName; pVarOutputFileName.bstrVal =
cDPPPrinter->getOutputFileName().AllocSysString();

if(S_OK==pDPrDocument->PrintOut(&vtMissing, &pVarAppend, &vtMissing,
&pVarOutputFileName, &vtMissing, &vtMissing, &vtMissing, &vtMissing,
&vtMissing, &vtMissing, &pVarPrintToFile))
//Exception occurs here

An error occurs on line 788 of atlsimpstr.h when the PrintOut method is
called

m_pszData = static_cast< PXSTR >( pData->data());

I'm presuming that this is possibly down to the way I have assigned
pVarOutputFileName? Any ideas what I am doing wrong here? I have the code
working from VB.NET via just calling PrintOut yet in C++ it is a complete
nightmare!.

So yeah, just incase, I'm using VC 2005 via the shared add-in template.

Nick.
 
N

NickP

Hi there,

I appear to be getting allot further than I have so far by ammending the
code to the following,

VARIANT pVarAppend; pVarAppend.vt = VT_BOOL; pVarAppend.boolVal = FALSE;
VARIANT pVarPrintToFile; pVarPrintToFile.vt = VT_BOOL;
pVarPrintToFile.boolVal = TRUE;
VARIANT pVarOutputFileName; pVarOutputFileName.vt = VT_BSTR;
pVarOutputFileName.bstrVal =
cDPPPrinter->getOutputFileName().AllocSysString();

Although it still isn't 100% correct it is actually starting the process
now.

Nick.
 
J

Jialiang Ge [MSFT]

Hello Nick,

From your post, my understanding on this issue is: you want to print a Word
document in a shared add-in project. If I'm off base, please feel free to
let me know.

As you noticed, a VARIANT value should be initialized with it type (vt).
The MSDN article
http://msdn2.microsoft.com/en-us/library/ms221627(VS.80).aspx listed all
the vt values. Notice: If an optional argument to an Automation method is
left blank, do not pass a VARIANT of type VT_EMPTY. Instead, pass a VARIANT
of type VT_ERROR with a value of DISP_E_PARAMNOTFOUND.

By the way, the kb: http://support.microsoft.com/kb/178784 illustrate how
to print a Word document in a MFC project.

Please let me know if you have any other concerns, or need anything else.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hi Nick,

If you need further assistance, feel free to let me know. I will be more
than happy to be of assistance.

Have a great day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top