Results 1 to 2 of 2

Thread: Usefullness of AddressOf operator

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    2

    Usefullness of AddressOf operator

    I recently asked a previous question in a seperate Thread, namely about calling back VB functions from C++ DLLS which run in seperate Threads. MerrionComputin answered the question (thanks!), but it raised a further, more general, question in my mind:

    As I understand it the return value of the AddressOf operator CANNOT be used in the following circumstances:

    1) By VB in any thread (as it cannot use function pointers to call functions).
    2) By a DLL (or equivalent) which runs in a seperate Thread to the main VB app.

    So my question is simply this: What use is it? If a DLL is going to use the AddressOf operator to call back a VB function, yet this DLL function runs in the same Thread as the main app, why not just wait for the DLL function to return normally? Usually in programming, call backs are used to deal with events which are unpredictable, and as such we do not wish to bother "waiting" for them, but would rather they notify us when something happens.
    I can't think of a single circumstance where a user would Need a VB function to call a C++ function to call a VB function all in the same Threads calling stack! Surely instead the user would just use a VB function to call a C++ function, which would return, and then the VB app would call the final VB function itself.

    Have I mis-understood?

  2. #2
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    By far the most powerful use of the AddressOf operator is in windows subclassing - passing the address of your WNDPROC to override the def window proc.
    However it is also useful where a call may return an arbitrary number of values - such as EnumWindows which calls the callback once for each window found.

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

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