Results 1 to 3 of 3

Thread: ActiveX exe call back ***Resolved***

  1. #1

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    ActiveX exe call back ***Resolved***

    Hello,

    I'm trying to get an active X exe to raise an event back to a standard exe

    This is what I have so far

    Client (standard exe)
    VB Code:
    1. Option Explicit
    2. ' Reference set to AlsServer under Project references
    3. Private WithEvents myServer As AlsServer.cServer
    4.  
    5. Private Sub cmdCall_Click()
    6.     Set myServer = New AlsServer.cServer
    7. End Sub
    8.  
    9. Private Sub myServer_doCallBack()
    10.     MsgBox "Your Call has matured!!", , "Als Server"
    11. End Sub

    Server (ActiveX exe)
    VB Code:
    1. Option Explicit
    2. Event doCallBack()
    3.  
    4. Private Sub Class_Initialize()
    5.     doMyStuff
    6. End Sub
    7.  
    8. Private Sub doMyStuff()
    9.     Dim i As Long, z As Long
    10.  
    11.     z = 0
    12.     For i = 0 To 1000000
    13.         z = z + 1
    14.         If z = 999999 Then
    15.             RaiseEvent doCallBack
    16.             Exit For
    17.         End If
    18.     Next
    19. End Sub

    I've stepped through it and the raise event line is executed but doesn't get fired through to the client, does anyone know why?

    Any help will be greatly appreciated

    Regards Al
    Last edited by aconybeare; Mar 29th, 2004 at 07:16 AM.

  2. #2

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772
    I've resolved my problem and thought I should post the solution.

    I've solved it by adding a timer to my Server via API Calls (SetTimer and KillTimer).

    Why? My event never appears to fire, because instantiating the new object doesn't return until the loop is finished (the call to Initialize is syncronous).
    By firing a timer (fake asyncronous method) with a short interval, which in turn disables the timer and calls the doMyStuff method. This allows the Initialize method to return immediately, the event then fires.

    Note: I used a class and a standard module courtesy of a post by Woka Widget. If you want to use this there is a minor typo in the Class Terminate sub
    replace it with this
    VB Code:
    1. Private Sub Class_Terminate()
    2.    mobjTimer.StopTimer 'This must be run to terminate the timerobject
    3.    Set mobjTimer = Nothing
    4. End Sub

    Cheers Al

  3. #3
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    Yes, COM calls are synchronous, even cross-thread or process.
    an ending

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