Results 1 to 6 of 6

Thread: Function Pointers

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73

    Function Pointers

    PHP Code:
    void (*Function(HWND hwnd); 
    How would I call that?

    I'm trying to do like WNDCLASSEX does..... :-\ no luck....
    if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
    {
    SetWindowText(hwnd,"I suck.");
    SendMessage(hwnd,WM_START_SUCKING,0,0);
    SendMessage(hwnd,WM_CRASH,0,0);
    }

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    should be
    void (*Function)(HWND hwnd);

    and you call it like
    Function(somehwnd);
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73
    Heres my code: (Its an imitation MFC thing)
    I excluded all the irrelevant parts

    PHP Code:
    class Window
    {
    public:
        
    void (*OnDestroy)(HWND hwnd);
    }; 
    PHP Code:
    LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
        switch(
    msg)
        {
        case 
    WM_DESTROY:
            
    Window::OnDestroy(hwnd);
    //ERROR OCCURS HERE
            
    break;
        default:
            return 
    DefWindowProc(hwnd,msg,wParam,lParam);
        }
        return(
    0);

    NOTE! THAT IS NOT IN THE CLASS!!!!

    PHP Code:
    void Cls_OnDestroy(HWND hwnd)
    {
        
    PostQuitMessage(0);

    PHP Code:
    w.OnDestroy=Cls_OnDestroy
    Error: C2064: term does not evaluate to a function

    Any ideas?
    if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
    {
    SetWindowText(hwnd,"I suck.");
    SendMessage(hwnd,WM_START_SUCKING,0,0);
    SendMessage(hwnd,WM_CRASH,0,0);
    }

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    call it like:
    w.OnDestroy(hwnd);
    or change OnDestroy to static
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Reason for the error:

    Your 'OnDestroy' function pointer is a member variable of each instance of your class. It only has meaning in the context of an object which is an instance of your class; it doesn't mean anything when it's just associated with the class itself, not an instance of that class.

    You have used the scope resolution operator, ::, to resolve the scope of your function pointer (ie to acquire the function pointer so you can call it). However, this will only give you access to static class members, since non-static class members have no meaning without an associated instance of that class.

    As Kedaman suggests, the solutions are to either make the function pointer static (the same variable is available to all instances of a class) and continuing to use the scope resolution operator, ::, as you do at the moment, or alternatively to instantiate an object of the class and assign the function pointer in that object. You can then use that object to get to your member function pointer, and you can call it using the direct member access operator (the dot . ).

    Looks like you want to do it the latter way, by using the dot instead of ::
    Harry.

    "From one thing, know ten thousand things."

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73
    Ahhh! I get it now!!!!

    Thanks!

    Now I remember that from my certification course thingy (not finished yet)
    if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
    {
    SetWindowText(hwnd,"I suck.");
    SendMessage(hwnd,WM_START_SUCKING,0,0);
    SendMessage(hwnd,WM_CRASH,0,0);
    }

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