C++ timer winapi - problem z kompilacją.
Ostatnio zmodyfikowano 2018-10-21 17:55
Haisse Temat założony przez niniejszego użytkownika |
C++ timer winapi - problem z kompilacją. » 2018-10-21 15:26:59 Witam wszystkich. Mam problem z timerem w c++ jestem początkującym i nie rozumiem przyczyny błędu. Co ciekawe ten sam kod na innym komputerze z tym samym systemem operacyjnym kompilował się i program działał poprawnie. Po przesłaniu pliku cpp z kodem źródłowym na domowy komputer nie mogę skompilować programu. Proszę o wyjaśnienie ewentualnego błędu w kodzie lub przyczyny nie kompilowania się pliku na innym komputerze. Kod : #include <windows.h> #include <iostream> #include <cstdlib>
using namespace std;
void static CALLBACK p( HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime ) { cout << "Timer dziala jesli ta linia tekstu wyswietla sie co 3 sekundy" << endl; }
int main() { UINT TimerId = SetTimer( NULL, 1, 3000, & p ); MSG Msg; while( 1 ) { GetMessage( & Msg, NULL, 0, 0 ); DispatchMessage( & Msg ); } return 0; }
Komunikat błędu: General: TDM-GCC 4.8.1 64-bit Release Executing g++.exe... g++.exe "C:\Users\Allen\Desktop\test timer.cpp" -o "C:\Users\Allen\Desktop\test timer.exe" -I"C:\Users\Allen\Desktop\Dev-Cpp 5.6.0 TDM-GCC x64 4.8.1 Portable (1)\Dev-Cpp\MinGW64\include" -I"C:\Users\Allen\Desktop\Dev-Cpp 5.6.0 TDM-GCC x64 4.8.1 Portable (1)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Users\Allen\Desktop\Dev-Cpp 5.6.0 TDM-GCC x64 4.8.1 Portable (1)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.8.1\include" -I"C:\Users\Allen\Desktop\Dev-Cpp 5.6.0 TDM-GCC x64 4.8.1 Portable (1)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.8.1\include\c++" -L"C:\Users\Allen\Desktop\Dev-Cpp 5.6.0 TDM-GCC x64 4.8.1 Portable (1)\Dev-Cpp\MinGW64\lib" -L"C:\Users\Allen\Desktop\Dev-Cpp 5.6.0 TDM-GCC x64 4.8.1 Portable (1)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc C:\Users\Allen\Desktop\test timer.cpp: In function 'int main()': C:\Users\Allen\Desktop\test timer.cpp:15:46: error: invalid conversion from 'void (*)(HWND, UINT, UINT, DWORD) {aka void (*)(HWND__*, unsigned int, unsigned int, long unsigned int)}' to 'TIMERPROC {aka void (*)(HWND__*, unsigned int, long long unsigned int, long unsigned int)}' [-fpermissive] UINT TimerId = SetTimer(NULL, 1, 3000, &p); //tworzenie timera ^
In file included from c:\users\allen\desktop\dev-cpp 5.6.0 tdm-gcc x64 4.8.1 portable (1)\dev-cpp\mingw64\x86_64-w64-mingw32\include\windows.h:72:0, from C:\Users\Allen\Desktop\test timer.cpp:2: c:\users\allen\desktop\dev-cpp 5.6.0 tdm-gcc x64 4.8.1 portable (1)\dev-cpp\mingw64\x86_64-w64-mingw32\include\winuser.h:2365:30: error: initializing argument 4 of 'UINT_PTR SetTimer(HWND, UINT_PTR, UINT, TIMERPROC)' [-fpermissive] WINUSERAPI UINT_PTR WINAPI SetTimer(HWND hWnd,UINT_PTR nIDEvent,UINT uElapse,TIMERPROC lpTimerFunc); ^
Compilation failed after 1,20 seconds with errors
|
|
pekfos |
» 2018-10-21 15:36:41 |
|
Haisse Temat założony przez niniejszego użytkownika |
» 2018-10-21 15:44:51 @pekfos
Racja. Poprawione
Zamiast "UINT nIDEvent" w funkcji powinno być "UINT_PTR nIDEvent"
Temat do zamknięcia. Chyba , że ktoś jest w stanie wyjaśnić dlaczego kod kompilował się na innym komputerze .
|
|
pekfos |
» 2018-10-21 17:55:11 UINT i UINT_PTR mogą być tym samym typem i wtedy program się skompiluje. |
|
« 1 » |