Function pointers problem

Discussion in 'C++' started by Noah Roberts, Dec 11, 2003.

  1. Noah Roberts

    Noah Roberts Guest

    Question: Why is the compiler complaining about conversion from typeA to
    typeA function pointers?! AFAICT that is what it is doing...

    Thanks,
    NR

    mingw message:

    Dialup.cpp: In function `void DialupChooser(HWND__*, int, char*,
    stack_t**)':
    Dialup.cpp:92: invalid conversion from `BOOL (*)(HWND__*, unsigned int,
    unsigned int, long int)' to `BOOL (*)(HWND__*, unsigned int,
    unsigned int,
    long int)'
    Dialup.cpp: In function `void setup(HWND__*, int, char*, stack_t**, int,
    BOOL
    (*)(HWND__*, unsigned int, unsigned int, long int))':
    Dialup.cpp:272: invalid conversion from `BOOL (*)(HWND__*, unsigned int,
    unsigned int, long int)' to `BOOL (*)(HWND__*, unsigned int,
    unsigned int,
    long int)'


    Declaration of function:


    BOOL CALLBACK dchose_proc (HWND hwnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam);

    Declaration of setup():

    static void setup(HWND hwndParent,
    int string_size,
    char *variables,
    stack_t **stacktop,
    int dialog_resource_id,
    BOOL CALLBACK (*proc)(HWND,UINT,WPARAM,LPARAM));

    Call to setup (line 92):

    setup(hwndParent, string_size, variables, stacktop,
    ID_CHOOSE_DIALOG,dchose_proc);

    Line 272 (inside setup()):

    dialog = CreateDialog(hinst,
    MAKEINTRESOURCE(dialog_resource_id),
    parent,
    proc);
     
    Noah Roberts, Dec 11, 2003
    #1
    1. Advertising

  2. On Thu, 11 Dec 2003 14:40:49 -0800, Noah Roberts <> wrote:

    >Question: Why is the compiler complaining about conversion from typeA to
    >typeA function pointers?! AFAICT that is what it is doing...



    > ...
    >
    >Declaration of function:
    >
    >
    > BOOL CALLBACK dchose_proc (HWND hwnd,
    > UINT message,
    > WPARAM wParam,
    > LPARAM lParam);
    >
    >Declaration of setup():
    >
    > static void setup(HWND hwndParent,
    > int string_size,
    > char *variables,
    > stack_t **stacktop,
    > int dialog_resource_id,
    > BOOL CALLBACK (*proc)(HWND,UINT,WPARAM,LPARAM));
    >
    >Call to setup (line 92):
    >
    > setup(hwndParent, string_size, variables, stacktop,
    >ID_CHOOSE_DIALOG,dchose_proc);
    >
    >Line 272 (inside setup()):
    >
    > dialog = CreateDialog(hinst,
    > MAKEINTRESOURCE(dialog_resource_id),
    > parent,
    > proc);
    >



    Basically it's because you're using a non-standard extension of the
    language, namely the specifier that the CALLBACK macro expands to.
    What you have is a syntax error. You can "fix" that error by moving
    CALLBACK into (*proc), just before the *, but it's Microsoft, not C++.

    Instead of using such non-standard extensions all over the place, consider
    using the types defined by the platform-specific header files you're using.

    In this case, the DLGPROC type, which encapsulates the non-standard things
    of the function pointer type definition.
     
    Alf P. Steinbach, Dec 11, 2003
    #2
    1. Advertising

  3. Noah Roberts

    Noah Roberts Guest


    > Basically it's because you're using a non-standard extension of the
    > language, namely the specifier that the CALLBACK macro expands to.
    > What you have is a syntax error. You can "fix" that error by moving
    > CALLBACK into (*proc), just before the *, but it's Microsoft, not C++.
    >
    > Instead of using such non-standard extensions all over the place, consider
    > using the types defined by the platform-specific header files you're using.
    >
    > In this case, the DLGPROC type, which encapsulates the non-standard things
    > of the function pointer type definition.
    >


    Thanks, I didn't realize my problem was due to the non-standard stuff
    but instead something with my C++ understanding. I will see if that
    helps tomarro at work.

    NR
     
    Noah Roberts, Dec 12, 2003
    #3
  4. Noah Roberts

    Noah Roberts Guest

    Alf P. Steinbach wrote:

    > Basically it's because you're using a non-standard extension of the
    > language, namely the specifier that the CALLBACK macro expands to.
    > What you have is a syntax error. You can "fix" that error by moving
    > CALLBACK into (*proc), just before the *, but it's Microsoft, not C++.


    This seemed to work, thank you.
    >
    > Instead of using such non-standard extensions all over the place, consider
    > using the types defined by the platform-specific header files you're using.
    >
    > In this case, the DLGPROC type, which encapsulates the non-standard things
    > of the function pointer type definition.
    >

    I couldn't figure out how to do this one. It seems DLGPROC is actually
    a double indirection, the other option was easier ;)

    NR
     
    Noah Roberts, Dec 12, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil
    Replies:
    1
    Views:
    650
    llewelly
    Sep 16, 2003
  2. muser
    Replies:
    3
    Views:
    765
    Ron Natalie
    Sep 18, 2003
  3. Peter Goddard

    void pointers & void function pointers

    Peter Goddard, May 16, 2005, in forum: C Programming
    Replies:
    3
    Views:
    519
    Peter Goddard
    May 16, 2005
  4. n2xssvv g02gfr12930

    Smart pointers and member function pointers

    n2xssvv g02gfr12930, Nov 26, 2005, in forum: C++
    Replies:
    3
    Views:
    472
    n2xssvv g02gfr12930
    Nov 27, 2005
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    681
Loading...

Share This Page