1

I wanted to get the mouse image using C++. I used the code that I got from
How to get mouse cursor icon VS c++ question. I used visual studio 2010 IDE. I created a c++ win32 project and entered that code snippet into _tmain method and I added missing structures(CURSORINFO and ICONINFO) also. after building the project, error console shows

error C2664: 'GetCursorInfo' : cannot convert parameter 1 from 'CURSORINFO *' to 'PCURSORINFO'

what is the reason for this build error. can you explain? this is the code I built.

#include "stdafx.h"
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
    typedef struct _ICONINFO {
        BOOL    fIcon;
        DWORD   xHotspot;
        DWORD   yHotspot;
        HBITMAP hbmMask;
        HBITMAP hbmColor;
    } ICONINFO, *PICONINFO;

    typedef struct {
        DWORD   cbSize;
        DWORD   flags;
        HCURSOR hCursor;
        POINT   ptScreenPos;
    } CURSORINFO, *PCURSORINFO, *LPCURSORINFO;


    HDC hdcScreen = GetDC(NULL);
    HDC hdcMem = CreateCompatibleDC(hdcScreen);

    CURSORINFO cursorInfo = { 0 };
    cursorInfo.cbSize = sizeof(cursorInfo);

    if (::GetCursorInfo(&cursorInfo))
    {
        ICONINFO ii = {0};
        GetIconInfo(cursorInfo.hCursor, &ii);
        DeleteObject(ii.hbmColor);
        DeleteObject(ii.hbmMask);
        ::DrawIcon(hdcMem, cursorInfo.ptScreenPos.x - ii.xHotspot, cursorInfo.ptScreenPos.y -          ii.yHotspot, cursorInfo.hCursor);
    }
    return 0;
}

1 Answer 1

3

Don't redefine structs that are declared in Windows SDK headers. This is what likely causes the error.

Basically add this:

#include <Windows.h> // includes WinUser.h

unless that is already in stdafx.h. If it is, remove your own typedefs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.