By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

SmartPointers and COM from .NET

P: n/a
I have created a COM component in VB.NET with a couple of interfaces.
Any number of classes may be created that use both of these interfaces.

When I try to creat a variable that references one of my interfaces I get an
error about the methods being virtual - I can understand this.

How do I create a smart pointer to an unknown object that users both of my
interfaces?

In the code below the class MAPIForm is used as an example but in the real
world all I will know is the ProgID of the object that has used my
interfaces - _Form and _FormEvents.

--------- code snip ---------
Imports System
Imports System.Runtime.InteropServices

<ComVisible(False)> Public Delegate Sub NewMessageEventHandler()
<ComVisible(False)> Public Delegate Sub ShutdownEventHandler()
<ComVisible(False)> Public Delegate Sub PrintEventHandler()
<ComVisible(False)> Public Delegate Sub SavedEventHandler()

<GuidAttribute("93D44286-4BA4-4cc7-8971-0C7831EA0354"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface _Form
<DispId(&H1001)> Sub ShowForm(ByVal sCN As String, ByVal sGUID As
String)
<DispId(&H1002)> Sub ShutDownForm(ByVal SaveOptions As UInt32)
<DispId(&H1003)> Sub DoVerb(ByVal Verb As Int32)
End Interface

<GuidAttribute("06670E52-A3C2-480b-8D7A-7CE3DD1D03A3"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface _FormEvents
<DispId(&HF001)> Sub NewMessage()
<DispId(&HF002)> Sub Shutdown()
<DispId(&HF003)> Sub Print(ByVal PageNumber As UInt32, ByVal Status As
UInt32)
<DispId(&HF004)> Sub Saved()
End Interface

' This is your COM object, you must implement _Form and _FormEvents
' For each object that you create you will need to assign a unique GUID
' and give the class a unique ProgID
<GuidAttribute("9d8a13bf-df52-3084-954b-95e85887111d"),
ProgIdAttribute("SQLView.Form"), ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(GetType(_FormEvents))> _
Public Class MAPIForm
Implements _Form

Public Event NewMessage As NewMessageEventHandler
Public Event ShutDown As ShutdownEventHandler
Public Event Print As PrintEventHandler
Public Event Saved As SavedEventHandler

Private WithEvents frm As New OutlookForm

' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub

Public Sub ShowForm(ByVal sCN As String, ByVal sGUID As String)
Implements _Form.ShowForm
' This is called by Outlook when a form needs to be displayed
frm.txtCON.Text = sCN
frm.txtGUID.Text = sGUID
frm.Show()
End Sub

Public Sub ShutDownForm(ByVal SaveOptions As UInt32) Implements
_Form.ShutDownForm
' The is called by Outlook when it wants to close the form
End Sub

Public Sub DoVerb(ByVal Verb As Int32) Implements _Form.DoVerb
' The is called by Outlook when a verb (eg Print) needs to be done
' Verbs are defined in the cfg file
End Sub

Private Sub oForm_ShutDownForm() Handles frm.ShutDownForm
RaiseEvent ShutDown()
End Sub

End Class

-----------------------------

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com

Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.