[gelöst] MinGW compiler error
-
Hallo Leute
Mir macht wieder einmal MinGW zu schaffen. Ich wollte die Funktion SendInput verwenden, um einen Mouse Input zu simulieren.
Meine Window Procedure:
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { POINT cursor; static INPUT my_input; static MOUSEINPUT my_mouseinput; static int time_out = 0, arrow_up = 0, arrow_down = 0, arrow_left = 0, arrow_right = 0, delay = 0; /* procede the referenced messages */ switch(message) { /* initializations */ case WM_CREATE: /* register the hot keys */ RegisterHotKey(hwnd, HOT_EXIT_PRGM, MOD_CONTROL | MOD_ALT, VK_END); RegisterHotKey(hwnd, HOT_TIME_OUT, MOD_CONTROL | MOD_ALT, 'T'); RegisterHotKey(hwnd, HOT_ARROW_UP, MOD_CONTROL, VK_UP); RegisterHotKey(hwnd, HOT_ARROW_DOWN, MOD_CONTROL, VK_DOWN); RegisterHotKey(hwnd, HOT_ARROW_LEFT, MOD_CONTROL, VK_LEFT); RegisterHotKey(hwnd, HOT_ARROW_RIGHT, MOD_CONTROL, VK_RIGHT); RegisterHotKey(hwnd, HOT_LEFT_CLICK, MOD_CONTROL, 'K'); RegisterHotKey(hwnd, HOT_RIGHT_CLICK, MOD_ALT, 'K'); /* initialize the mouse input structure */ my_mouseinput.dx = 0; my_mouseinput.dy = 0; my_mouseinput.mouseData = 0; my_mouseinput.time = 0; my_mouseinput.dwExtraInfo = 0; /* initialize the input structure */ my_input.type = INPUT_MOUSE; return(0); /* timer event */ case WM_TIMER: switch((UINT)wParam) { case ID_DELAY_TIMER: /* reset all move vectors, because the time has run out */ if(delay) { arrow_up = 0; arrow_down = 0; arrow_left = 0; arrow_right = 0; } break; } return(0); /* a hot key is pressed */ case WM_HOTKEY: switch((UINT)wParam) { /* exit the program */ case HOT_EXIT_PRGM: PostMessage(hwnd, WM_DESTROY, 0, 0); break; /* time out key is pressed */ case HOT_TIME_OUT: /* play a beep sound */ MessageBeep(MB_ICONEXCLAMATION); /* end of tim out (come from time out) */ if(time_out) { time_out = 0; } /* time out (go to time out) */ else { /* kill the timer */ KillTimer(hwnd, ID_DELAY_TIMER); /* reset all move vectors */ arrow_up = 0; arrow_down = 0; arrow_left = 0; arrow_right = 0; /* time out is enable */ time_out = 1; } break; /* left mouse button simulation */ case HOT_LEFT_CLICK: /* if the time out is enabled, don't process the hot key */ if(time_out) { return(0); } /* set the type of mouse input */ my_mouseinput.dwFlags = MOUSEEVENTF_LEFTDOWN; /* copy the mouse input to the input structure */ my_input.mi = my_mouseinput; /* send the mouse input */ SendInput(1, &my_input, sizeof(INPUT)); break; /* right mouse button simulation */ case HOT_RIGHT_CLICK: /* if the time out is enabled, don't process the hot key */ if(time_out) { return(0); } break; /* arrow up key is pressed */ case HOT_ARROW_UP: /* if the time out is enabled, don't process the hot key */ if(time_out) { return(0); } /* increment the move up vector */ arrow_up++; /* reset the other move vectors */ arrow_down = 0; arrow_left = 0; arrow_right = 0; break; /* arrow down key is pressed */ case HOT_ARROW_DOWN: /* if the time out is enabled, don't process the hot key */ if(time_out) { return(0); } /* increment the move down vector */ arrow_down++; /* reset the ohter move vectors */ arrow_up = 0; arrow_left = 0; arrow_right = 0; break; /* arrow left key is pressed */ case HOT_ARROW_LEFT: /* if the time out is enabled, don't process the hot key */ if(time_out) { return(0); } /* increment the move left vector */ arrow_left++; /* reset the other move vectors */ arrow_up = 0; arrow_down = 0; arrow_right = 0; break; /* arrow right key is pressed */ case HOT_ARROW_RIGHT: /* if the time out is enabled, don't process the hot key */ if(time_out) { return(0); } /* increment the move right vector */ arrow_right++; /* reset the other move vectors */ arrow_up = 0; arrow_down = 0; arrow_left = 0; break; } /* restart the delay timer */ delay = 1; SetTimer(hwnd, ID_DELAY_TIMER, 100, NULL); /* get the cursor position */ GetCursorPos(&cursor); /* compute the new cursor position */ cursor.x += (arrow_right - arrow_left); cursor.y += (arrow_down - arrow_up); /* set the new cursor position */ SetCursorPos(cursor.x, cursor.y); return(0); /* clean up and quit the program */ case WM_DESTROY: /* unregister the hot keys */ UnregisterHotKey(hwnd, HOT_EXIT_PRGM); UnregisterHotKey(hwnd, HOT_TIME_OUT); UnregisterHotKey(hwnd, HOT_ARROW_UP); UnregisterHotKey(hwnd, HOT_ARROW_DOWN); UnregisterHotKey(hwnd, HOT_ARROW_LEFT); UnregisterHotKey(hwnd, HOT_ARROW_RIGHT); UnregisterHotKey(hwnd, HOT_LEFT_CLICK); UnregisterHotKey(hwnd, HOT_RIGHT_CLICK); /* kill the timer */ KillTimer(hwnd, ID_DELAY_TIMER); /* send the post quit message to leave the program */ PostQuitMessage(0); return(0); } /* procede unreferenced messages with the default window procedure */ return(DefWindowProc(hwnd, message, wParam, lParam)); }Die Fehlermeldungen des Compilers:
gcc -O0 -g3 -Wall -c -fmessage-length=0 -obuttmo2.o ..\buttmo2.c ..\buttmo2.c: In function `WndProc': ..\buttmo2.c:124: error: syntax error before "my_input" ..\buttmo2.c:125: error: syntax error before "my_mouseinput" ..\buttmo2.c:150: error: `my_mouseinput' undeclared (first use in this function) ..\buttmo2.c:150: error: (Each undeclared identifier is reported only once ..\buttmo2.c:150: error: for each function it appears in.) ..\buttmo2.c:157: error: `my_input' undeclared (first use in this function) ..\buttmo2.c:157: error: `INPUT_MOUSE' undeclared (first use in this function) ..\buttmo2.c:225: warning: implicit declaration of function `SendInput' ..\buttmo2.c:225: error: `INPUT' undeclared (first use in this function) Build error occurred, build is stopped Time consumed: 344 ms.Kann mir da jemand weiterhelfen? ich bin einfach ratlos. Der Compiler scheint alles Definitionen und Deklarationen aus der winuser.h zu ignorieren.
mfg
Sputnik
-
Das verstehe ich zum Beispei schonmal nicht:
..\buttmo2.c:124: error: syntax error before "my_input"
..\buttmo2.c:125: error: syntax error before "my_mouseinput"Dann benutz doch Microsoft Visual C++ Express Edition. Was spricht den dagegen?
Okay das willst du nicht vielleicht hast du vergessen die input.h oder wie die heist einzubinden schaut ganz so aus.
-
Hmm, leider habe ich nicht vergessen, diese Header einzubinden. Es müsste laut Doku genügen, die windows.h einzubinden. Ich habe dann auch mal die winuser.h eingebunden, wo diese Funktionen und defines definiert werden, allerdings hat es auch dann noch nicht geklappt. Dort hat es dann noch so Präprozessor-Bedinnungen, welche irgendwas mit der Windows-Vesion zu tun zu haben scheinen, aber ich versthen nicht genau wie.
hier mal der entscheidende Ausschnitt aus der winuser.h:
#if (_WIN32_WINNT >= 0x0403) typedef struct tagMOUSEINPUT { LONG dx; LONG dy; DWORD mouseData; DWORD dwFlags; DWORD time; ULONG_PTR dwExtraInfo; } MOUSEINPUT,*PMOUSEINPUT; typedef struct tagKEYBDINPUT { WORD wVk; WORD wScan; DWORD dwFlags; DWORD time; ULONG_PTR dwExtraInfo; } KEYBDINPUT,*PKEYBDINPUT; typedef struct tagHARDWAREINPUT { DWORD uMsg; WORD wParamL; WORD wParamH; } HARDWAREINPUT,*PHARDWAREINPUT; typedef struct tagINPUT { DWORD type; _ANONYMOUS_UNION union { MOUSEINPUT mi; KEYBDINPUT ki; HARDWAREINPUT hi; } DUMMYUNIONNAME; } INPUT,*PINPUT,*LPINPUT;Ich versthe das einfach nicht. Da sind ja die Defines zu finden, es sei denn _WIN32_WINNT ist kleiner als 0x0403.
Ich bin langsam am verzweifeln, warum kann das nicht einfach funzen?
mfg
Sputnik
-
Ja tatsächlich eine komische Sache. Ich bin mir sicher dass du im Google auch nichts findest. ... Vielleicht kannst du den Header winuser.h auch noch inkludieren also nicht nur windows.h obwohl windows.h eigentlich von alleine winuser.h inkludiert. Schau doch mal nach gibt es bei dir keinen Rechtsklick-Dropdown->Gehe zu Deklaration. Da müsste eigentlich das richtige kommen. Wenn nicht dann binde winuser.h explizit ein.
P.S.: Was ist MinGW eigentlich für ein Compiler? Den kenn ich garnicht versuchs mal mit Visual C++ 6.0 Das ist für die Windows SDK.
-
Naja, ich habe die winuser.h schon als Include drin und es funzt nicht, dass ist ja genau das, was mich so verwirrt.
MinGW ist eine Sammlung von Libs für die Programmierung der WinAPI mit einem gcc-Compiler. Und ich habe früher immer VC++ verwendet, wollte aber von dem wegkommen, weil er mir zu viele Sachen aufzwingt, die ich nicht will.
mfg
Sputnik
-
MinGW ist eine Sammlung von Libs für die Programmierung der WinAPI mit einem gcc-Compiler. Und ich habe früher immer VC++ verwendet, wollte aber von dem wegkommen, weil er mir zu viele Sachen aufzwingt, die ich nicht will.
Dann versuch das selbe mit VC++ und schau ob du da einen Fehler hast und wenn es noch immer nicht klappt dann schau ob es einen neuen Release von MingW gibt.
-
C-Chris schrieb:
Wenn nicht dann binde winuser.h explizit ein.
Das wird ganz bestimmt nix bringen
.C-Chris schrieb:
P.S.: Was ist MinGW eigentlich für ein Compiler? Den kenn ich garnicht versuchs mal mit Visual C++ 6.0 Das ist für die Windows SDK.
Oha^^
Also, eigentlich war Sputnik schon auf dem richtigen Weg, die Präprozessor-Definitionen unterbinden die Kompilierung des betroffenen (eingeschlossenen) Codes. So geht's richtig (am Anfang Deiner Quellcodedatei anfügen, in der die WndProc definiert ist):
#define _WIN32_WINNT 0x0403 #include <windows.h> // ... LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { POINT cursor; static INPUT my_input; // ...
-
Vielen Dank für dein Hilfe. Ist eigentlich logisch, dass man das mal ausprobiert, hatte aber angst, dass ich damit den Compiler sonst wo vergraule. Naja, auf jeden fall tut es jetzt und ich bin heilfroh, dass ich am eigentlichen Problem weiterarbeiten kann.
Ach ja, was ich noch erwähnen wollte: Man sollte den Define #define _WIN32_WINNT 0x0403 unbedingt vor dem Include der windows.h machen, da damit es einwandfrei funzt. Nur für den Fall, dass mal jemand anders sich mit dem gleichen Problem rumschlägt und diesen Thread liest

mfg
Sputnik
-
Und noch was kleines:
Grossen Dank, dass mich niemand wegen meinem English in meinem Source-Code ausgelacht hat, bin halt ein Schweizer und nicht gerade der begabteste auf diesem Gebiet
Ich habe mir halt einfach eines Tages vorgenommen, alle meine Codes nur noch auf English zu dokumentieren, damit sie so quasie international lesbar sind (ich weiss, ist ein bischen kindisch).Vielen Dank für euer Verständnis
Sputnik
-
Ausserdem noch Danke das CodeFinder so nett ist nur weil ich nicht weis was MingW ist und ich Beiträge sammeln möchte.

CodeFinder mobbt mich

Hallo es ist Weihnachten
:xmas1:

-
C-Chris schrieb:
Ausserdem noch Danke das CodeFinder so nett ist nur weil ich nicht weis was MingW ist und ich Beiträge sammeln möchte.

CodeFinder mobbt mich

Hallo es ist Weihnachten
:xmas1:

CodeFinder mobbt Dich sicher nicht. Er hat mir sehr weitergeholfen und MinGW ist nun wirklich etwas, wo man früher oder später drüberstolpert, wenn man unter der GPL programmieren will und aucht gerne mit Linux arbeitet und sich daher den GCC schon gewöhnt ist. Zudem hat es beinahe kommentarlos hingenommen, dass Du das nicht wusstest.
mfg
Sputnik