Solved

ActiveX DLL

Posted on 2006-06-16
11
373 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
ID: 16926954
>> 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
ID: 16927922
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
ID: 16936351
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 16936394
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
ID: 16937237
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
 
LVL 28

Accepted Solution

by:
AzraSound earned 500 total points
ID: 16937995
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
ID: 16938805
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
ID: 16938812
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
ID: 16938902
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
ID: 16942431
The modules must reference the public/global variable of the form you created.
0
 
LVL 9

Author Comment

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 211
Updates not working for MS Windows 7 12 181
Saving history changes to sub form 4 48
vb6 connector to mongodb 2 121
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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