Threads - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Threads

Archer282Archer282 Posts: 243Member
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 ?

Comments

  • GenjuroGenjuro Posts: 913Member
    : 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:

    [code]
    Declare CreateThread ... (...., ...., ThreadParm as Any)
    Declare CreateThread ... (...., ...., ByVal ThreadParm as Long)
    [/code]

    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.
Sign In or Register to comment.