So my problem is I keep getting error
"this declaration has no storage class or type specifier"
"the size of an array must be greater than zero"
" expected a ';' "
I don't know what's wrong. I tried to look online and find no specific solution to my problem other than generic solutions like defining the class for the terms in my .h file but I don't even know where to begin defining 'ZeroMemory' or something like that. You can see in my code, in my Source.cpp, I have commented out the code and did a paste crossover into my .h file. The error presented above appears and it seems it won't compile but its fine compiling if I leave them in my Source.cpp file instead. How do I go about solving this? I'm at my wits end here.
BTW I want them on a separate file which is a .h file.
Source.cpp file
#include <windows.h>
#include <iostream>
#include <conio.h>
#include "Input Buttons.h"
int main()
{
//INPUT blocks[6], grabs[4];
/*ZeroMemory(blocks, sizeof(blocks));*/
/*ZeroMemory(grabs, sizeof(grabs));*/
//virutal key list website
//docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
//Setting up key/mouse input environment
//a
//blocks[0].type = INPUT_KEYBOARD;
//blocks[0].ki.wVk = 0x41; //keyboard button 'a'
//blocks[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY; //press down
//blocks[1].type = INPUT_KEYBOARD;
//blocks[1].ki.wVk = 0x41;
//blocks[1].ki.dwFlags = KEYEVENTF_KEYUP; //let go
//d
//blocks[2].type = INPUT_KEYBOARD;
//blocks[2].ki.wVk = 0x44; //keyboard button 'd'
//blocks[2].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
//blocks[3].type = INPUT_KEYBOARD;
//blocks[3].ki.wVk = 0x44;
//blocks[3].ki.dwFlags = KEYEVENTF_KEYUP;
//s
//blocks[4].type = INPUT_KEYBOARD;
//blocks[4].ki.wVk = 0x53; //keyboard button 's'
//blocks[4].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
//blocks[5].type = INPUT_KEYBOARD;
//blocks[5].ki.wVk = 0x53;
//blocks[5].ki.dwFlags = KEYEVENTF_KEYUP;
//i
//grabs[0].type = INPUT_KEYBOARD;
//grabs[0].ki.wVk = 0x49; //keyboard button 'i'
//grabs[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
//grabs[1].type = INPUT_KEYBOARD;
//grabs[1].ki.wVk = 0x49;
//grabs[1].ki.dwFlags = KEYEVENTF_KEYUP;
//k
//grabs[2].type = INPUT_KEYBOARD;
//grabs[2].ki.wVk = 0x4B; //keyboard button 'k'
//grabs[2].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
//grabs[3].type = INPUT_KEYBOARD;
//grabs[3].ki.wVk = 0x4B;
//grabs[3].ki.dwFlags = KEYEVENTF_KEYUP;
}
Input Buttons.h
#pragma once
using namespace std;
INPUT blocks[6], grabs[4];
ZeroMemory(blocks, sizeof(blocks));
ZeroMemory(grabs, sizeof(grabs));
//a
blocks[0].type = INPUT_KEYBOARD;
blocks[0].ki.wVk = 0x41; //keyboard button 'a'
blocks[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY; //press down
blocks[1].type = INPUT_KEYBOARD;
blocks[1].ki.wVk = 0x41;
blocks[1].ki.dwFlags = KEYEVENTF_KEYUP; //let go
Error in image form from my perspective
CodePudding user response:
As it currently is, your header file has "freestanding" execution code. This is not possible in C - C is not a scripting language where you can execute code in arbitrary files.
Every executable code needs to be in a function.
So you better declare a function prototype in your Buttons.h
with the necessary data types.
Then you create a function in Buttons.cpp
where you define the function with the code you want to execute and compile and link it. You can then include Buttons.h
and call the function from main()
Buttons.h
#include <conio.h>
void do_stuff();
Buttons.cpp
void do_stuff() {
INPUT blocks[6];
INPUT grabs[4];
//... rest of your code//
}
Source.cpp
#include "Buttons.h" // makes do_stuff() visible in Source.cpp
int main() {
do_stuff();
}