How to fire events from c# activeX COM dll

November 16, 2011 at 1:05 pm Leave a comment

I want to fire an event to VB6 from an ActiveX COM dll.

I find:

http://stackoverflow.com/questions/1455577/how-can-i-make-an-activex-control-written-with-c-sharp-raise-events-in-javascrip

http://www.freelists.org/post/programmingblind/C-and-COM-creating-COM-events,9

so I start to write the code:

IVideocapEE.cs (interface to export COM method/property)

[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IVideocapEE
{
void StartCapture(string filename);

}

IVideocapEE.cs (interface to export COM events)

[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IVideocapEEevents
{
void NotifyVideoInfo(int numDroppedFrame, int numEncodedFrame);
}

VideocapEE.cs (code)

public delegate void NotifyVideoInfoDelegate(int numDroppedFrame, int numEncodedFrame);
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IVideocapEEevents))]
public class VideocapEE : IVideocapEE
{
public event NotifyVideoInfoDelegate NotifyVideoInfo;

public void StartCapture(string filename)
{

this.NotifyVideoInfo(numDropped,numEncoded);
}

}

compile it.

Use in VB6:

Dim WithEvents videocapEE As videocapEE.videocapEE

Private Sub videocapEE_NotifyVideoInfo(ByVal numDroppedFrame As Long, ByVal numEncodedFrame As Long)
MsgBox numDroppedFrame & “-” & numEncodedFrame
End Sub

It works.

Use in C#:

videocapEE = new VideocapEE();
videocapEE.NotifyVideoInfo += new NotifyVideoInfoDelegate(videocapEE_NotifyVideoInfo);

void videocapEE_NotifyVideoInfo(int numDroppedFrame, int numEncodedFrame)
{
MessageBox.Show(numDroppedFrame + “-” + numEncodedFrame);
}

It works

Entry filed under: .NET, c#, VB6. Tags: .

Spegnere un computer da remoto

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

November 2011
M T W T F S S
« Oct    
 123456
78910111213
14151617181920
21222324252627
282930  

Most Recent Posts


Follow

Get every new post delivered to your Inbox.