I'm trying to compile the following program (file named test.cpp):
#include "stdafx.h"
int main(int argc, char* argv[]){
INPUT *buffer = new INPUT[1]; //allocate a buffer
buffer->type = INPUT_MOUSE;
buffer->mi.dx = 100;
buffer->mi.dy = 100;
buffer->mi.mouseData = XBUTTON1;
buffer->mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
buffer->mi.time = 0;
buffer->mi.dwExtraInfo = 0;
SendInput(1,buffer,sizeof(INPUT));
delete (buffer); //clean up our messes.
}
when "stdafx.h" is:
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
Then I get the following errors:
e:\test\src\test.cpp(4) : error C2065: 'INPUT' : undeclared identifier
e:\test\src\test.cpp(4) : error C2065: 'buffer' : undeclared identifier
e:\test\src\test.cpp(4) : error C2061: syntax error : identifier 'INPUT'
e:\test\src\test.cpp(5) : error C2227: left of '->type' must point to class/struct/union type is ''unknown-type''
e:\test\src\test.cpp(5) : error C2065: 'INPUT_MOUSE' : undeclared identifier
e:\test\src\test.cpp(5) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(6) : error C2227: left of '->mi' must point to class/struct/union type is ''unknown-type''
e:\test\src\test.cpp(6) : error C2228: left of '.dx' must have class/struct/union type
e:\test\src\test.cpp(6) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(7) : error C2227: left of '->mi' must point to class/struct/union type is ''unknown-type''
e:\test\src\test.cpp(7) : error C2228: left of '.dy' must have class/struct/union type
e:\test\src\test.cpp(7) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(8) : error C2227: left of '->mi' must point to class/struct/union type is ''unknown-type''
e:\test\src\test.cpp(8) : error C2228: left of '.mouseData' must have class/struct/union type
e:\test\src\test.cpp(8) : error C2065: 'XBUTTON1' : undeclared identifier
e:\test\src\test.cpp(8) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(9) : error C2227: left of '->mi' must point to class/struct/union type is ''unknown-type''
e:\test\src\test.cpp(9) : error C2228: left of '.dwFlags' must have class/struct/union type
e:\test\src\test.cpp(9) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(10) : error C2227: left of '->mi' must point to class/struct/union type is ''unknown-type''
e:\test\src\test.cpp(10) : error C2228: left of '.time' must have class/struct/union type
e:\test\src\test.cpp(10) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(11) : error C2227: left of '->mi' must point to class/struct/union type is ''unknown-type''
e:\test\src\test.cpp(11) : error C2228: left of '.dwExtraInfo' must have class/struct/union type
e:\test\src\test.cpp(11) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(12) : error C2070: ''unknown-type'': illegal sizeof operand
e:\test\src\test.cpp(12) : error C3861: 'SendInput': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(12) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(12) : error C3861: 'INPUT': identifier not found, even with argument-dependent lookup
e:\test\src\test.cpp(13) : error C2541: 'delete' : cannot delete objects that are not pointers
e:\test\src\test.cpp(13) : error C3861: 'buffer': identifier not found, even with argument-dependent lookup
I'm using everyting as specified in MSDN, but still got this stupid compiler error. Have no idea why... :(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/KeyboardInput/KeyboardInputReference/KeyboardInputFunctions/SendInput.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/KeyboardInput/KeyboardInputReference/KeyboardInputStructures/INPUT.asp
Obviously what I want is this code to compile and run :)
PS
When I compile it with only <winuser.h> (instead #include "stdafx.h" I write #include <winuser.h>), I get the following errors:
c:\...\include\winuser.h(39) : error C2146: syntax error : missing ';' before identifier 'HDWP'
c:\...\include\winuser.h(39) : fatal error C1004: unexpected end of file found
I've tried to compile both on VC++ 6.0 and .net and both produce the same errors!!!