Solved

ActiveX DLL

Posted on 2006-06-16
11
370 Views
Last Modified: 2010-05-18
Im creating an ActiveX dll as part of a larger project.  I have added many modules and forms from a previous program for simplicity.  

The problem is that I need the dll to raise an event when one of the forms raises an event and im not sure how to do that.
0
Comment
Question by:justchat_1
  • 6
  • 3
  • 2
11 Comments
 
LVL 14

Expert Comment

by:Shiju Sasidharan
Comment Utility
>> I have added many modules and forms from a previous program for simplicity

u added these files to dll project ?

>>I need the dll to raise an event when one of the forms raises an event

pls explain a little bit more
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
yes the forms have some controls that i need to use.  

Basically a form is parsing information and the dll needs to raise an event when certain information is parsed.  However im not sure how the form can raise the event on the dlls class module.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
Usually when you include forms inside of a DLL, you have to interact with it from the instantiated class, and so your class usually declares a form variable to work with, e.g.,


Dim WithEvents myForm As Form1

Public Sub ShowForm()
    If myForm Is Nothing Then Set myForm = New Form1
    myForm.Show
End Sub


Now, your form will raise events to your class module which you can, in turn, then raise an event to the client calling your DLL, e.g.,


Event FormClicked()


Private Sub myForm_Click()
    RaiseEvent FormClicked
End Sub
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
Comment Utility
Class1.cls
'------------------------------------------------
Event YourEvent1()
Event YourEvent2()

Public Function MyFunction1()
   
    RaiseEvent YourEvent1

End Function

Public Function MyFunction2()
   
    RaiseEvent YourEvent2

End Function
'------------------------------------------------

Form1.frm
'------------------------------------------------
Dim WithEvents obj As Class1

Private Sub Command1_Click()
Dim oTest As New Class1
    Set obj = oTest
    obj.MyFunction1
    obj.MyFunction2
End Sub

Private Sub obj_YourEvent1()
    MsgBox "Event Raised: YourEvent1"
End Sub

Private Sub obj_YourEvent2()
    MsgBox "Event Raised: YourEvent2"
End Sub
'------------------------------------------------
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
azrasound:
I tried that already the problem is the form interfaces with other modules in the project.  If its an object the modules are unable to pass information back to the form.

shijusn:
thought about that too... the problem is that the class is the main class for the dll and it needs to be instantiated by another program that uses the dll...
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 28

Accepted Solution

by:
AzraSound earned 500 total points
Comment Utility
Well another option is to create a public variable for the form in a bas module and set your class form object to that variable, e.g.,

'in a bas module
Public GlobalForm As New Form1

'inside class module
Private WithEvents myForm As Form1

Private Sub Class_Initialize()
    Set myForm = GlobalForm
End Sub


Normally you would approach this from a more structured method, but since it sounds like these existing forms/modules are all intertwined as it is, this should be a simple fix.
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
looked good in a test program but im getting an "Object does not source automation events" when i try to compile in the real thing.

At line:
Private WithEvents myform As frmIMSniff
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
nevermind...I created a seperate public event and that solved it.

I just need to finish testing and then I will award points.
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
still having trouble:
when the modules reference the form can they use its name or do they need to use the object name?
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
The modules must reference the public/global variable of the form you created.
0
 
LVL 9

Author Comment

by:justchat_1
Comment Utility
Great solution...I was able to finish the dll
thanks for all the help
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now