#import [out,retval] ?

B

Bill Swartz

Hello,
I wrote an ATL in-proc server for use with VBA and MFC. In the MFC code, I
am using #import on the server's type library. MFC complains about interface
methods with an [out,retval] parameter. I can add a second copy of the
method to the interface with a new name and the [out,retval] changed to just
[out]. This seems to work. Is there a way to get rid of the errors without
adding a bunch of (almost) redundant methods to the interface?
 
K

Kim Gräsman

Bill,

Please post:
- IDL for the ATL server
- #import statement
- The exact error message you get

Best regards,
Kim
 
K

Kim Gräsman

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.
 
B

Bill Swartz

Thanks. I am now using raw interfaces. The non-raw versions were loosing
error info that my server creates with AtlReportError.
Kim Gräsman said:
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.
 
I

Igor Tandetnik

Bill Swartz said:
Thanks. I am now using raw interfaces. The non-raw versions were loosing
error info that my server creates with AtlReportError.

They shouldn't. They throw an exception of type _com_error on COM error,
and _com_error has methods for retrieving all the rich error info. Does
your COM component implement ISupportErrorInfo?
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top