VB COM Interface Implementation 
Author Message
 VB COM Interface Implementation

Hi all,

I want to implement interfaces and callbacks from a vb6 activex exe to .net,
just like the Coffee sample of VB6. I have the following class in my vb6
server:

Private mstrGUID As String
Public Event Done(bolCanceled As Boolean)

Public Sub Done(bolCanceled As Boolean)
    RaiseEvent Done(bolCanceled)
End Sub

Public Property Get SearchGUID() As String
    SearchGUID = mstrGUID
End Property

Public Property Let SearchGUID(ByVal NewGUID As String)
    mstrGUID = NewGUID
End Property

Now my problem is how to implement the interface and the members in .NET. I
have defined a nested class as:

  public class myNotify: DOMDisPatcher.IDomSearchNotify
  {

  }

But how to I go on by implementing the get, set properties and the event?

Thanks,
Ivan



Sat, 04 Jun 2005 20:49:17 GMT  
 VB COM Interface Implementation
VB6 would define both two distinct interfaces for your COM server: a main
class interface (usually starts with a single underscore) and an events
interface (usually starts with a double underscore). If you want to make a
.NET version of the server that implements the identical interfaces, then
you need to make a reference to the VB6 type library. The VB or C# project
system will produce an interop assembly that provides a .NET version of the
COM interfaces. The import process creates several interfaces, optimised for
calling the VB6 thing. But in order to implement a class that looks just
like the VB6 think from .NET, you need to use some of the hidden
"underscore" interfaces.

You'll also need to specify some attributes on the class to tell .NET how to
expose your class to COM. Here is an example of your class implemented in VB
.NET and using the imported COM interfaces from VB6.

< _
System.Runtime.InteropServices.ComVisible(True), _
System.Runtime.InteropServices.ClassInterface(Runtime.InteropServices.ClassI
nterfaceType.None), _
System.Runtime.InteropServices.ComSourceInterfaces(GetType(DOMDisPatcher.__I
DomSearchNotify)) _

Quote:
> _

Public Class myNotify
    Implements DOMDisPatcher._IDomSearchNotify  ' the original COM interface
has a single underscore
    Implements DOMDisPatcher.__IDomSearchNotify_Event ' the .NET version of
the event interface

    Private mstrGUID As String

    ' Avoid name collision with Done event by renaming to ImplementsDone
    Sub ImplementsDone(ByRef bolCanceled As Boolean) Implements
DOMDisPatcher._IDomSearchNotify.Done
        RaiseEvent Done(bolCanceled)
    End Sub

    Property SearchGUID() As String Implements
DOMDisPatcher._IDomSearchNotify.SearchGUID
        Get
            Return Me.mstrGUID
        End Get
        Set(ByVal Value As String)
            Me.mstrGUID = Value
        End Set
    End Property

    ' The runtime matches this event by NAME in
DOMDisPatcher.__IDomSearchNotify, as specified
    ' by the ComSourceInterfacesAttribute.
    Event Done(ByRef bolCanceled As Boolean) Implements
DOMDisPatcher.__IDomSearchNotify_Event.Done

End Class

I hope this gets you started. You can read more about this in the VS help
topic "Exposing .NET Framework Components to COM"
John
The VB .NET Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> Hi all,

> I want to implement interfaces and callbacks from a vb6 activex exe to
.net,
> just like the Coffee sample of VB6. I have the following class in my vb6
> server:

> Private mstrGUID As String
> Public Event Done(bolCanceled As Boolean)

> Public Sub Done(bolCanceled As Boolean)
>     RaiseEvent Done(bolCanceled)
> End Sub

> Public Property Get SearchGUID() As String
>     SearchGUID = mstrGUID
> End Property

> Public Property Let SearchGUID(ByVal NewGUID As String)
>     mstrGUID = NewGUID
> End Property

> Now my problem is how to implement the interface and the members in .NET.
I
> have defined a nested class as:

>   public class myNotify: DOMDisPatcher.IDomSearchNotify
>   {

>   }

> But how to I go on by implementing the get, set properties and the event?

> Thanks,
> Ivan



Mon, 06 Jun 2005 05:50:16 GMT  
 VB COM Interface Implementation
Actually I want the other way round, where the COM interface is exposed to
..NET. I managed to somehow implement the interface, but I'm still not sure
how the event will be raised coz the delegate stuff is still confusing for
me. I've got the following class now:

 //Notify class (nested)
 public class Notify: IDomSearchNotify
 {
  private string sGUID = null;
  public event __IDomSearchNotify_DoneEventHandler Done;

  void _IDomSearchNotify.Done(ref bool bolCanceled)
  {
   if (Done != null)
    Done(ref bolCanceled);
  }

  string _IDomSearchNotify.SearchGUID
  {
   get
   {
    return sGUID;
   }
   set
   {
    sGUID = value;
   }
  }
 }

I think it should do the job. Right??

Ivan



Quote:
> VB6 would define both two distinct interfaces for your COM server: a main
> class interface (usually starts with a single underscore) and an events
> interface (usually starts with a double underscore). If you want to make a
> .NET version of the server that implements the identical interfaces, then
> you need to make a reference to the VB6 type library. The VB or C# project
> system will produce an interop assembly that provides a .NET version of
the
> COM interfaces. The import process creates several interfaces, optimised
for
> calling the VB6 thing. But in order to implement a class that looks just
> like the VB6 think from .NET, you need to use some of the hidden
> "underscore" interfaces.

> You'll also need to specify some attributes on the class to tell .NET how
to
> expose your class to COM. Here is an example of your class implemented in
VB
> .NET and using the imported COM interfaces from VB6.

> < _
> System.Runtime.InteropServices.ComVisible(True), _

System.Runtime.InteropServices.ClassInterface(Runtime.InteropServices.ClassI
Quote:
> nterfaceType.None), _

System.Runtime.InteropServices.ComSourceInterfaces(GetType(DOMDisPatcher.__I

- Show quoted text -

Quote:
> DomSearchNotify)) _
> > _
> Public Class myNotify
>     Implements DOMDisPatcher._IDomSearchNotify  ' the original COM
interface
> has a single underscore
>     Implements DOMDisPatcher.__IDomSearchNotify_Event ' the .NET version
of
> the event interface

>     Private mstrGUID As String

>     ' Avoid name collision with Done event by renaming to ImplementsDone
>     Sub ImplementsDone(ByRef bolCanceled As Boolean) Implements
> DOMDisPatcher._IDomSearchNotify.Done
>         RaiseEvent Done(bolCanceled)
>     End Sub

>     Property SearchGUID() As String Implements
> DOMDisPatcher._IDomSearchNotify.SearchGUID
>         Get
>             Return Me.mstrGUID
>         End Get
>         Set(ByVal Value As String)
>             Me.mstrGUID = Value
>         End Set
>     End Property

>     ' The runtime matches this event by NAME in
> DOMDisPatcher.__IDomSearchNotify, as specified
>     ' by the ComSourceInterfacesAttribute.
>     Event Done(ByRef bolCanceled As Boolean) Implements
> DOMDisPatcher.__IDomSearchNotify_Event.Done

> End Class

> I hope this gets you started. You can read more about this in the VS help
> topic "Exposing .NET Framework Components to COM"
> John
> The VB .NET Team

> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.


> > Hi all,

> > I want to implement interfaces and callbacks from a vb6 activex exe to
> .net,
> > just like the Coffee sample of VB6. I have the following class in my vb6
> > server:

> > Private mstrGUID As String
> > Public Event Done(bolCanceled As Boolean)

> > Public Sub Done(bolCanceled As Boolean)
> >     RaiseEvent Done(bolCanceled)
> > End Sub

> > Public Property Get SearchGUID() As String
> >     SearchGUID = mstrGUID
> > End Property

> > Public Property Let SearchGUID(ByVal NewGUID As String)
> >     mstrGUID = NewGUID
> > End Property

> > Now my problem is how to implement the interface and the members in
..NET.
> I
> > have defined a nested class as:

> >   public class myNotify: DOMDisPatcher.IDomSearchNotify
> >   {

> >   }

> > But how to I go on by implementing the get, set properties and the
event?

> > Thanks,
> > Ivan



Mon, 06 Jun 2005 18:07:18 GMT  
 VB COM Interface Implementation
Sorry that I wasn't as helpful before. I'm not a pro on C# event syntax,
just VB. I would recommend that you post your message to one of the
following newsgroups to get better support.
    microsoft.public.dotnet.framework.interop
    microsoft.public.dotnet.languages.csharp
Good luck!
John
The VB .NET Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:
> Actually I want the other way round, where the COM interface is exposed to
> .NET. I managed to somehow implement the interface, but I'm still not sure
> how the event will be raised coz the delegate stuff is still confusing for
> me. I've got the following class now:

>  //Notify class (nested)
>  public class Notify: IDomSearchNotify
>  {
>   private string sGUID = null;
>   public event __IDomSearchNotify_DoneEventHandler Done;

>   void _IDomSearchNotify.Done(ref bool bolCanceled)
>   {
>    if (Done != null)
>     Done(ref bolCanceled);
>   }

>   string _IDomSearchNotify.SearchGUID
>   {
>    get
>    {
>     return sGUID;
>    }
>    set
>    {
>     sGUID = value;
>    }
>   }
>  }

> I think it should do the job. Right??

> Ivan



> > VB6 would define both two distinct interfaces for your COM server: a
main
> > class interface (usually starts with a single underscore) and an events
> > interface (usually starts with a double underscore). If you want to make
a
> > .NET version of the server that implements the identical interfaces,
then
> > you need to make a reference to the VB6 type library. The VB or C#
project
> > system will produce an interop assembly that provides a .NET version of
> the
> > COM interfaces. The import process creates several interfaces, optimised
> for
> > calling the VB6 thing. But in order to implement a class that looks just
> > like the VB6 think from .NET, you need to use some of the hidden
> > "underscore" interfaces.

> > You'll also need to specify some attributes on the class to tell .NET
how
> to
> > expose your class to COM. Here is an example of your class implemented
in
> VB
> > .NET and using the imported COM interfaces from VB6.

> > < _
> > System.Runtime.InteropServices.ComVisible(True), _

System.Runtime.InteropServices.ClassInterface(Runtime.InteropServices.ClassI
Quote:
> > nterfaceType.None), _

System.Runtime.InteropServices.ComSourceInterfaces(GetType(DOMDisPatcher.__I

- Show quoted text -

Quote:
> > DomSearchNotify)) _
> > > _
> > Public Class myNotify
> >     Implements DOMDisPatcher._IDomSearchNotify  ' the original COM
> interface
> > has a single underscore
> >     Implements DOMDisPatcher.__IDomSearchNotify_Event ' the .NET version
> of
> > the event interface

> >     Private mstrGUID As String

> >     ' Avoid name collision with Done event by renaming to ImplementsDone
> >     Sub ImplementsDone(ByRef bolCanceled As Boolean) Implements
> > DOMDisPatcher._IDomSearchNotify.Done
> >         RaiseEvent Done(bolCanceled)
> >     End Sub

> >     Property SearchGUID() As String Implements
> > DOMDisPatcher._IDomSearchNotify.SearchGUID
> >         Get
> >             Return Me.mstrGUID
> >         End Get
> >         Set(ByVal Value As String)
> >             Me.mstrGUID = Value
> >         End Set
> >     End Property

> >     ' The runtime matches this event by NAME in
> > DOMDisPatcher.__IDomSearchNotify, as specified
> >     ' by the ComSourceInterfacesAttribute.
> >     Event Done(ByRef bolCanceled As Boolean) Implements
> > DOMDisPatcher.__IDomSearchNotify_Event.Done

> > End Class

> > I hope this gets you started. You can read more about this in the VS
help
> > topic "Exposing .NET Framework Components to COM"
> > John
> > The VB .NET Team

> > --
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.


> > > Hi all,

> > > I want to implement interfaces and callbacks from a vb6 activex exe to
> > .net,
> > > just like the Coffee sample of VB6. I have the following class in my
vb6
> > > server:

> > > Private mstrGUID As String
> > > Public Event Done(bolCanceled As Boolean)

> > > Public Sub Done(bolCanceled As Boolean)
> > >     RaiseEvent Done(bolCanceled)
> > > End Sub

> > > Public Property Get SearchGUID() As String
> > >     SearchGUID = mstrGUID
> > > End Property

> > > Public Property Let SearchGUID(ByVal NewGUID As String)
> > >     mstrGUID = NewGUID
> > > End Property

> > > Now my problem is how to implement the interface and the members in
> .NET.
> > I
> > > have defined a nested class as:

> > >   public class myNotify: DOMDisPatcher.IDomSearchNotify
> > >   {

> > >   }

> > > But how to I go on by implementing the get, set properties and the
> event?

> > > Thanks,
> > > Ivan



Tue, 07 Jun 2005 04:27:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB Interface Implementation - Novice Question

2. Lack of support for explicit interface implementation in VB.Net

3. Interface implementation in VB => nod Debugging

4. Explicit interface implementation?

5. Generate Interface implementation Code?

6. Interface implementation: property name is a keyword

7. Changes in Interface implementation

8. virtual events, explicit interface implementation

9. Interface Implementation

10. Interface and Implementation file location

11. Interface Implementation for OCX

12. TAPI 3 - Implementation of the interface ITLegacyAddressMediaControl2 in VB6

 

 
Powered by phpBB® Forum Software