Thread: What's wrong with "INPUT ttnptt;"?

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    42

    What's wrong with "INPUT ttnptt;"?

    Hi there,

    What's wrong with declaring "INPUT ttnptt;" in main.c? No matter how the variable is named: nptt, or ttnptt, it gets the same error as "main.c(58) : error C2061: syntax error : identifier 'ttnptt'". We know that INPUT is Declared in Winuser.h, which is included in Windows.h.

    Could anyone please give advice on this? This is very much appreciated.
    : Thanks,
    Code:
    #include <windows.h>
    
    ...
    
    INPUT ttnptt;
    
    ..
    
    
            cl -Z7 -Od -c -W3 -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -D_X86_=1 
    -D_WINNT -D_WIN32_WINNT=0x0400 -D_WIN32_IE=0x0300 -DWINVER=0x0400 -DWIN32  -D_WIN32 main.c
    main.c
    main.c(58) : error C2061: syntax error : identifier 'ttnptt'
    main.c(58) : error C2059: syntax error : ';'
    NMAKE : fatal error U1077: 'cl' : return code '0x2'
    Stop.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    #define _WIN32_WINNT 0x500
    #include <windows.h>

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    Thanks so much. The error becomes warning as the following:

    Code:
    main.c(21) : warning C4005: '_WIN32_WINNT' : macro redefinition
            unknown(0) : see previous definition of '_WIN32_WINNT'

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > -D_WINNT -D_WIN32_WINNT=0x0400 -D_WIN32_IE=0x0300 -DWINVER=0x0400
    Make sure this lot on the command line is up to your requirements.
    Changing the _WIN32_WINNT to match that in the source code for example.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    Thanks so much. The warning was gone now. But why following code can not be compiled?

    INPUT is a structure surely, why "error C2224: left of '.type' must have struct/union type"?

    Code:
    INPUT inp;
    
    inp.type = INPUT_KEYBOARD;
    inp.ki.wVk = 0;
    inp.ki.wScan = 0xded2;
    inp.ki.dwFlags = KEYEVENTF_UNICODE;
    inp.ki.time = 0;
    inp.ki.dwExtraInfo = 0;
    hResult = SendInput(1, (LPINPUT) &inp, sizeof(INPUT));
    
    
    cl -Ox -c -W3 -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -D_X86_=1 -D_WINNT 
    -D_WIN32_WINNT=0x0450 -D_WIN32_IE=0x0400 -DWINVER=0x0450 -DWIN32 -D_WIN32 main.c
    main.c
    main.c(349) : error C2224: left of '.type' must have struct/union type
    main.c(350) : error C2224: left of '.ki' must have struct/union type
    main.c(351) : error C2224: left of '.ki' must have struct/union type
    main.c(352) : error C2224: left of '.ki' must have struct/union type
    main.c(352) : error C2065: 'KEYEVENTF_UNICODE' : undeclared identifier
    main.c(353) : error C2224: left of '.ki' must have struct/union type
    main.c(354) : error C2224: left of '.ki' must have struct/union type
    NMAKE : fatal error U1077: 'cl' : return code '0x2'
    Stop.
    
    typedef struct tagINPUT { 
      DWORD type; 
      union {MOUSEINPUT mi; 
                KEYBDINPUT ki;
                HARDWAREINPUT hi;
               };
      }INPUT, *PINPUT
    Thanks,

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    INPUT is a structure surely, why "error C2224: left of '.type' must have struct/union type"?

    If memory serves me correctly, you must also include the WinAble.h header file to provide the necessary support (structs etc.) for SendInput

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    Even #include <winable.h> is added, the error messages are the same. I check winable.h, all declarations about INPUT and KEYBDINPUT are the same as they are in winuser.h, which is included in windows.h

    Thanks,

  8. #8
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    This example works for me with winable.h but does NOT compile if I use winuser.h. It just turns the Caps Lock light on.
    Code:
    // Compile: cl key.cpp
    #pragma comment( lib, "user32.lib" ) 
    #include <windows.h>
    #include <WinAble.h> // Required for the SendInput function
    int main(void)
    {
        INPUT input[2];
        ZeroMemory(input, sizeof(input));        
        input[0].type = input[1].type = INPUT_KEYBOARD;
        input[0].ki.wVk  = input[1].ki.wVk = VK_CAPITAL;
        SendInput(2, input, sizeof(INPUT));
        return 0;
    }

  9. #9
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    Thank you all. It works now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM