locked
Subclassing, x64 RRS feed

  • Question

  • Hi,

    i dlike to use simple subclassing in my x64 program. When i use, compiling below attached code under x86 platform., thats all works fine(tested on WinXP, x86):

    WNDPROC g_pOldProc;

    static LRESULT CALLBACK MyEditProc(HWND, UINT, WPARAM, LPARAM);

     

    g_pOldProc = (WNDPROC)SetWindowLong(hwndOfCallingComponent, GWL_WNDPROC, (LONG)MyEditProc);

     

    LRESULT CALLBACK MyEditProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {

        MessageBox(NULL, "HereIAm", NULL, MB_OK);

        return CallWindowProc (g_pOldProc, hwnd, message, wParam, lParam);

    }

     

    When I tryed compile the same program, source code(GWLP_WNDPROC included) under x64 platform it doesnt work properly under Win Vista => MessageBox was never displayed, no errors displayed, no others problem. When i tryed use the same code but replace SetWindowLong -> SetWindowLongPtr, then program was completely frozen, no errors displayed. 

    Friday, December 31, 2010 1:57 PM

Answers

  • Try this: SetWindowLongPtr( hwndOfCallingComponent, GWL_WNDPROC, (LONG_PTR)MyEditProc ).

    • Marked as answer by Johny Cage Friday, December 31, 2010 3:51 PM
    Friday, December 31, 2010 2:56 PM
  • >When I tryed compile the same program, source code(GWLP_WNDPROC included) under x64 platform it doesnt work properly under Win Vista => MessageBox was never displayed, no errors displayed, no others problem. When i tryed use the same code but replace SetWindowLong -> SetWindowLongPtr, then program was completely frozen, no errors displayed. 

    You should be using SetWindowLongPtr, and here:

    g_pOldProc = (WNDPROC)SetWindowLong(hwndOfCallingComponent,
    GWL_WNDPROC, (LONG)MyEditProc);

    The LONG cast is wrong (for x64), use LONG_PTR.

    If you're still having a problem, show the latest code you're using.

    Dave

    • Marked as answer by Johny Cage Friday, December 31, 2010 3:51 PM
    Friday, December 31, 2010 3:06 PM

All replies

  • Try this: SetWindowLongPtr( hwndOfCallingComponent, GWL_WNDPROC, (LONG_PTR)MyEditProc ).

    • Marked as answer by Johny Cage Friday, December 31, 2010 3:51 PM
    Friday, December 31, 2010 2:56 PM
  • >When I tryed compile the same program, source code(GWLP_WNDPROC included) under x64 platform it doesnt work properly under Win Vista => MessageBox was never displayed, no errors displayed, no others problem. When i tryed use the same code but replace SetWindowLong -> SetWindowLongPtr, then program was completely frozen, no errors displayed. 

    You should be using SetWindowLongPtr, and here:

    g_pOldProc = (WNDPROC)SetWindowLong(hwndOfCallingComponent,
    GWL_WNDPROC, (LONG)MyEditProc);

    The LONG cast is wrong (for x64), use LONG_PTR.

    If you're still having a problem, show the latest code you're using.

    Dave

    • Marked as answer by Johny Cage Friday, December 31, 2010 3:51 PM
    Friday, December 31, 2010 3:06 PM
  • LONG x LONG_PTR , it was the problem, much thanks messieurs.
    Friday, December 31, 2010 3:50 PM
  • For check all 64-bit issues use PVS-Studio (Viva64).

    Example: Search of explicit type conversion errors in 64-bit programs.


    Andrey Karpov is technical manager of the OOO "Program Verification Systems" (Co Ltd) company developing the PVS-Studio tool which is a package of static code analyzers integrating into the Visual Studio development environment.

    Saturday, January 1, 2011 5:59 PM