Solved

ActiveX DLL

Posted on 2006-06-16
11
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro which automatically sends attachment to Outlook 14 82
VB 6.0 printer how to align 6 71
Added a column screws up code 5 69
VB 6 error 5 in windows 10 but not in XP 7 67
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 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