Board index » delphi » Return values and properties in a custom interface

Return values and properties in a custom interface

Hi,

I am creating some oleautomation compatible COM components using ATL via a
custom interface (not dual).

For those methods that return a value, I have declared parameters as
[out,retval]. For example in the IDL I have

[
  object,
  uuid(B0550411-A358-11D3-926F-00C04FA1187D),
  oleautomation,
  pointer_default(unique)
]
interface ITSLDrawingSurface : IUnknown
{
  HRESULT attach([in] LONG hWnd, [out,retval] VARIANT_BOOL * sts );

Quote
} ;

In VB6, the retval is correctly interpreted when the type library is
imported, and I can do the following :
      Dim sts As Boolean
      sts = drawingSurface.attach( hWnd )

In Delphi 3 and Delphi 5, we import the type library and it generates the
following :
    function attach(hWnd: Integer; out Retval: WordBool): HResult; stdcall;

Also, the properties are imported as their underlying get/put methods,
rather than properties that can just be read or assigned to.  Again, in VB6
they are OK.

As an aside, an earlier system that we implemented used a dual interface and
for the equivalent method the type library import crrectly generated :
   function attach(hWnd: Integer): WordBool; safecall;

How can I get Delphi (any version !!) to understand the return values and
properties correctly without resorting to dual/dispatch interfaces.
Please, please tell me that I don't have to re-engineer this (again).

Many thanks,

Dave Vint.

 

Re:Return values and properties in a custom interface


On Wed, 2 Feb 2000 16:53:41 -0000, "Dave Vint"

Quote
<dave.v...@tenetsystems.com> wrote:
>[
>  object,
>  uuid(B0550411-A358-11D3-926F-00C04FA1187D),
>  oleautomation,
>  pointer_default(unique)
>]
>interface ITSLDrawingSurface : IUnknown
>{
>  HRESULT attach([in] LONG hWnd, [out,retval] VARIANT_BOOL * sts );
>} ;

>In VB6, the retval is correctly interpreted when the type library is
>imported, and I can do the following :
>      Dim sts As Boolean
>      sts = drawingSurface.attach( hWnd )

>In Delphi 3 and Delphi 5, we import the type library and it generates the
>following :
>    function attach(hWnd: Integer; out Retval: WordBool): HResult; stdcall;

But this isn't wrong.
This will let you return the results in retval parameter, and becouse
the function returns an HResult, the values you send to result ( i.e.
: attach := 2; or Result := 2;) will be sent to the com-system as an
HRESULT on wich to raise error or not.

In VB6, you cannot use the HRESULT value, but instead you have to do :
Err.Raise to sendt the HRESULT, but this will trap also if you sendt
positive values, which is wrong.

HRESULT values is negative to signal error, can be positive to signal
an waring..  IMHO..

Re:Return values and properties in a custom interface


<<Dave Vint:
As an aside, an earlier system that we implemented used a dual
interface and for the equivalent method the type library import
crrectly generated :
   function attach(hWnd: Integer): WordBool; safecall;

Quote

Go to Tools|Environment options|Typelibrary (in D5) and
make All v-table interfaces is ticked, instead of Dual
interfaces only.

--
Deborah Pate

Re:Return values and properties in a custom interface


Thanks, I've tried that since posting the message and it didn't work.  I've
now given up and am tweaking my custom interfaces into duals.  It turns out
not to be too difficult/time consuming with ATL.

Dave.

Quote
Deborah Pate <dp...@ic24.net> wrote in message news:389b4309@dnews...
> <<Dave Vint:
> As an aside, an earlier system that we implemented used a dual
> interface and for the equivalent method the type library import
> crrectly generated :
>    function attach(hWnd: Integer): WordBool; safecall;

> Go to Tools|Environment options|Typelibrary (in D5) and
> make All v-table interfaces is ticked, instead of Dual
> interfaces only.

> --
> Deborah Pate

Re:Return values and properties in a custom interface


Interesting observation. However, I'd have to side with Delphi to be correct
on this one. If you import the typelib into VC++ I bet you'll have the same
results as Delphi. VB on the other hand, can have lots of added vodoo (which
is sometimes good, although might not be technically logical) that can
sometimes make life easier.

have fun
--
Binh Ly
Need help on COM development?
http://www.techvanguards.com

Quote
Dave Vint <dave.v...@tenetsystems.com> wrote in message

news:879muo$29v10@bornews.borland.com...
Quote
> Hi,

> I am creating some oleautomation compatible COM components using ATL via a
> custom interface (not dual).

> For those methods that return a value, I have declared parameters as
> [out,retval]. For example in the IDL I have

> [
>   object,
>   uuid(B0550411-A358-11D3-926F-00C04FA1187D),
>   oleautomation,
>   pointer_default(unique)
> ]
> interface ITSLDrawingSurface : IUnknown
> {
>   HRESULT attach([in] LONG hWnd, [out,retval] VARIANT_BOOL * sts );
> } ;

> In VB6, the retval is correctly interpreted when the type library is
> imported, and I can do the following :
>       Dim sts As Boolean
>       sts = drawingSurface.attach( hWnd )

> In Delphi 3 and Delphi 5, we import the type library and it generates the
> following :
>     function attach(hWnd: Integer; out Retval: WordBool): HResult;
stdcall;

> Also, the properties are imported as their underlying get/put methods,
> rather than properties that can just be read or assigned to.  Again, in
VB6
> they are OK.

> As an aside, an earlier system that we implemented used a dual interface
and
> for the equivalent method the type library import crrectly generated :
>    function attach(hWnd: Integer): WordBool; safecall;

> How can I get Delphi (any version !!) to understand the return values and
> properties correctly without resorting to dual/dispatch interfaces.
> Please, please tell me that I don't have to re-engineer this (again).

> Many thanks,

> Dave Vint.

Other Threads