Question and Answer Database FAQ: FAQ4629C — Return value as a prameter Category: ActiveX/OLE/COM/ActiveForm Platform: All-32Bit Product: C++Builder3.x, C++Builder4.x, Question: I would like to see a example on how to return a value as a parameter when the function is called from a ASP script. With BCB 3.0 I can return it, but with 4.0 the typelibrary editor say "Functions of Automation Interfaces must have a return type of HRESULT" Ok, but I can not call the function from ASP when it has pointers parameters..... Answer: Methods of interfaces must return HRESULT, unless the interface is marked 'local'. That's the rule of OLE and we enforce it. However, your interface can still return parameters accessible from an ASP script (or VB or Delphi or C++Builder): You simply have to take the return parameter as a reference parameter to your method. That parameter must be the last one and it must be marked [out, retval] from the flags page. For example: HRESULT __stdcall IMyInterface::GetName(BSTR *name /*out|retval*/); An ASP script will still access the method using ' Obj.GetName'. The returned HRESULT is hidden to the script writer (well, it's exposed in case of errors — i.e. via On Error). Similarly, a C++ client accesses your method using try { nameVar = server->GetName(); } catch ... (NOTE: In the old days things were not like this: with old style dispinterfaces, you specified your return type on the LHS. With the introduction of dual interfaces, this was no longer possible because there was no place to report an error condition: hence the 'HRESULT' on LHS and 'out|retval' reference parameter). 6/16/99 2:56:13 PM
Last Modified: 01-SEP-99