Solved

print excel table from c++ in win2000

Posted on 2001-07-10
6
492 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

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

Author Comment

by:lubaka
ID: 6283219
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
ID: 6283281
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Axter
ID: 6284355
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
ID: 6825684
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
ID: 6875463
Per recommendation points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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.

749 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