Board index » cppbuilder » automation server idispatch return value problem

automation server idispatch return value problem

I have this problem. Some time ago I built an automation server which had a
single IDispatch function with two arguments, an [in] and an [out], and a
return value of int. I set the flags for the IDispatch interface (or at
least, they
somehow got set to) to dual,
ole automation and replaceable.This worked fine, and I set the function's
return value to TRUE if it completed successfully, FALSE otherwise.

I've just created a second server which is supposed to do a similar job.
However I can't set the replaceable flag for the IDispatch interface, as
it's greyed out, and it won't let me use a return value of type int for the
function - it insists that "functions of Automation Interfaces must have a
return type of HRESULT". Using HRESULT, the code generated is this:

  TAutoArgs<2> _args;
  _args[1] = data /*[VT_BSTR:0]*/;
  _args[2] = result /*[VT_BSTR:1]*/;
  return OleFunction(_dispid, _args); // return outcome of OLE call
presumably - always 0

whereas what I wanted (and got the first time) was this:

  TAutoArgs<2> _args;
  _args[1] = data /*[VT_BSTR:0]*/;
  _args[2] = result /*[VT_BSTR:1]*/;
  OleFunction(_dispid, _args);
  return _args.GetRetVariant(); // return outcome of calling my server
function.

I'm not clear what (if anything) different I did the second time round. Any
suggestions please?

 

Re:automation server idispatch return value problem


Brian,

I'm afraid I don't know how you got by the first time: HRESULT as return
value is the way it is unless your interface is marked 'local' (That's my
understanding of the rules of IDL, anyway).

I'm currently revisiting the various areas of the TypeLibrary that do not
enforce IDL rules and return value is one of these areas. You'll be allowed
to have a boolean return on a method of a dispinterface; but when it comes
to vtable-based interfaces, we want to enforce HRESULT return types to allow
COM to relay errors (specially when the object is remote).

I'm happy to investigate the scenario that allowed you to get by in the
first place; and let you know whether it's safe. Let me know if you find out
more.

Regards,

Bruneau.

Quote
Brian Marsden wrote in message <7guvp3$ek...@forums.borland.com>...
>I have this problem. Some time ago I built an automation server which had a
>single IDispatch function with two arguments, an [in] and an [out], and a
>return value of int. I set the flags for the IDispatch interface (or at
>least, they
>somehow got set to) to dual,
>ole automation and replaceable.This worked fine, and I set the function's
>return value to TRUE if it completed successfully, FALSE otherwise.

>I've just created a second server which is supposed to do a similar job.
>However I can't set the replaceable flag for the IDispatch interface, as
>it's greyed out, and it won't let me use a return value of type int for the
>function - it insists that "functions of Automation Interfaces must have a
>return type of HRESULT". Using HRESULT, the code generated is this:

>  TAutoArgs<2> _args;
>  _args[1] = data /*[VT_BSTR:0]*/;
>  _args[2] = result /*[VT_BSTR:1]*/;
>  return OleFunction(_dispid, _args); // return outcome of OLE call
>presumably - always 0

>whereas what I wanted (and got the first time) was this:

>  TAutoArgs<2> _args;
>  _args[1] = data /*[VT_BSTR:0]*/;
>  _args[2] = result /*[VT_BSTR:1]*/;
>  OleFunction(_dispid, _args);
>  return _args.GetRetVariant(); // return outcome of calling my server
>function.

>I'm not clear what (if anything) different I did the second time round. Any
>suggestions please?

Other Threads