c++ Function Pointer in VB


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: c++ Function Pointer in VB

  1. #1
    Join Date
    Oct 2005
    Posts
    6

    Question c++ Function Pointer in VB

    I rewrite it from c++ forum, becouse i think some one in this forum will give solution,

    i have a DLL function in VC++ like this

    void CDLLCPPTest::CallerFunction(void (*aFunction)());

    and i declared it from vb like,

    Declare Sub CallerFunction Lib "C:\Choirul\Project\callbacks\DLLCPPTest\Debug\DLLC PPTest.dll" (ByRef funct)

    then in VB6 i have fungtion,

    public sub callMe()
    end sub

    how to pass a VB6 function (callMe) to it(CallerFunction). i have tried used "addressof" but it terminated with error.

  2. #2
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    try to declare the function like:

    Declare Sub ..... (byval funct as Long)

    (not byref, because using addressof you pass a value) and call it like

    CallerFunction addressof callMe

    callMe must be in a bas (standard) module.

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  3. #3
    Join Date
    Oct 2005
    Posts
    6
    i have tried but it give a error message "Bad DLL calling convention". you know the c++ function is pass a void function pointer
    void CDLLCPPTest::CallerFunction(void (*aFunction)());
    so any another way to pass a VB function ?

  4. #4
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    It looks like your method is in a class (CDLLCPPTest), sorry I missed that. You can't do that.

    There are two ways to interacts between VB and C, one is to write a standard API library, where methods are exposed by declaring them by

    __declspec(dllexport)

    but they cannot be in a class. The other is to write a COM dll, a little more complex (the library must be registered) but more VB 'friendly'. Methods of a COM library do not need declaration, you just need a reference of it in the VB project, then you create instances of the library public classes with the New operator, and call public methods of that class.

    Well, this is in a nutshell.

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  5. #5
    Join Date
    Oct 2005
    Posts
    6
    Thanks very much mstraf, you are master. it's work if i declared like what you said,

    extern DLLCPPTEST_API void __stdcall CallerFunction(void (*aFunction)());

    but why i cant do the same way in this code by "addressof",

    MIA_RETURN_CODE MSCMIA_API __cdecl MIA_RegisterCallback(void *aFunction, MIA_USERDATA aUserData);

    MSCMIA_API is a fix DLL that i cant change it.

  6. #6
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    sorry I do not understand your last question
    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

Similar Threads

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 10:09 AM
  2. pass C++ function pointer in VB
    By hafazah in forum C++
    Replies: 1
    Last Post: 10-11-2005, 08:50 AM
  3. Thanks!!! Re: call c/c++ function from VB
    By Chris in forum VB Classic
    Replies: 1
    Last Post: 08-08-2002, 12:02 PM
  4. Reading data from a pointer to string in VB 6
    By Ouaes Jamali in forum VB Classic
    Replies: 0
    Last Post: 08-21-2000, 06:08 PM
  5. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center