Results 1 to 6 of 6

Thread: C++ DLL calling callback function in VB

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    C++ DLL calling callback function in VB

    is it possible for VB to send a function pointer to a C++ DLL and have the DLL call that function?

    the VB function is in a standard module and i used this typedef in C++

    typedef void (__stdcall *FUNC_PTR)(long);

    and i suppose it passes the value right but when i call the function like this

    (*callback)(i);

    where i have this in the DLL function arguement list

    FUNC_PTR callback

    is gives one of those illegal operation errors from windows
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Make sure the VB function is declared as
    Public Sub SomeFunc(ByVal param As Long)
    '...
    End Sub

    and you pass it using AdressOf
    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

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    it still gives an error
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  4. #4
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    Toronto, Ontario
    Posts
    280
    It is very difficult to do the programming in VB (i.e. setting the AddressOf parameters properly, etc.). Make sure that it is correct.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    setting addressof parameters? isn't there only one parameter? and thats to a function i wrote in a module
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The callback worked for me by using your typedef and writing:
    VB Code:
    1. Declare Function MyFunc Lib "mylib.dll" (ByVal addrCallback As Long)
    2.  
    3. Public Sub CB(ByVal l As Long)
    4.   Debug.print Format(l)
    5. End Sub
    6.  
    7. ' In a function
    8. MyFunc(AddressOf(CB))
    Code:
    typedef void (__stdcall *CBFUNC)(long);
    
    void __stdcall MyFunc(CBFUNC f)
    {
      f(5);
    }
    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.

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