Click here to Skip to main content
15,898,724 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I am relatively new to excel automation, And I have to do automation projects.
This code shows that RangePtr and Range * differ.
Exell::_WorksheetPtr pSheet;
Excel::RangePtr pRangeA1 = pSheet->Cells->Item[1][1];
Excel::RangePtr pRangeB2 = pSheet->Cells->Item[2][2];
Excel::RangePtr pRange1 = pSheet->Range[(Range*)pRangeA1][(Range*)pRangeB2];//ok
Exell::RangePtr pRange2 = pSheet->Range[pRangeA1][pRangeA2];//causes error:
/*
error C2664: 'Excel::_Worksheet::GetRange' : cannot convert parameter 1 from 'Excel::RangePtr' to 'const _variant_t &'
*/

It means that Range * converts to _variant_t & and RangePtr doesn't.
I didn't find Declaration for RangePtr iGwtRangen *.tlh, *.tli, VC++ include directories.
Can anybody help me?
Thanks in advance
abzadeh
Posted
Updated 16-Apr-11 21:51pm
v4

1 solution

Did you examine if the RangePtr is a smart pointer to a Range instance? A Range pointer inheriting from IUnknown would fit a constructor of _variant_t whereas the smart pointer wouldn't without a cast or dereference.
 
Share this answer
 
Comments
mr.abzadeh 18-Apr-11 14:07pm    
It seems very resonable to be the case. but I found no way to examine. No help in msdn, no definition in *.tlh and *.tli files.
Thanks for your point out
abzadeh
Niklas L 18-Apr-11 14:21pm    
If you right-click it and pick 'Go To Declaration'. Can't VS find the declaration then? (It does miss on occasion.)
mr.abzadeh 18-Apr-11 14:43pm    
No.
It just says this:
A definition for the 'RangePtr' could not be located
mr.abzadeh 18-Apr-11 15:30pm    
mr.abzadeh - 7 mins ago
One way to prove that RangePtr is a smart ptr.
Disassemply shows that when instance of RangePtr goes out of scope, it is destructed as below
call _com_ptr_t<_com_IIID<excel::range,&_guid_00020846_0000_0000_c000_000000000046> >::~_com_ptr_t<_com_IIID<excel::range,&_guid_00020846_0000_0000_c000_000000000046> > (0E31087h).
Niklas L 18-Apr-11 15:36pm    
Indeed it is

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900