Thread: non static WndProc problem

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    non static WndProc problem

    I have a class called CWindowFrame which can create a window. My problem is that I cannot have the WndProc static as I want it virtual too. Anyway, when specifying the WNDCLASSEX lpfnWndProc = (WNDPROC)WinProc; I get the following error:

    Code:
    '=' : cannot convert from 'long (__thiscall CWindowFrame::*)(struct HWND__ *, unsigned int, unsigned int, long) ' to 'long (__stdcall*)(struct HWND__ *, unsigned int, unsigned int, long)'
    What might be the problem?
    Thanks
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    this is MFC? CWndFrame I think is the class name in mfc and your naming convention is similar. Well obviously you must have a __stdcall for a callback. __thiscall is a member function that hides a "this" pointer in the first parameter. therefore, it must be either static or global (and a friend would be nice).
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    No, this is not MFC, plain win32 code. Any ideas???
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I already told you. only my first question was bout mfc
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Originally posted by FillYourBrain
    Well obviously you must have a __stdcall for a callback. __thiscall is a member function that hides a "this" pointer in the first parameter. therefore, it must be either static or global (and a friend would be nice).
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    if you're having problems post the source. But in order for a callback to be declared inside a class it has to be one of the following:

    friend //a global function made a friend of the class
    static //which means global in a sense anyway

    either one with "APIENTRY", "WINAPI" or just __stdcall
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Ok, thanks everyone. I made it global. But what if I want it to be virtual too?
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  8. #8
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I know what you're trying to do. I just posted this in another thread too. You don't make the actual callback virtual. Make a member function called "Callback" which is not global. The global function will need to call it.

    here it is: http://cboard.cprogramming.com/showt...threadid=25611
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  9. #9
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Thank you, that was the solution to my problem. I have made the MsgProc function in my class virtual and non-CALLBACK and I created a CALLBACK function WndProc handling the actual messages. So, in my WNDCLASSEX struct, i define the lpfnWndProc = WndProc (WndProc is returning the MsgProc)

    This is how my code looks:
    Code:
    static CWindowFrame *win;
    
    LRESULT CALLBACK WndProc(...)
    {
       return win->MsgProc(...);
    }
    
    LRESULT CWindowFrame::MsgProc(...)
    {
    checking messages here
    }
    
    bool CWindowFrame::MakeWindow(........)
    {
    ...
    ...
    WNCLASSEX ex;
    ...
    ex.lpfnWndProc = WndProc;
    ..
    register, blah blah, create, blah. return true
    }
    The code compiles great. I have this class in a DLL, so there is another problem. When I try to create a window, it causes an access violation and points to WndProc!
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  10. #10
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    could be that your pointer is not filled in. zip and post your code and I might be able to tell you for sure what's wrong
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  11. #11
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Ok, here is the code.
    Don't forget to set your VC++6 directories include to the window parent directory as well. Also tghe library directories the debug dir of window project. the dll is automatically copied correctly. In the file it is included both the DLL and the client application.
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  12. #12
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    pretty simple actually. You have this "window" pointer that you never set. so obviously it crashes when you try to dereference it
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  13. #13
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    It is fixed! Thank you soooo much man, you really helped me out here. I changed the pointer to an instance. But if I had a pointer, \what should I do to fix it?

    However it works now, I ask of curiosity
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  14. #14
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Not exactly sure what you're asking there. personally I would prefer not to have a global pointer like that. You can set a pointer per window with SetWindowLong and GWL_USERDATA.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  15. #15
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Ok, I will look this up.
    Cya
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with unaligned intrinsics
    By The Wazaa in forum C++ Programming
    Replies: 4
    Last Post: 02-18-2009, 12:36 PM
  2. uploading file to http server via multipart form data
    By Dynamo in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2008, 04:36 AM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. Static Splitter Problem
    By dhrodrigues in forum Windows Programming
    Replies: 0
    Last Post: 05-19-2005, 05:49 AM
  5. problem about static Lib and function pointer
    By wu7up in forum C Programming
    Replies: 3
    Last Post: 02-24-2003, 09:34 AM