Solved

print excel table from c++ in win2000

Posted on 2001-07-10
6
456 Views
Last Modified: 2008-03-10
Hi,

i have an c++ application that use excel com object
(Excel::_ApplicationPtr ).

to print the table we use the details from CPrintDialog object(mfc) in c++.

the problem is:
i cant print in win2000.
i think that it's because CPrintDialog returns the real port name but the algorithm in the excel print property search 4 it in  the registry (so it fail).
the same code works correctly in win95.

HELP !!!!!

the code :

Excel::_ApplicationPtr pXL;

try {
     pXL.CreateInstance(L"Excel.Application.9");
CPrintDialog dlg(FALSE, PD_USEDEVMODECOPIESANDCOLLATE | PD_NOPAGENUMS |PD_NOSELECTION);
               
if(dlg.DoModal() == IDOK)
{
  //**** didnt include all the code :
  //**** b4 i get lots of details ( like copies, page, etc
CString port_name = dlg.GetPortName();
pXL ->PutActivePrinter((LPCTSTR)(dev_name + " on " + port_name));
}


the error code i get is: 800a03ec
0
Comment
Question by:lubaka
6 Comments
 
LVL 2

Expert Comment

by:exelrud
Comment Utility
Have you considered make excel to show the print dialog to the user (like file|Print) ?
0
 

Author Comment

by:lubaka
Comment Utility
The excell application runs in the background (visable = false), so i cant use any of it's methods/dialogs/etc.

0
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
you should be using a BSTR in your call - ps this may not be you problem but you should know about this)

eg

BSTR bstrPrinter=CString(dev_name + " on " + port_name).AllocSysString();
pXL ->PutActivePrinter(bstrPrinter);
::SysFreeString(bstrPrinter);

a BSTR may look like a WCHAR* but it isn't - it has a hidden 4 bytes before the data that contain the length - if you just use a WCHAR* then it is random what 4 bytes are in front of it - you may be lucky you may be not.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Expert Comment

by:Axter
Comment Utility
Are you using the same version of Excel in both Win95 and Win2000?
Have you tested your code in Win98, WinNT, Win2000-Server?  If so, what was the result?
Are you printing to the same type of printer?

Any thing that has changed from one test-computer to another could be the real cause of the problem.  You should rule-them out first.
0
 
LVL 11

Expert Comment

by:griessh
Comment Utility
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since you never gave more feedback.

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
Comment Utility
Per recommendation points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now