?
Solved

Class Event Lifetime

Posted on 2003-02-26
3
Medium Priority
?
130 Views
Last Modified: 2010-04-07
I have a third party COM product which triggers events and works fine in VBA.
Porting to VB6 I have difficulty because the old problem of asynchronous execution means the event class terminates before the Class events I am trying to trap have triggered.
ie xyzCompleteEvent never traps because the sub calling the process completes and terminates the class before xyz even gets underway.
If I add a timing loop, all is well but I can't live with that.
Register_event_Handler is being called from the same sub that calls the process I am trying to trap.
I remember reading somewhere of the ability to make the class global or some such.
Any help appreciated.
   
0
Comment
Question by:IanDB
[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
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
webJose earned 150 total points
ID: 8030274
Ok, sounds like you have a COM server that provides an object capable of asynchronous processing, probably accomplished by multithreading.  What you want is start the process and do not leave the starting procedure until the task being done in the worker thread (I assume) is done, which is signaled by the xyzCompleteEvent.  Am I correct?  Well, if so, I don't see much gain in the component using multithreading, but a code like the one below should do the trick.

Private Const INFINITE As Long = &HFFFFFFFF

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" (byval lpEventAttributes As long, ByVal bManualReset As Long, ByVal bInitialState As Long, ByVal lpName As String) As Long
Private Declare Function SetEvent Lib "kernel32" (ByVal hEvent As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

private hCompleteEvent as long

Private Sub SomeObject_xyzCompleteEvent()
    setevent hcompleteevent
end sub

private sub StartTheWork()
    hcompleteevent = createevent(0, 0, 0, "_MyCompleteEvent_")
    someobject.startjob
    waitforsingleobject hcompleteevent, infinite
    closehandle hcompleteevent
    'The rest of code here, like Unload Me or sumtin
end sub

When you call StartTheWork(), the object will start working, then you wait using the WaitForSingleObject API function until the _MyCompleteEvent_ event gets signaled in the xyzCompleteEvent.  Once signaled, the code in StartTheWork() resumes execution.
0
 

Expert Comment

by:CleanupPing
ID: 8901060
IanDB:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 7

Expert Comment

by:webJose
ID: 8903367
Again, I think my answer is correct and I should get the points awarded.
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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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