Re: #import [out,retval] ? by Kim
Kim
Mon Aug 18 10:35:35 CDT 2003
Hi Bill,
> #import "..\\officeHelp\\officeHelp.tlb"
>
> G:\PWG\pwgDll\paramsWorkBook.cpp(200) : error C2660: 'getRowFromSheet' :
> function does not take 3 parameters
>
> Since I posted the message, I have learned that the 'raw_' versions of the
> methods at least compile with no errors. I will test the executables.
Ah, that clears it up. #import generates wrapper classes for you (IxxxPtr),
which transform [out, retval] into actual C++ return values, and the HRESULT
is mapped to an exception. You can open up the generated .tlh and .tli files
to see how #import does its magic (or at least what the magic result it)
If you want to stay with raw types, you should decorate #import like so:
#import "..\\officeHelp\\officeHelp.tlb" raw_native_types
raw_interfaces_only
This should throw no exceptions, nor produce wrappers.
Alternatively, if you're comfortable with exception handling, use the
wrappers directly:
IOfficeHelperPtr pOH(__uuidof(OfficeHelper));
_variant_t pRange = pOH->getRowFromSheet(foo, bar);
Note that any failure in the call chain will throw a _com_error exception
that you need to handle accordingly.
--
Best regards,
Kim Gräsman