Home > Mobile >  cast from WNDPROC to LONG
cast from WNDPROC to LONG

Time:05-01

static LRESULT CALLBACK wndProcNew(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}

int CALLBACK wWinMain(HINSTANCE hInst,HINSTANCE,PWSTR szcmdLine,int cmdShow){
    using namespace std;
    Pixel pix;
    LONG tmp = SetWindowLong(pix.getWnd(), GWLP_WNDPROC, (LONG)wndProcNew);
    return 0;
}

I want to change the window procedure. mingw throws an error:

error: cast from 'LRESULT ()(HWND, UINT, WPARAM, LPARAM)' {aka 'long long int ()(HWND__*, unsigned int, long long unsigned int, long long int)'} to 'LONG' {aka 'long int'} loses precision [-fpermissive] 21 | LONG tmp = SetWindowLongW(pix.getWnd(), GWLP_WNDPROC, (LONG)wndProcNew);

what am I doing wrong?

CodePudding user response:

On 64-bit Microsoft Windows, pointers (including function pointers) have a size of 64 bits, whereas a variable of type long or LONG has a size of 32 bits. Therefore, a variable of that size is unable to represent the value of a pointer.

If you want to set 64-bit values, I recommend that you use SetWindowLongPtr instead of SetWindowLong.

  • Related