Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cast from WNDPROC to LONG

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading