Results 1 to 4 of 4

Thread: How Can I Define C functions to use VB Callback

  1. #1

    Thread Starter
    Lively Member Ceri's Avatar
    Join Date
    Sep 2000
    Posts
    72

    How Can I Define C functions to use VB Callback

    How do i define functions in C so that vb is able to pass through a function address (using the AddressOf function in VB6) adn then what whould be the code in C to call that function address

    thanks in advance

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    a VB funciton that should be called must be declared in the main module:
    Code:
    public function MyCallback(i as Long, j as Long) as Long
    can be passed to a function in C as follows:
    PHP Code:
    // define the type of the function
    typedef long (__stdcallVBCB)(longlong);

    // then the function that receives the address:
    void __stdcall Func(long iVBCB pVbFunc)
    {
      
    // call the function
      
    long j pVbFunc(ii+1);

    and the remaining Vb code:
    Code:
    private declare sub Func lib "thedll" (i as long, pFunc as long)
    
    'call it
    Func 34 AddressOf(MyCallback)
    'maybe you need to add "" to the function name
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    MISTAKE!!!
    Code:
    public function MyCallback(i as Long, j as Long) as Long
    'needs to be
    public function MyCallback(byval i as Long, byval j as Long) as Long
    or you end up with vb.exe producing an access violation

    Code:
    private declare sub Func lib "thedll" (i as long, pFunc as long)
    'needs to be
    private declare sub Func lib "thedll" (byval i as long, byval pFunc as long)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Lively Member Ceri's Avatar
    Join Date
    Sep 2000
    Posts
    72

    Thanks....

    Thanks for that. It works great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width