DWF Viewer (Read Only)
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using the EV COM interface from C++

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
474 Views, 11 Replies

Using the EV COM interface from C++

I am trying to use COM from within a C++/MFC dialog with a CAdViewer object
called m_ev
The wizard created automatically the wrapper class, but now I can't find a
TLB or a .C/.H file for using COM interface names like IAdPageViewer

This is the code I would like to exec. (where can I find names definition
? )

LPDISPATCH pDisp = NULL;
IAdPageViewer* pageViewer = NULL
HRESULT hr = S_OK;

pDisp = m_ev.GetViewer();
hr = pDisp->QueryInterface(IID_IAdPageViewer, (LPVOID*)&pageViewer);


On the other hand, I tried to use Print (hdc, dwflags) method directly from
CAdViewer instance "m_ev" , but nothing is printed out
There is no documentation about dwflags parameter on API help

CPrintDialog dlg(FALSE);
if (dlg.DoModal() == IDOK)
{
HDC hdc = dlg.GetPrinterDC();
DWORD dwFlags ;
CDC dcPrinter;
dcPrinter.Attach(hdc);
m_ev.Print (&dcPrinter, dwFlags);
}

Thanks
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: Anonymous

> The wizard created automatically the wrapper class, but now I can't find a
> TLB or a .C/.H file for using COM interface names like IAdPageViewer

You can import AdPageView.dll the same way you import a TLB.

#import "AdPageView.dll" // add any attributes like no_namespace here

> On the other hand, I tried to use Print (hdc, dwflags) method directly
from
> CAdViewer instance "m_ev" , but nothing is printed out
> There is no documentation about dwflags parameter on API help

Two things, you need to call StartDoc and I suggest using
IAdPageViewer::PrintEx.

HRESULT MyPrintClass::printAll (BSTR sourcePath)
{
if ( !m_hDC )
return E_FAIL;

HRESULT hr;
if ( FAILED (hr = m_pAdViewerWin->setSourcePath ( sourcePath ) ))
return hr;

CComPtr pIDispPageViewer;
if ( FAILED (hr = getPageViewer (&pIDispPageViewer) ))
return hr;

CComQIPtr<:IADPAGEVIEWER> pPageViewer = pIDispPageViewer;
if ( !pPageViewer )
return E_FAIL;

if ( FAILED (hr = pPageViewer->WaitForPageLoaded ()) )
return hr;

CComQIPtr<:IADCOLLECTION> pPageCollection;
pPageCollection = pPageViewer->GetPages ();
if ( !pPageCollection )
return E_FAIL;

// Set the Doc info
CString buff (sourcePath);
DOCINFO docI;
memset( &docI, 0, sizeof(DOCINFO) );
docI.cbSize = sizeof (DOCINFO);
docI.lpszDocName = buff;

// Start the page
int nError = StartDoc(m_hDC, &docI);
if ( nError <= 0 )
return E_FAIL;

long pageCount = pPageCollection->GetCount();
for ( int pNum = 1; pNum <= pageCount && SUCCEEDED (hr) ; pNum++ )
{
// Get the next page
CComVariant vPageIndex, vPage;
vPageIndex.vt = VT_I4;
vPageIndex.lVal = pNum;
vPage = pPageCollection->GetItem (vPageIndex);

// Load the page
pPageViewer->PutPage (vPage);
if (FAILED (hr = pPageViewer->WaitForPageLoaded () ))
break;

CComQIPtr<:IADPAGE> pPage = vPage.pdispVal;
CComQIPtr<:IADPAGEPAPER> pPaper = pPage->GetPaper ();
double paperWidth = pPaper->GetWidth();
double paperHeight = pPaper->GetHeight();

fitDCToPageSize (m_hDC, paperWidth, paperHeight,
(PaperUnits)pPaper->GetUnits() );
hr = pPageViewer->PrintEx ( (wireHDC)m_hDC, 0.0,0.0, paperWidth,
paperHeight, VARIANT_TRUE);
}

EndDoc (m_hDC);

return hr;
}

Hope this is helpful,
Ben
Message 3 of 12
Anonymous
in reply to: Anonymous

Hi Ben

Thank you for your help, I put the code inside my app. and got these
messages
getPageViewer : undeclared identifier
fitDCToPageSize : undeclared identifier
PaperUnits : undeclared identifier
PrintEx : is not a member of '_NoAddRefReleaseOnCComPtr
AdPageView::IAdPageViewer>'

I have imported AdPageView on stdafx.h using #import "AdPageView.dll" , but
I think I am still missing some header or library
Thanks again
Message 4 of 12
Anonymous
in reply to: Anonymous

The function I posted is part of a bigger class with other functions. With
the exception of the PrintEx error a you will have to implement what these
methods are doing your self, they are not part of AEV.


> getPageViewer : undeclared identifier
Call GetViewer on your m_ev instance

> fitDCToPageSize : undeclared identifier
You don't need to do this. I was going to cut this out of my post, but I
forgot. In this method I am querying the printer for its different paper
sizes and then refitting the DC to that paper size. I noticed that you are
using a print dialog and the print dialog will set up the DC for you based
on what the user decides.

> PaperUnits : undeclared identifier
This is something I defined myself. You can use 0, 1 and 2 or define your
own.
enum PaperUnits
{
kUnknown = 0,
kInches,
kMillimeters,
};

In regards to the PrintEx error, without seeing your code I am not exactly
sure what the problem is, but based on the error I think you have something
like

pAdPageViewer.PrintEx ( .........

when you should have

pAdPageViewer->PrintEx ( ...........

Let me know if you get it working.

Ben



"Carlos Kruger" wrote in message
news:50C0E12E12721D59C6D388D905F395FE@in.WebX.maYIadrTaRb...
> Hi Ben
>
> Thank you for your help, I put the code inside my app. and got these
> messages
> getPageViewer : undeclared identifier
> fitDCToPageSize : undeclared identifier
> PaperUnits : undeclared identifier
> PrintEx : is not a member of '_NoAddRefReleaseOnCComPtr
> AdPageView::IAdPageViewer>'
>
> I have imported AdPageView on stdafx.h using #import "AdPageView.dll" ,
but
> I think I am still missing some header or library
> Thanks again
>
>
Message 5 of 12
Anonymous
in reply to: Anonymous

Hi Ben

 

 

> getPageViewer : undeclared
identifier
> Call GetViewer on your m_ev instance

 

I DID THIS:

 

CComPtr<IDispatch> 
pIDispPageViewer;
pIDispPageViewer =
m_pAdViewerWin.GetViewer();
CComQIPtr<AdPageView::IAdPageViewer>
pPageViewer = pIDispPageViewer;
if ( !pPageViewer
)        return E_FAIL;

 

> In regards to the PrintEx error,
without seeing your code I am not exactly
> sure what the problem is, but
based on the error I think you have something
> like
>
>
    pAdPageViewer.PrintEx ( .........
> when you should
have
>     pAdPageViewer->PrintEx (
...........

 


Here is my code (with corrections), same as
yours, except I've got pPageViewer in replace of pAdPageViewer
When
I type pPageViewer->  , I get all the methods but there is no PrintEx in
the list

I DID THIS:

 

if ( FAILED (hr =
pPageViewer->WaitForPageLoaded ())
)        return
hr;
CComQIPtr<AdPageView::IAdCollection>
pPageCollection;
pPageCollection = pPageViewer->GetPages ();
if (
!pPageCollection )        return
E_FAIL;

 

CString buff (sourcePath);
DOCINFO
docI;
memset( &docI, 0, sizeof(DOCINFO) );
docI.cbSize = sizeof
(DOCINFO);
docI.lpszDocName = buff;
   
int nError =
StartDoc(m_hDC, &docI);
if ( nError <= 0
)        return E_FAIL;
long pageCount =
pPageCollection->GetCount();
for ( int pNum = 1; pNum <= pageCount
&& SUCCEEDED (hr) ; pNum++
)
{
       

        CComVariant vPageIndex,
vPage;
        vPageIndex.vt =
VT_I4;
        vPageIndex.lVal =
pNum;
        vPage =
pPageCollection->GetItem
(vPageIndex);
       

        pPageViewer->PutPage
(vPage);
        if (FAILED (hr =
pPageViewer->WaitForPageLoaded () ))  break;

 

       
CComQIPtr<AdPageView::IAdPage> pPage =
vPage.pdispVal;
       
CComQIPtr<AdPageView::IAdPagePaper> pPaper = pPage->GetPaper
();
        double paperWidth =
pPaper->GetWidth();
        double
paperHeight = pPaper->GetHeight();

 

     
  hr = pPageViewer->PrintEx ( (wireHDC)m_hDC, 0.0,0.0,
paperWidth,paperHeight, VARIANT_TRUE );  

 

}

 

Thanks you for your help

Carlos

 
Message 6 of 12
Anonymous
in reply to: Anonymous

No PrintEx, you must have an old version.
Use the line
href="http://www.autodesk.com/global/expressviewer/installer/ExpressViewerSetup.exe"><http://www.au...
>
to get the latest version.

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Hi Ben

 

 

> getPageViewer : undeclared
identifier
> Call GetViewer on your m_ev instance

 

I DID THIS:


face=Arial>
 

CComPtr<IDispatch> 
pIDispPageViewer;
pIDispPageViewer =
m_pAdViewerWin.GetViewer();
CComQIPtr<AdPageView::IAdPageViewer>
pPageViewer = pIDispPageViewer;
if ( !pPageViewer
)        return E_FAIL;

 

> In regards to the PrintEx error,
without seeing your code I am not exactly
> sure what the problem is,
but based on the error I think you have something
> like
>

>     pAdPageViewer.PrintEx ( .........
> when you
should have
>     pAdPageViewer->PrintEx (
...........

 


Here is my code (with corrections), same
as yours, except I've got pPageViewer in replace of
pAdPageViewer
When I type pPageViewer->  , I get all the
methods but there is no PrintEx in the list

I DID THIS:

 

if ( FAILED (hr =
pPageViewer->WaitForPageLoaded ())
)        return
hr;
CComQIPtr<AdPageView::IAdCollection>
pPageCollection;
pPageCollection = pPageViewer->GetPages ();
if (
!pPageCollection )        return
E_FAIL;

 

CString buff (sourcePath);
DOCINFO
docI;
memset( &docI, 0, sizeof(DOCINFO) );
docI.cbSize = sizeof
(DOCINFO);
docI.lpszDocName = buff;
   
int nError =
StartDoc(m_hDC, &docI);
if ( nError <= 0
)        return E_FAIL;
long pageCount =
pPageCollection->GetCount();
for ( int pNum = 1; pNum <= pageCount
&& SUCCEEDED (hr) ; pNum++
)
{
       

        CComVariant vPageIndex,
vPage;
        vPageIndex.vt =
VT_I4;
        vPageIndex.lVal =
pNum;
        vPage =
pPageCollection->GetItem
(vPageIndex);
       

        pPageViewer->PutPage
(vPage);
        if (FAILED (hr =
pPageViewer->WaitForPageLoaded () ))  break;

 


size=2>       
CComQIPtr<AdPageView::IAdPage> pPage =
vPage.pdispVal;
       
CComQIPtr<AdPageView::IAdPagePaper> pPaper = pPage->GetPaper
();
        double paperWidth =
pPaper->GetWidth();
        double
paperHeight = pPaper->GetHeight();

 

     
  hr = pPageViewer->PrintEx ( (wireHDC)m_hDC, 0.0,0.0,
paperWidth,paperHeight, VARIANT_TRUE );  

 

}

 

Thanks you for your help

Carlos


size=2>
 
Message 7 of 12
Anonymous
in reply to: Anonymous

You were right, I was using AdPageView.dll from a Nov/2002 version of EV
Thanks

"Ben Cochran" wrote in message
No PrintEx, you must have an old version.
Use the line
<> xe> to get the latest version.
Message 8 of 12
Anonymous
in reply to: Anonymous

Hi Ben

The PrintEx application worked great from C++
Now just a little doubt, when you send your PageView and hDC objects from VB
code, how are you deailing with it from C++ ActiveX ? as LPDISPATCH
parameters, OLEHANDLE ? LPUNKNOWN ?

I am trying this code in order to get the VB pageView object from within C++
Activex and it works great, just wanted to know if this is the right way

void CPrintExCtrl::doPrintex(LPDISPATCH pageView)
{

CComPtr pIDispPageViewer;
pIDispPageViewer = (IAdPageViewer) pageView;
...
...
}


calling from VB code....

printEXobject.doPrintex ( EVObject.viewer )

Thanks !
Message 9 of 12
Anonymous
in reply to: Anonymous

If I understand your question correctly you are creating a Viewer using VB
and then passing it as a parameter into a C++ function.



The problem is that you are casting an IDispatch into an IAdPageViewer and
then trying to assign it back to an IDispatch. You want to do a Query
Interface on the IDispatch for an IAdPageViewer. Using the CComQIPtr will
automatically do the Query Interface for you.



Use can use various different syntax but I would write it like so:



HRESULT CPrintExCtrl::doPrintex(IDispatch* pIDisp)

{

CComQIPtr < AdPageView::IAdPageViewer> pIPageViewer = pIDisp;

If ( !pIPageViewer )

Return E_FAIL;



.



}



Please let me know if I misunderstood your question.





"Carlos Kruger" wrote in message
news:4FE699D87D550A86D95ADB39E822CBB9@in.WebX.maYIadrTaRb...
> Hi Ben
>
> The PrintEx application worked great from C++
> Now just a little doubt, when you send your PageView and hDC objects from
VB
> code, how are you deailing with it from C++ ActiveX ? as LPDISPATCH
> parameters, OLEHANDLE ? LPUNKNOWN ?
>
> I am trying this code in order to get the VB pageView object from within
C++
> Activex and it works great, just wanted to know if this is the right way
>
> void CPrintExCtrl::doPrintex(LPDISPATCH pageView)
> {
>
> CComPtr pIDispPageViewer;
> pIDispPageViewer = (IAdPageViewer) pageView;
> ...
> ...
> }
>
>
> calling from VB code....
>
> printEXobject.doPrintex ( EVObject.viewer )
>
> Thanks !
>
>
Message 10 of 12
Anonymous
in reply to: Anonymous

Perfectly clear !
Now, how do you deal with the hDC parameter inside C++ if you want to send
it from VB code

CommonDialog1.ShowPrinter
hDC = CommonDialog1.hDC
Ctrl.PrintExl viewer, hDC

from C++ code:

Ctrl::PrintEx (IDispatch* pageView, HDC m_hDC) ??
in .odl dispinteface section, how do you cast HDC parameters ???
same question for ctrl.cpp BEGIN_DISPATCH_MAP section\

Thanks

>
> Please let me know if I misunderstood your question.
Message 11 of 12
Anonymous
in reply to: Anonymous

I solved it

I just call from VB:
PrintDialog.Flags = cdlPDReturnDC
PrintDialog.ShowPrinter
printCtrl.doPrintex viewer.viewer, PrintDialog1.hDC

and receive parameters in C++ DLL as :
void CPrintExCtrl::doPrintex(IDispatch* pageView, long hDC)

Anyway, thank you again for your help
Message 12 of 12
Anonymous
in reply to: Anonymous

Your solution is exactly what I would have suggested.



"Carlos Kruger" wrote in message
news:7035D54B030CEF17C6F8F7B23A78C1D2@in.WebX.maYIadrTaRb...
> I solved it
>
> I just call from VB:
> PrintDialog.Flags = cdlPDReturnDC
> PrintDialog.ShowPrinter
> printCtrl.doPrintex viewer.viewer, PrintDialog1.hDC
>
> and receive parameters in C++ DLL as :
> void CPrintExCtrl::doPrintex(IDispatch* pageView, long hDC)
>
> Anyway, thank you again for your help
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report