Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18011
Number of posts: 55384

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Threads Posted by Archer282 on 27 Apr 2005 at 7:49 PM
I am having some trouble creating threads in VB, i have used them in C++ many, many times,

i believe the problem is that the callback has a parameter that is LPVOID and VB has no equivilant to this, because i can get CreateThread() function to succeed, but after its has been called the program crashes and causes a debug error

any ideas ?
Report
Re: Threads Posted by Genjuro on 28 Apr 2005 at 2:48 AM
: I am having some trouble creating threads in VB, i have used them in C++ many, many times,
:
: i believe the problem is that the callback has a parameter that is LPVOID and VB has no equivilant to this, because i can get CreateThread() function to succeed, but after its has been called the program crashes and causes a debug error
:
: any ideas ?
:

One, but quite a clear one.
Don't multithread in VB6; if you can, prefer DoEvents (which is a kind of PeekMessage wrapper), Shell (it's asynchronous, and any process has a primary thread anyway) or CreateProcess, or Timers (instead of a background thread waiting).

This said, if you really need so, then create a function with a proper prototype, then use the "as any" or "as long" type specifier:

Declare CreateThread ... (...., ...., ThreadParm as Any)
Declare CreateThread ... (...., ...., ByVal ThreadParm as Long)


In case you declare a long, you'd better send in a zero (essentially a NULL pointer). Not that the API messes with that param anyway.

I'd also add a few more pointers:
- beware the VB6 runtime: it *can* crash, when shutting down a multithreaded program (not at random, though), although threads work fine.
- Don't use any additional thread tied to the user interface, as most UI properties/methods have no multithreading support and will crash at random.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.