473,382 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Raising Events Handled by a COM Sink

I have created a class with a number of methods and events as described in
the MSDN infor for handling events.

I am trying to use the attributes GuidAttribute and DispID. The problem that
I'm having is that when I try to use the tlb file the guid and dispid
attributes seem to have been ignored - here is some of the code I'm using.

Any ideas ?

-------- snip ---------------
<GuidAttribute("20000000-3371-0000-AF8A-AFFECC1B0967"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface _Form
DispId(10)> _
Sub ShowForm(ByVal sCN As String, ByVal sGUID As String)
<DispId(20)> _
Event ShutDownForm()
End Interface
<GuidAttribute("10000000-3371-0000-AF8A-AFFECC1B0967"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)> _
Public Interface MAPIFormEvents
Sub ShutdownForm()
End Interface

<GuidAttribute("30000000-3371-0000-AF8A-AFFECC1B0967"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(GetType(MAPIFormEvents))> _
Public Class Form
Implements _Form
Public Event ShutDownForm() Implements _Form.ShutDownForm

--------- snip ----------------

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

Nov 21 '05 #1
9 1699
starting from the general and moving into the more specific...
0) Your class "Form" needs to inherit from ServicedComponent
1) the compiler will assume the Attribute portion of the tag -- so, you
can simply write Guid(...) in lieu of GuidAttribute
2) <ClassInterface(ClassInterfaceType.None)> is the recommended setting
-- ClassInterfaceType.AutoDual causes versioning problems
3) DispIds are generated based upon the position of the members in the
class; yo can override them, but this level of control is generally not
needed unless you are attempting to prevent a new version of your
component from breaking an app that uses a previous version

Are you trying to call your .NET component in non-.NET code? If so,
see "Calling a .NET Component from a COM Component"
http://msdn.microsoft.com/library/en...asp?frame=true
and
"Packaging an Assembly for COM"
http://msdn2.microsoft.com/library/b...us,vs.80).aspx

Nov 21 '05 #2
Hi,

Why do I need to use ServicedComponent - I thought this was for COM+ ?

According to the MSDN docs I should use GuidAttribute to avoid confusion
with the type guid

I'm not using ClassInterfaceType.AutoDual

I don't think your comments tell me why my guids are not being using when
generating the code - the tlb shows a completely different set of guids.

How do I get me tlb to contain definitions (my guids) for the interfaces ?

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
"stand__sure" <st*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
starting from the general and moving into the more specific...
0) Your class "Form" needs to inherit from ServicedComponent
1) the compiler will assume the Attribute portion of the tag -- so, you
can simply write Guid(...) in lieu of GuidAttribute
2) <ClassInterface(ClassInterfaceType.None)> is the recommended setting
-- ClassInterfaceType.AutoDual causes versioning problems
3) DispIds are generated based upon the position of the members in the
class; yo can override them, but this level of control is generally not
needed unless you are attempting to prevent a new version of your
component from breaking an app that uses a previous version

Are you trying to call your .NET component in non-.NET code? If so,
see "Calling a .NET Component from a COM Component"
http://msdn.microsoft.com/library/en...asp?frame=true
and
"Packaging an Assembly for COM"
http://msdn2.microsoft.com/library/b...us,vs.80).aspx

Nov 21 '05 #3
sorry, about the dual thing... could have sworn I read it in your
code... as for ServicedComponent inherit it -- you are doing COM...

I have been unable to replicate your problem on my box... please post
FULL code

Nov 21 '05 #4
also, lest I forget are you using a .NET COM component in a non .NET
language (I assume that you are, but more details as to where and how
you are trying to use the class would be helpful). how are you
registering the component? regsvcs? regasm? what is your command line
for doing this?

Nov 21 '05 #5
Yes, I'm creating a .NET component and trying to use if BOTH from VB 6 and
VC++.

The class functions correctly in VB6

In VC++ I #import the type library but when I look at the generated tli and
tlh files the guids are NOT the guids that I specified when I used the
GuidAttribute. In addition there are no definitions for the interfaces that
I created in .NET (there are definitions for the Methods and Events but
again they do not have the Despid that I assigned to them)

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
"stand__sure" <st*********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
also, lest I forget are you using a .NET COM component in a non .NET
language (I assume that you are, but more details as to where and how
you are trying to use the class would be helpful). how are you
registering the component? regsvcs? regasm? what is your command line
for doing this?

Nov 21 '05 #6
Michael Tissington wrote:
Yes, I'm creating a .NET component and trying to use if BOTH from VB 6 and
VC++.

The class functions correctly in VB6

In VC++ I #import the type library but when I look at the generated tli and
tlh files the guids are NOT the guids that I specified when I used the
GuidAttribute. In addition there are no definitions for the interfaces that
I created in .NET (there are definitions for the Methods and Events but
again they do not have the Despid that I assigned to them)


VB is doing the work behind the scenes that you must explicitly do in
c++

AGAIN, PLEASE POST CODE -- IT IS IMPOSSIBLE TO KNOW WHAT YOU ARE DOING
WITHOUT AN EXEMPLAR!

your code should (probably) look something like this (meta-code)
//
HRESULT hr;
IUnknown * punk;
hr = CoCreateInstanceEx(CLSID,punk,...);
//test hr
void ** ppobj;
hr = punk->QueryInterface(IID,ppobj);
//test hr
hr = punk->AddRef();
//

Nov 21 '05 #7
Hello,

Thanks for the code snipet .. its very similar to mine.

The BIG question is the definitions for the CLSID and IID (that I specify in
my .NET) are not being generated in my tlb file - in fact they seem to being
ignored.

---- VB.NET code. --------

Imports System
Imports System.Runtime.InteropServices

Namespace MapiForm

<GuidAttribute("20000000-3371-0000-AF8A-AFFECC1B0967"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface _Form
<DispId(10)> _
Sub ShowForm(ByVal sCN As String, ByVal sGUID As String)
<DispId(20)> _
Event ShutDownForm()
End Interface

<GuidAttribute("10000000-3371-0000-AF8A-AFFECC1B0967"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)> _
Public Interface MAPIFormEvents
Sub ShutdownForm()
End Interface

<GuidAttribute("30000000-3371-0000-AF8A-AFFECC1B0967"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(GetType(MAPIFormEvents))> _
Public Class Form
Implements _Form

Public Event ShutDownForm() Implements _Form.ShutDownForm

Private WithEvents oForm As New Form1

Public Sub ShowForm(ByVal sCN As String, ByVal sGUID As String)
Implements _Form.ShowForm
oForm.txtCON.Text = sCN
oForm.txtGUID.Text = sGUID
oForm.Show()
End Sub

Private Sub oForm_ShutDownForm() Handles oForm.ShutDownForm
RaiseEvent ShutDownForm()
End Sub

End Class
End Namespace

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

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
"stand__sure" <st*********@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Michael Tissington wrote:
Yes, I'm creating a .NET component and trying to use if BOTH from VB 6
and
VC++.

The class functions correctly in VB6

In VC++ I #import the type library but when I look at the generated tli
and
tlh files the guids are NOT the guids that I specified when I used the
GuidAttribute. In addition there are no definitions for the interfaces
that
I created in .NET (there are definitions for the Methods and Events but
again they do not have the Despid that I assigned to them)


VB is doing the work behind the scenes that you must explicitly do in
c++

AGAIN, PLEASE POST CODE -- IT IS IMPOSSIBLE TO KNOW WHAT YOU ARE DOING
WITHOUT AN EXEMPLAR!

your code should (probably) look something like this (meta-code)
//
HRESULT hr;
IUnknown * punk;
hr = CoCreateInstanceEx(CLSID,punk,...);
//test hr
void ** ppobj;
hr = punk->QueryInterface(IID,ppobj);
//test hr
hr = punk->AddRef();
//

Nov 21 '05 #8
Oh, what a boo boo - i was looking at the wrong tlb, so each time I made
some changes the one I was importing was not getting changed - anyway thanks
for your efforts.

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
"Michael Tissington" <mi*****@nospam.com> wrote in message
news:uJ**************@TK2MSFTNGP10.phx.gbl...
Hello,

Thanks for the code snipet .. its very similar to mine.

The BIG question is the definitions for the CLSID and IID (that I specify
in my .NET) are not being generated in my tlb file - in fact they seem to
being ignored.

---- VB.NET code. --------

Imports System
Imports System.Runtime.InteropServices

Namespace MapiForm

<GuidAttribute("20000000-3371-0000-AF8A-AFFECC1B0967"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sDual)> _
Public Interface _Form
<DispId(10)> _
Sub ShowForm(ByVal sCN As String, ByVal sGUID As String)
<DispId(20)> _
Event ShutDownForm()
End Interface

<GuidAttribute("10000000-3371-0000-AF8A-AFFECC1B0967"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)> _
Public Interface MAPIFormEvents
Sub ShutdownForm()
End Interface

<GuidAttribute("30000000-3371-0000-AF8A-AFFECC1B0967"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(GetType(MAPIFormEvents))> _
Public Class Form
Implements _Form

Public Event ShutDownForm() Implements _Form.ShutDownForm

Private WithEvents oForm As New Form1

Public Sub ShowForm(ByVal sCN As String, ByVal sGUID As String)
Implements _Form.ShowForm
oForm.txtCON.Text = sCN
oForm.txtGUID.Text = sGUID
oForm.Show()
End Sub

Private Sub oForm_ShutDownForm() Handles oForm.ShutDownForm
RaiseEvent ShutDownForm()
End Sub

End Class
End Namespace

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

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
"stand__sure" <st*********@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Michael Tissington wrote:
Yes, I'm creating a .NET component and trying to use if BOTH from VB 6
and
VC++.

The class functions correctly in VB6

In VC++ I #import the type library but when I look at the generated tli
and
tlh files the guids are NOT the guids that I specified when I used the
GuidAttribute. In addition there are no definitions for the interfaces
that
I created in .NET (there are definitions for the Methods and Events but
again they do not have the Despid that I assigned to them)


VB is doing the work behind the scenes that you must explicitly do in
c++

AGAIN, PLEASE POST CODE -- IT IS IMPOSSIBLE TO KNOW WHAT YOU ARE DOING
WITHOUT AN EXEMPLAR!

your code should (probably) look something like this (meta-code)
//
HRESULT hr;
IUnknown * punk;
hr = CoCreateInstanceEx(CLSID,punk,...);
//test hr
void ** ppobj;
hr = punk->QueryInterface(IID,ppobj);
//test hr
hr = punk->AddRef();
//


Nov 21 '05 #9
no problem -- that explains why I couldn't duplicate the problem ;-)

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bren | last post by:
I am having problems with custom events raised by an object, if an aspx form is the event sink - I had posted earlier about this and found I was having problems changes in the UI not reflected...
4
by: Chris | last post by:
Hi, I followed the the aricle http://support.microsoft.com/default.aspx?scid=kb;en-us;321525 and was able to execute a dts package in vb.net. I replaced all the "Console.WriteLine" with "msgbox"....
7
by: cider123 | last post by:
I'm coding a project using the following article as reference: http://www.codeproject.com/csharp/DynamicPluginManager.asp In this type of project, plugins are loaded dynamically into a Plugin...
3
by: Chris Dunaway | last post by:
Consider the following simple classes/interfaces defined below. When the derived class raises the events, on which thread is the event code run? Do I need to do anything to catch the events in my...
0
by: Alexander Czernay | last post by:
I created a VB.NET-PowerPoint-AddIn as described in the VisualStudio 2003 documentation. That works very well. The AddIn adds a new toolbar to PowerPoint if the active document is based on a...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
6
by: fshawish | last post by:
Hello all, I have a C# Class Lib that exposes a public events, methods and properties. I am referencing this ClassLib from an MFC DIalog app that is compiled with /CLR. I use gcroot<T> to...
0
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I have a very odd problem which I hope someone can help me with. I have written a very simple test program using remoting as an excercise in using a custom sink - just a simple server with a single...
0
ADezii
by: ADezii | last post by:
Not all ADO Power Users realize that there are Events, specifically related to the Connection and Recordset Objects, for which they can write code for. If one is aware of these Events, it is not...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.