Rules for "implements" in VB 
Author Message
 Rules for "implements" in VB

Does anyone know of a list of rules for creating an interface (or objects)
that can be implemented within VB. I'm creating a system which allows some
of our staff to use VB to work with our ATL objects.The interface and
methods work can be implemented (as expected) from C++ and Delphi, but do
not seem to compatible with VB's implements keyword.

I've created an interface (let's call it IMyInterface) which has the
following method HRESULT Test([out] long* value). When I reference this
relevent typelib within VB and then type Implements IMyInterface within VB I
noticed that the IMyInterface object does not exist, however if I change the
[out] to [out, retval] or [in, out] it lists the interface and allows me to
implement the interface from within VB.

So, now I'm looking for a possible list of things I have to do to ensure VB
will work with all my interfaces and objects - anyone know of such a thing ?

Thanks
Mark



Sun, 16 Mar 2003 03:00:00 GMT  
 Rules for "implements" in VB

The reason you have to change you method signature to [out, retval]
is to allow VB to return data from the method to a variable on the left-hand
side of the assignment operator.

In C all methods return HRESULT and returned data is stored in the [out,
retval]
parameter, but in VB the [ , retval] is returned to the left side of the
assignment,
so,

IDL - HRESULT MyMethod([out, retval]int Age);

In C,
obj->MyMethod(&Result)

In VB,

Result = MyMethod()


Quote:
> Does anyone know of a list of rules for creating an interface (or objects)
> that can be implemented within VB. I'm creating a system which allows some
> of our staff to use VB to work with our ATL objects.The interface and
> methods work can be implemented (as expected) from C++ and Delphi, but do
> not seem to compatible with VB's implements keyword.

> I've created an interface (let's call it IMyInterface) which has the
> following method HRESULT Test([out] long* value). When I reference this
> relevent typelib within VB and then type Implements IMyInterface within VB
I
> noticed that the IMyInterface object does not exist, however if I change
the
> [out] to [out, retval] or [in, out] it lists the interface and allows me
to
> implement the interface from within VB.

> So, now I'm looking for a possible list of things I have to do to ensure
VB
> will work with all my interfaces and objects - anyone know of such a thing
?

> Thanks
> Mark



Sun, 16 Mar 2003 03:00:00 GMT  
 Rules for "implements" in VB
Thanks, yes I was aware of the reason for using [out, retval]. However, I
had not intended for the [out] parameter to be a retval.

I was more interested in why [out] wasn't supported in VB and what
restriction were placed upon development of components/interfaces for use by
VB's Implements keyword. I've since found a document as part of the MSDN
that outlines what's supported. Although there's no descriptions of why the
lack of support for [out].

Still, at least I now know some of the pitfalls.

Thanks
Mark


Quote:

> The reason you have to change you method signature to [out, retval]
> is to allow VB to return data from the method to a variable on the
left-hand
> side of the assignment operator.

> In C all methods return HRESULT and returned data is stored in the [out,
> retval]
> parameter, but in VB the [ , retval] is returned to the left side of the
> assignment,
> so,

> IDL - HRESULT MyMethod([out, retval]int Age);

> In C,
> obj->MyMethod(&Result)

> In VB,

> Result = MyMethod()



Sun, 23 Mar 2003 03:00:00 GMT  
 Rules for "implements" in VB

[out] is not supported, because it is not a really natural convention. In VB
(like in C++ BTW) you have passing by value which corresponds to
[in] and passing by address which corresponds to [in, out]. [out] is an
efficiency mechanism used in IDL so as not to needlessly transmit the
value of the parameter from the caller to the callee because the callee
will ignore it anyway. With COM in C++ you pass [out] and [in, out]
via pointers (which is NOT the C++ reference type !!!) so you are free
to ignore what the pointer points to. VB doesn't have pointers and you
don't have this option... In fact VB can call a method containing [out]
parameters, but the VB runtime may create a memory leak...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Thanks, yes I was aware of the reason for using [out, retval]. However, I
> had not intended for the [out] parameter to be a retval.

> I was more interested in why [out] wasn't supported in VB and what
> restriction were placed upon development of components/interfaces for use
by
> VB's Implements keyword. I've since found a document as part of the MSDN
> that outlines what's supported. Although there's no descriptions of why
the
> lack of support for [out].

> Still, at least I now know some of the pitfalls.

> Thanks
> Mark



> > The reason you have to change you method signature to [out, retval]
> > is to allow VB to return data from the method to a variable on the
> left-hand
> > side of the assignment operator.

> > In C all methods return HRESULT and returned data is stored in the [out,
> > retval]
> > parameter, but in VB the [ , retval] is returned to the left side of the
> > assignment,
> > so,

> > IDL - HRESULT MyMethod([out, retval]int Age);

> > In C,
> > obj->MyMethod(&Result)

> > In VB,

> > Result = MyMethod()



Sun, 23 Mar 2003 03:00:00 GMT  
 Rules for "implements" in VB
Ah, thanks for the explanation - your last line indicates why I was confused
about the lack of this capability (and others) within the Implements keyword
usage in VB. i.e. that VB can call methods on these interfaces that I
designed, seemingly, without a problem, but I couldn't Implement them, which
seemed odd. However the more I try and get into VB's head (as it were) the
more I understand why it has these idiosyncrasy's.

Thanks again
Mark


Quote:

> [out] is not supported, because it is not a really natural convention. In
VB
> (like in C++ BTW) you have passing by value which corresponds to
> [in] and passing by address which corresponds to [in, out]. [out] is an
> efficiency mechanism used in IDL so as not to needlessly transmit the
> value of the parameter from the caller to the callee because the callee
> will ignore it anyway. With COM in C++ you pass [out] and [in, out]
> via pointers (which is NOT the C++ reference type !!!) so you are free
> to ignore what the pointer points to. VB doesn't have pointers and you
> don't have this option... In fact VB can call a method containing [out]
> parameters, but the VB runtime may create a memory leak...



Mon, 24 Mar 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Broken Rule For "For -- Loop"

2. PATH used during "post-Build" rules

3. implementing "ls eli*"

4. implementing "complete" comparison

5. Implement a "var.Add(...)"?

6. implementing "trace" in c

7. Question on implementing "repeat...until keypress"?

8. "Implement Connection Point..." option is missing

9. implement a "kill" with signals

10. How to implement "autometic statement completion"?

11. Implementing "cp" shell command

12. How to implement "Multiway Serch Tree"?

 

 
Powered by phpBB® Forum Software