Thread: INPUT error

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    6

    INPUT error

    I have this code that gets the color of 4 pixels off the screen and checks them to see if they are white, but I am getting an error at INPUT saying that it is an unknown identifier. Any help?

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	HDC	     hdcScrn;
    	hdcScrn	 = CreateDC((LPCWSTR)"DISPLAY", 0, 0, 0); //Capture the screen
    	COLORREF    Col1,Col2,Col3,Col4; //Colors
    	POINT LP, RP, UP, DP;
    	LP.x = 374;LP.y = 391;
    	RP.x = 627;RP.y = 387;
    	UP.x = 533;UP.y = 362;
    	DP.x = 467;DP.y = 415;
    	//Define the input keys
    	INPUT Left, Right, Up, Down;
    	Left.type    = INPUT_KEYBOARD;
    	Right.type   = INPUT_KEYBOARD;
    	Up.type      = INPUT_KEYBOARD;
    	Down.type    = INPUT_KEYBOARD;
    	Left.ki.wVk  = VK_LEFT;
    	Right.ki.wVk = VK_RIGHT;
    	Up.ki.wVk    = VK_UP;
    	Down.ki.wVk  = VK_DOWN;
    
    	while (true)
    	{
    		//SetActiveWindow(hWnd);
    		Col1 = GetPixel(hdcScrn, LP.x, LP.y);
    		Col2 = GetPixel(hdcScrn, RP.x, RP.y);
    		Col3 = GetPixel(hdcScrn, UP.x, UP.y);
    		Col4 = GetPixel(hdcScrn, DP.x, DP.y);
    		if (Col1 == 16777215)//left
    		{
    			SendInput(1, &Left, sizeof(INPUT));
    		}
    		if (Col2 == 16777215)//right
    		{
    			SendInput(1, &Right, sizeof(INPUT));
    		}
    		if (Col3 == 16777215)//up
    		{
    			SendInput(1, &Up, sizeof(INPUT));
    		}
    		if (Col4 == 16777215)//down
    		{
    			SendInput(1, &Down, sizeof(INPUT));
    		}
    
    	}
    	DeleteDC(hdcScrn);	// deletes the handle
    	return 0;
    }
    Edit: Had the POINT stuff screwed up, fixed now.
    Last edited by Tanner.B; 03-29-2007 at 04:13 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Where did you get that code from? INPUT is a type that has to be defined somewhere. It looks like you think it is defined in windows.h (or in a header you include in stdafx.h), but apparently it is not.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6
    Oh... I read somewhere that it was included in windows.h. I'll do some more reading on MSDN and see if I can figure it out.

    http://msdn2.microsoft.com/en-us/library/ms646270.aspx

    It says it is defined in winuser.h and to include windows.h
    Last edited by Tanner.B; 03-29-2007 at 04:08 PM.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Code:
    typedef struct tagINPUT {
        DWORD   type;
    
        union
        {
            MOUSEINPUT      mi;
            KEYBDINPUT      ki;
            HARDWAREINPUT   hi;
        };
    } INPUT, *PINPUT, FAR* LPINPUT;
    Include winable.h.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6

    Cool

    Ok, I did that. It got rid of all the errors =) Thank you very much.

    But now I get these errors when linking:
    error LNK2019: unresolved external symbol __imp__DeleteDC@4 referenced in function _wmain
    error LNK2019: unresolved external symbol _SendInput@12 referenced in function _wmain
    error LNK2019: unresolved external symbol __imp__GetPixel@12 referenced in function _wmain
    error LNK2019: unresolved external symbol __imp__CreateDCW@16 referenced in function _wmain

  6. #6
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    You're missing a .lib library that you need to include in your project. I can't tell you off the top of my head which it is. At least, that is the most common way to get that error. What you can be sure of is that the compiler knows that those functions exist. It just can't find them.
    Don't quote me on that... ...seriously

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6
    The MSDN site says they are in gdi32.lib. I searched my computer for it and found 2 copies and then checked what libraries are included in VC++, and the folders that contain them are included. So I am out of ideas.

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    I've never used VC, but I'd assume that you have to link to that library thru linker options, no?

    For Dev, I do;

    "C:\Dev-Cpp\lib\libgdi32.a"

    More than likely, someone will come on by and toss you the bone you need....

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Yes, you need to go to the Project Properties/Settings and under Linker put gdi32.lib as an additional dependency.

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6
    Awesome! Compiles now. I had to add gdi32.lib and user32.lib as addictional dependencies. Thanks for the awesome and fast help everyone.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM