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;
}
General Grievance
  • 4,555
  • 31
  • 31
  • 45
lakshman
  • 2,641
  • 6
  • 37
  • 63

1 Answers1

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.

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152