Announcement

Collapse
No announcement yet.

PB Callingback > VB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PB Callingback > VB

    I remember many discussions about having a dll function callback within
    VB, and I remember the outcome to always cause a GPF.

    Has anyone worked a solution? This is what I'm trying to do.

    Make .DLL in PowerBasic
    Make .OCX that wrappes the .DLL in Visual Basic and the .DLL sends callbacks to the .OCX

    I could simply make a type library and call that within my .OCX but that
    somewhat seems less productive.


    Any ideas?

    Thanks,
    Greg

    ------------------
    -Greg
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

  • #2
    Greg,

    I remember many discussions about having a dll function callback within
    VB, and I remember the outcome to always cause a GPF.
    This is, for the most part, false. As long as the DLL calls back to VB on the same thread that VB called the DLL on, you'll have no problems. If your DLL spawns threads and calls back on a different thread, you're sunk.

    To solve your proposed problem:

    1) Make the DLL w/ exported functions in PB (I'm assuming that one of these functions will take a function pointer to the callback function).
    2) Make a BAS file in VB w/ a function that matches the signature of the defined callback function.
    3) When you want to set up the callback in VB, pass in the function pointer to your exported DLL function using the AddressOf keyword.

    You're done. Note that you cannot call back to a class method, which means that the callback function must have a reference to the object to call a well-known method on the object.

    Not to toot my own horn, but check out my article on PB's web site:

    http://www.powerbasic.com/support/te...threading3.asp

    Note that there is a hard-coded path in one of the Declares when you download the code, but the rest should work just fine.

    BTW, there is a way to call a class method on a callback. Buy Matt Curland's "Advanced Visual Basic 6" book to find out .

    Regards,

    Jason Bock

    ------------------

    Comment


    • #3
      Thank you Jason

      ------------------
      -Greg
      -Greg
      [email protected]
      MCP,MCSA,MCSE,MCSD

      Comment

      Working...
      X