Results 1 to 8 of 8

Thread: ActiveX DLL - Event Handler problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4

    Question ActiveX DLL - Event Handler problem

    Hi. This is the first time that I post a message in this forum. Hope someone could give me a helping hand on this:


    I have wrote a ActiveX DLL using VB6. And then I wrote a client program which use this ActiveX DLL

    Here is the sample code for the client program

    ==========================
    Option Explicit

    Private WithEvents aa As BossCheckerOject.IQueryCmd
    Private WithEvents bb As BossCheckerOject.IQueryCmd

    Private Sub aa_DataArrival()
    MsgBox "aaaa"
    End Sub

    Private Sub bb_DataArrival()
    MsgBox "bbbbb"
    End Sub

    Private Sub Command1_Click()
    Set aa = New BossCheckerOject.QueryCmd
    Set bb = New BossCheckerOject.QueryCmd

    aa.strBossIp = "127.0.0.1"
    aa.strBossPort = "10000"
    aa.m_intLocaleId = 2052
    aa.SetRequestMsg "20050", "13922200525~6006~1"

    aa.SendQuery
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    Set aa = Nothing
    Set bb = Nothing

    End Sub
    ===================

    The object I wrote "BossCheckerOject.QueryCmd" would fire a DataArrival event. I used the "aa" object to send a query out. I expected that I should received an event from the "aa" object. But then the event handler of "bb" handle the event.

    Do you have any idea of what's going on?

    Chris

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Probably a bug in your dll. I would suspect the new instance of the object has obsconded the control from the first instance.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4

    Unhappy

    Thanks for your reply, brucevde.

    I am not so sure if there is any bug in my original ActiveX DLL.

    If you don't mind, could you give me some comments on my test program. I made a group project, which contains a dummy ActiveX DLL and a container program.

    I created 3 objects in the container programs, and implements 3 event handlers in this container program. I only called the first object function once. But then all three event handlers got the events.... is there anything that I made it wrong?

    Chris
    Attached Files Attached Files

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    It is a bug in your Dll.

    All instances of your class are using the same Form and thus the same timer. When the Timer_Timer event fires, all three class instances get the event and in turn all three raise their Data_Arrival events.

    Create a new instance of the Form for each class - or add a new Timer to the form when the class gets initialized.

    VB Code:
    1. Private Sub Class_Initialize()
    2.     Dim objForm As Form
    3.     Set objForm = New Form1
    4.     Load objForm
    5.     Set myTimer = objForm.Timer1
    6. End Sub
    7. Private Sub Class_Terminate()
    8.     Set myTimer = Nothing
    9. End Sub

    Also instead of using Form1.Timer.Enabled = False use myTimer.Enabled = False

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4

    Smile

    hi brucevde, I gotta say thank you again.
    It fixed my problem now. Thank you so much.

    What I was thinking is that the Active DLL is using the Apartment threading model, and so I expected that every instance of class is residing in its own apartment... but seems like the form is not in the apartment (which I thought it was)... Hehehe..

    I really appreaciated that you pin-point my error.

    Chris

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Apartment threading applies to two different programs using the same dll. Each program gets their own version of the dll and thus the Form.

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4

    Lightbulb

    So, what you mean is:

    for the sample program that I attached above, there is only thread (the container program), which has ONE apartment and all three objects or instances that I created are all resided in this apartment. Am I right?

    And there will be another apartment only when there is another client progam (thread) that uses the same dll?


    Chris

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Yes. That is how I understand it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width