About CALLBACK function 
Author Message
 About CALLBACK function

Hi,all:
 I see these from
< http://www.*-*-*.com/
5&Setting=A9999F0001>:
Usually MSDN provides a template for CALLBACK functions. For example: see
the function 'EnumFontFamilies()'. One of the parameters described as:

int CALLBACK EnumFontFamProc(
  ENUMLOGFONT *lpelf,    // logical-font data
  NEWTEXTMETRIC *lpntm,  // physical-font data
  DWORD FontType,        // type of font
  LPARAM lParam          // application-defined data
);

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

You need to replace just a name of that one - or leave it as is and write
your own body of that function:

int CALLBACK MyFontEnumerator (
  ENUMLOGFONT *lpelf,    // logical-font data
  NEWTEXTMETRIC *lpntm,  // physical-font data
  DWORD FontType,        // type of font
  LPARAM lParam          // application-defined data
) {
  // your code here...

Quote:
}

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

...and then pass 'MyFontEnumerator' as the parameter into function which
requested it:

EnumFontFamilies (...,  ... MyFontEnumerator);

---------------------------------------------------------------------------
Then,Can the parameters change in the MyFontEnumerator function?When calls
EnumFontFamilies function,it is how to pass on values to the
MyFontEnumerator function's parameters?  
 Appreciate for any messages.



Sun, 27 Feb 2005 17:12:40 GMT  
 About CALLBACK function

Quote:

> Then,Can the parameters change in the MyFontEnumerator function?When calls
> EnumFontFamilies function,it is how to pass on values to the
> MyFontEnumerator function's parameters?

If I understand your question, the answer is 'no'.

--
Jeff Partch [MVP]



Sun, 27 Feb 2005 19:39:38 GMT  
 About CALLBACK function


Quote:


>> Then,Can the parameters change in the MyFontEnumerator function?When
>> calls EnumFontFamilies function,it is how to pass on values to the
>> MyFontEnumerator function's parameters?

> If I understand your question, the answer is 'no'.

> --
> Jeff Partch [MVP]

Hi,Jeff Partch
  I mean if can define a CALLBACK function by myself.If can,what does I
notice? Anyway,you can introduce it or offer some good articles.Thanks.


Sun, 27 Feb 2005 20:15:47 GMT  
 About CALLBACK function

Quote:





> >> Then,Can the parameters change in the MyFontEnumerator function?When
> >> calls EnumFontFamilies function,it is how to pass on values to the
> >> MyFontEnumerator function's parameters?

> > If I understand your question, the answer is 'no'.

> > --
> > Jeff Partch [MVP]

> Hi,Jeff Partch
>   I mean if can define a CALLBACK function by myself.If can,what does I
> notice? Anyway,you can introduce it or offer some good articles.Thanks.

You can define 'a' CALLBACK yourself for your own function that calls the CALLBACK, but you can not
redefine 'the' CALLBACK function as it is understood by an existing function who's implementation
you don't control. I'm not aware of any articles on this subject, sorry.

--
Jeff Partch [MVP]



Sun, 27 Feb 2005 20:54:44 GMT  
 About CALLBACK function

Quote:

>  I see these from
> <http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=112&MsgID=...
> 5&Setting=A9999F0001>:
> Usually MSDN provides a template for CALLBACK functions. For example: see
> the function 'EnumFontFamilies()'. One of the parameters described as:

> int CALLBACK EnumFontFamProc(
>   ENUMLOGFONT *lpelf,    // logical-font data
>   NEWTEXTMETRIC *lpntm,  // physical-font data
>   DWORD FontType,        // type of font
>   LPARAM lParam          // application-defined data
> );

That's the signature of the callback function that EnumFontFamilies
will try to call.  If you don't provide a function that is compatible
with that signature, your program will crash horribly.

Quote:
> ...and then pass 'MyFontEnumerator' as the parameter into function which
> requested it:

> EnumFontFamilies (...,  ... MyFontEnumerator);

> ---------------------------------------------------------------------------
> Then,Can the parameters change in the MyFontEnumerator function?

Not sure what you mean.  EnumFontFamilies will call MyFontEnumerator
through a function pointer with the signature above.  It will call it
with those parameters specified.  If you want to call them something
else (types, not names, are significant), you can, or if you want to
interpret them as something else that's compatible, you can, though
I can't think of a good reason to do the latter.

Quote:
> When calls
> EnumFontFamilies function,it is how to pass on values to the
> MyFontEnumerator function's parameters?

EnumFontFamilies will provide the parameter values.  You have no
control over this.


Sun, 27 Feb 2005 21:41:28 GMT  
 About CALLBACK function


Quote:

>>  I see these from
>> <http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=112&MsgID=
>> 13743 5&Setting=A9999F0001>:
>> Usually MSDN provides a template for CALLBACK functions. For example:
>> see the function 'EnumFontFamilies()'. One of the parameters
>> described as:

>> int CALLBACK EnumFontFamProc(
>>   ENUMLOGFONT *lpelf,    // logical-font data
>>   NEWTEXTMETRIC *lpntm,  // physical-font data
>>   DWORD FontType,        // type of font
>>   LPARAM lParam          // application-defined data
>> );

> That's the signature of the callback function that EnumFontFamilies
> will try to call.  If you don't provide a function that is compatible
> with that signature, your program will crash horribly.

>> ...and then pass 'MyFontEnumerator' as the parameter into function
>> which requested it:

>> EnumFontFamilies (...,  ... MyFontEnumerator);

>> ----------------------------------------------------------------------
>> ----- Then,Can the parameters change in the MyFontEnumerator
>> function?

> Not sure what you mean.  EnumFontFamilies will call MyFontEnumerator
> through a function pointer with the signature above.  It will call it
> with those parameters specified.  If you want to call them something
> else (types, not names, are significant), you can, or if you want to
> interpret them as something else that's compatible, you can, though
> I can't think of a good reason to do the latter.

>> When calls
>> EnumFontFamilies function,it is how to pass on values to the
>> MyFontEnumerator function's parameters?

> EnumFontFamilies will provide the parameter values.  You have no
> control over this.

Hi,
 Since MS has defined the int CALLBACK EnumFontFamProc(),do we need define
the int CALLBACK MyFontEnumerator()?
 Now,suppose I define 'a' CALLBACK myself for my own function that calls
the CALLBACK,when do I pass the parameter value?
 I'm suffering from the CALLBACK function.Could you offer any articles
about it?
 Thank you in advance.


Sun, 27 Feb 2005 22:16:40 GMT  
 About CALLBACK function

Quote:

>  Since MS has defined the int CALLBACK EnumFontFamProc(),do we need define
> the int CALLBACK MyFontEnumerator()?

MS provides a signature.  You have to define a function with that
signature and provide it to EnumFontFamilies.  EnumFontFamilies will
call the function that you provide.

Quote:
>  Now,suppose I define 'a' CALLBACK myself for my own function that calls
> the CALLBACK,when do I pass the parameter value?

When your own function calls the callback function, obviously, it has
to provide parameters -- it's no different from any other function
call.

e.g.

    // associates the name mycbproc_fn_t with a pointer to a function
    // with the signature int CALLBACK (int, int)
    typedef int (CALLBACK mycbproc_fn_t*)(int n1, int n2);

    void foo(mycbproc_fn_t pBar)
    {
        // Call through function pointer
        (*pBar)(1, 2);
    }



Mon, 28 Feb 2005 00:05:04 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Getting pointer to non-static member function from C callback function

2. Passing C++ Class Member Function to as a C Callback Function Parameter

3. Callback function/function pointer question

4. Callback functions as member functions

5. class member function as callback function

6. How to use member function of a C++ class as a callback function

7. Using Non-Static Callback Functions as member Functions VC5.0

8. help: textBox vs. StringBuilder in a callback function

9. Callback Functions

10. What are Callback Functions ?

11. Timeout for callback functions?

12. help on callback function

 

 
Powered by phpBB® Forum Software