tags:

views:

266

answers:

2

I need set events on a class library and catch them in an form.

For example, I run a sub in the dll and I need "receive" the event that the sub in the class is running.

The dll is creted by me in vb, but i don't know how raise events on it to be catched in the form.

Please an example.

A: 

When you talk about a 'native' unmanaged DLL there is not a direct way to achieve this. You must declare a method signature that should be used for this event. Then you must need to provide a way to put a pointer to a method matching this signature into the DLL (provide a callback method). From the DLL you then can call this method when necessary (instead of triggering the event).

Sebastian P.R. Gingter
+2  A: 

Code in the dll

 Public Event MySpecialEvent ()

 Private Sub Test 
   RaiseEvent MySpecialEvent
 End Sub

Code in the form

 Private _MyDll as MyDLL

 Public Sub Main
   _MyDLL = New MyDLL
   AddHandler _MyDLL.MySpecialEvent, AddressOf MySpecialEventHandler
 End Sub

 Private Sub MySpecialEventHandler
   'Put your code here to act upon the handled event
 End Sub

You'll also need to remove the event handler at some point in the form's life with

RemoveHandler _MyDLL.MySpecialEvent, AddressOf MySpecialEventHandler
Walter
Thank you a lot Walter!
Sein Kraft
You can also include a parameter in the event if you need to pass data to the listening codePublic Event MySpecialEvent(S as String)
Walter