Sunday, July 12, 2009

How do I make the Visual Basic 6 GUI remain responsive during a DLL call?

My employer will not spend the money to get me Visual Basic.Net. I am stuck using Visual Basic 6. I am pretty good with programming embedded C, but have no time to learn to program in Visual C++.








So I am doing some advanced programming, in VB6, using several DLL’s. I have 4 DLL’s, and two of them use callbacks. The problem is the GUI will appear to freeze during a DLL call. When the DLL returns, everything returns to normal. I have partly cured the problem by refreshing the forms, and calling DoEvents during callbacks. This works fine, unless the user clicks on a control button. The button event will not fire until the DLL returns, or during the callback. This makes the app very sluggish.





I have tried various methods of multi-tasking. Several of them work, in the IDE, but crash at runtime. The app will crash with an exception when one of the DLL’s executes a callback.

How do I make the Visual Basic 6 GUI remain responsive during a DLL call?
Not easy to follow everything you did, but I'd try something like this:


Make a worker thread that does the DLL calls. Keep or drop the callbacks. I guess you are using callbacks to signalize progress, if so you will have trouble - VB6 is too slow for that. If you're using callbacks for other things, it may be worth reconsidering them, I don't have good experience with callbacks in VB6.


The worker thread should send simple Windows Messages to signalize progress. Even in VB6 you can post/send Windows Messages.





The User Interface thread is the main VB thread, no modifications needed. To Windows Messages are trapped by subclassing some (main) window - good source code can be found for that on Internet. This read will be responsive all the time, and no risk of crashing.


No comments:

Post a Comment