Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Problem with RaiseEvent/WithEvents in VB6 ActiveX dll

Posted on 2009-02-12
12
Medium Priority
?
3,730 Views
Last Modified: 2013-12-20
I am having issues either raising an event or identifying the raised event in VB6.  I really don't know why this isn't working.

I have a Project Group set up, with an exe project calling a function in the dll.  It passes all of the information to the dll and processes correctly straight up to and including the RaiseEvent line.  I have a WithEvents in the Exe that should display a messagebox when the event is captured.  I'm not sure whether the RaiseEvent isn't working or whether the WithEvents isn't working.  I believe the issue is with the raised event because another customer can't catch the event either with their code.  Is there something I'm missing in the code?  Is there an easier way to troubleshoot this?

Here is the snippet of code in the Exe that passes a request to the ActiveX dll, which works:

Private Sub Command1_Click()
    Dim obj As clsTestDirect
    Set obj = New clsTestDirect
   
    Result = obj.TestRequest(arrRequest, strFlags)
End Sub

Here is the code inside the class in the ActiveX Dll that is being called and should raise the event:


Public Event Navigate(ScreenID, arrData)



Function TestRequest(arrRequest, strFlags)

   ' This Function is getting called
   ' The code does a bunch of validating, logging,
   ' and processing and eventually proceeds to the
   ' RaiseEvent line

   ' ..... [code] .....

   RaiseEvent Navigate(PageID, arrData)

End Function



Here is the code inside the Exe to try to handle the event, which is never executed:


Private WithEvents GetProgress As clsTestDirect

Private Sub Form_Load()
    Set GetProgress = New clsTestDirect
End Sub

Private Sub GetProgress_Navigate(PageID, arrData)
    MsgBox "PageID:" & PageID
End Sub



I also tried putting the WithEvent stuff in a class inside the Exe

Private WithEvents GetProgress As clsTestDirect

Private Sub Class_Initialize()
    Set GetProgress = New clsTestDirect
End Sub

Private Sub GetProgress_Navigate(PageID, arrData)
    MsgBox "PageID:" & PageID
End Sub
0
Comment
Question by:Random_Dent
  • 6
  • 3
  • 3
12 Comments
 
LVL 22

Expert Comment

by:danaseaman
ID: 23625277
Try adding this code to ActiveX Dll.

MsgBox "Before RaiseEvent Navigate"
RaiseEvent Navigate(PageID, arrData)
MsgBox "After RaiseEvent Navigate"

What is Instancing Property of your ActiveX Class.
5-Multiuse?
0
 

Author Comment

by:Random_Dent
ID: 23625310
Both MessageBoxes display fine when I test.

The Instancing is indeed set to 5 - MultiUse
0
 
LVL 22

Expert Comment

by:danaseaman
ID: 23625460
Do you have On Error Resume Next or similar in Function TestRequest?
Perhaps you could add an Error handler to see if there is an error with PageID or arrData.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Random_Dent
ID: 23625565
There is no Resume Next on.  If I were to change the "Navigate" event name to "Navigates", it does error.  PageID is a string that I am setting, and arrData is a valid name/value pair array that I am building right before I call the RaiseEvent.  To verify, I implemented the following code:

MsgBox "Before Raise:" & arrData(0) & PageID
            RaiseEvent Navigate(PageID, arrData)
MsgBox "After Raise"

The messagebox properly shows my first name/value pair ("RequestDateTime") and the string I am passing in PageID.

I've never used events prior to this.  For all I know the event could be raising correctly, but I'm not catching it properly using the With Events code...
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 2000 total points
ID: 23632116
you use the local copu of clsTestDirect, you should use the global one

Private Sub Command1_Click()
    GetProgress.TestRequest "1", "2"
End Sub
0
 

Author Comment

by:Random_Dent
ID: 23686160
EDDYKT,

That worked but I'm not quite sure it is what I need.  The problem is that user 1 (me) makes a call to the dll with to raise an event.  A 3rd party program is supposed to be listening for that event to be raised and execute a process when the raised event is detected (with the data provided in the raised event).  The 3rd party program isn't seeing the event being raised.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 23698187
who make that dll?
you?

you have to post some code at least.

I have no clue why it's not working.
0
 

Author Comment

by:Random_Dent
ID: 23706671
I am writing the DLL.  A 3rd party program will call the registered dll's "TestRequest" function and pass two parameters in, an array with data and a flags string to allow testing and logging functions.  The dll will do a bunch of code and will culminate with raising the "Navigate" public event.  A different 3rd party program should be listening for that flagged event to process the data array and screen information to display the appropriate data in a LOB application.  The only way I can see the raised event is if my test application is both firing the TestRequest and listening for the response (via your helpful suggestion of this:

Private Sub Command1_Click()
    GetProgress.TestRequest "1", "2"
End Sub

It does properly raise the event, but it doesn't seem to be doing it so another party can monitor for it.

Thank you very much for your help so far.  It seems like I'm so close...

Here is a cleaned version of all of the code (with the exception of the logging function I call):


Public Event Navigate(ScreenID, arrData)

Public Function TestRequest(arrRequest, strFlags)

    Result = lib_FileLogEvent(g_ShowMessages, g_LogMessages, "TestRequest", "Initializing TestRequest")
   
    If Not IsArray(arrPFFWScreenRequest) Then
        Result = lib_FileLogEvent(g_ShowMessages, g_LogMessages, "TestRequest", "Request is not an array")
        TestRequest = "-2" ' Invalid Request Array
        Exit Function
    End If
       
    Dim arrCount, arrParameter
    For arrCount = 0 To UBound((arrRequest)
        arrParameter = Split((arrRequest(arrCount), "==")
        If UBound(arrParameter) = 1 Then
            Select Case arrParameter(0)
               Case "Order Number"
                    strOrderNumber = Trim(arrParameter(1))
               Case "Customer Name"
                    strCustomerName = Trim(arrParameter(1))
               Case "Customer Number"
                    strCustomerNumber = Trim(arrParameter(1))              
               Case "LOB App Screen"
                    strScreenID = Trim(arrParameter(1))              
            End Select
        End If
    Next

    If Len(strScreenID) = 0 Then
        Result = lib_FileLogEvent(g_ShowMessages, g_LogMessages, "TestRequest", "LOB Screen ID Not Specified")
        TestRequest = "-4" ' Missing Screen ID
        Exit Function
    End If
   
    Select Case strScreenID
        Case "CustomerOrder"
            Dim strData, arrData
            strData = "RequestDateTime==" & Now() & "||" & _
                        "OrderNumber ==" & strOrderNumber & "||" & _
                        "CustomerNumber==" & strCustomerNumber & "||" & _
                        "CustomerName==" & strCustomerName
            arrData = Split(strData, "||")
            Result = lib_FileLogEvent(g_ShowMessages, g_LogMessages, "TestRequest", "Before Raise Event")
            RaiseEvent Navigate(strScreenID, arrData)
            Result = lib_FileLogEvent(g_ShowMessages, g_LogMessages, "TestRequest", "Event Raised")
            TestRequest = "0"
        Case Else
            Result = lib_FileLogEvent(g_ShowMessages, g_LogMessages, "TestRequest", "Screen ID Not Implemented")
            TestRequest= "-5" ' Screen ID not Implemented
            Exit Function
    End Select

End Function

           
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 23710133
can you see it if you write a simple vb application and trap for the Navigate event?

If you do, then it's 3 rd party app's problem

also if it goes into this checking, then no event is fired back. Are you sure it is not inside the if check case?

If Len(strScreenID) = 0 Then
        Result = lib_FileLogEvent(g_ShowMessages, g_LogMessages, "TestRequest", "LOB Screen ID Not Specified")
        TestRequest = "-4" ' Missing Screen ID
        Exit Function
    End If

Also


Case Else
            Result = lib_FileLogEvent(g_ShowMessages, g_LogMessages, "TestRequest", "Screen ID Not Implemented")
            TestRequest= "-5" ' Screen ID not Implemented
            Exit Function

0
 
LVL 22

Expert Comment

by:danaseaman
ID: 23711348
Each instance of the class (i.e. Set GetProgress = New clsTestDirect) is independant so when the 3rd party creates his instance to the DLL class it has no relation to whatever you are doing with your local instance. Calling GetProgress.TestRequest will raise event on your machine but will have no effect on the instance the 3rd party is running and events will never be seen.

0
 

Author Comment

by:Random_Dent
ID: 23711648
If each instance of the class is truly independant, is there a way to broadcast an event (or other method of passing the data) within the computer session?

To really muck things up, this dll will reside on a terminal server.  There will be multiple Application 1s connecting to the same dll to raise an event (or pass data in some way) to multiple Application 2s.  We need the data from App1 to be shared through the dll only to the App2 that is under the same user session.
0
 

Accepted Solution

by:
Random_Dent earned 0 total points
ID: 23774030
OK.  I found a way to make this work.

I had to create the ActiveX as an executable instead of a dll.  It is set to run as a COM Server.  I also had to make the project single threaded.  Once I did these changes, it worked.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

577 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