| | |
C++ Problem (Winapi)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 106
Reputation:
Solved Threads: 5
Hello all.
I have some problems with compilation while working with WinApi.
Here is the code:
If you look at it it seams that there are no problems, but there are some errors rising while compiling it, the two most importants are :
Error 1 error C2065: 'msg' : undeclared identifier
Error 2 error C2275: 'MSG' : illegal use of this type as an expression
Thise errors are given on the next line:
But i think the code is correct . Im using Visual Studio Professional edition.
Thanks in advance.
I have some problems with compilation while working with WinApi.
Here is the code:
c++ Syntax (Toggle Plain Text)
// include the basic windows header file #include <windows.h> #include <windowsx.h> // the WindowProc function prototype LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // the entry point for any Windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // the handle for the window, filled by a function HWND hWnd; // this struct holds information for the window class WNDCLASSEX wc; // clear out the window class for use ZeroMemory(&wc, sizeof(WNDCLASSEX)); // fill in the struct with the needed information wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.lpszClassName = "WindowClass1"; // register the window class RegisterClassEx(&wc); // create the window and use the result as the handle hWnd = CreateWindowEx(0, "WindowClass1", // name of the window class "Our First Windowed Program", // title of the window WS_OVERLAPPEDWINDOW, // window style 300, // x-position of the window 300, // y-position of the window 500, // width of the window 400, // height of the window NULL, // we have no parent window, NULL NULL, // we aren't using menus, NULL hInstance, // application handle NULL); // used with multiple windows, NULL // display the window on the screen ShowWindow(hWnd, nCmdShow); // enter the main loop: // this struct holds Windows event messages MSG msg; // wait for the next message in the queue, store the result in 'msg' while(GetMessage(&msg, NULL, 0, 0)) { // translate keystroke messages into the right format TranslateMessage(&msg); // send the message to the WindowProc function DispatchMessage(&msg); } // return this part of the WM_QUIT message to Windows return msg.wParam; } // this is the main message handler for the program LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { // sort through and find what code to run for the message given switch(message) { // this message is read when the window is closed case WM_DESTROY: { // close the application entirely PostQuitMessage(0); return 0; } break; } // Handle any messages the switch statement didn't return DefWindowProc (hWnd, message, wParam, lParam); }
Error 1 error C2065: 'msg' : undeclared identifier
Error 2 error C2275: 'MSG' : illegal use of this type as an expression
Thise errors are given on the next line:
c++ Syntax (Toggle Plain Text)
MSG msg;
Thanks in advance.
>>Include winuser.h
That should not be necessary since he's already including windows.h
>>Im using Visual Studio Professional edition.
Which version -- there are several of them.
>>but there are some errors rising while compiling it, the two most importants are :
Are there other errors listed before the two you posted? Correct those first, recompile then see if those two errors disappear.
That should not be necessary since he's already including windows.h
>>Im using Visual Studio Professional edition.
Which version -- there are several of them.
>>but there are some errors rising while compiling it, the two most importants are :
Are there other errors listed before the two you posted? Correct those first, recompile then see if those two errors disappear.
Last edited by Ancient Dragon; Jul 31st, 2009 at 9:23 am.
I compiled your program with vc++ 2008 Express and had no errors or warnings. I also have Microsoft Windows SDK installed, but since you have the Pro edition that shouldn't be your problem. Are you certain you created a "win32 project" instead of a console project? Attached is the project I created.
•
•
Join Date: Jan 2009
Posts: 106
Reputation:
Solved Threads: 5
Once again i dont see the edit button...
I've created an Empty Project, and winapi hello world
Worked just fine.
I also searched for the definition of MSG and found #Define MSG UserMsg. Triyed to put it in my code and it said that UserMsg is not recognized... Maybe there is any problem with my sdk (its v6.0A) ?
Going to check other sdk i have here (Windows Server 2003 R2). Maybe thise would help...
Edit:
Tested, same problem.
I've created an Empty Project, and winapi hello world
c++ Syntax (Toggle Plain Text)
#include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL,"a","b",0); return 0; }
I also searched for the definition of MSG and found #Define MSG UserMsg. Triyed to put it in my code and it said that UserMsg is not recognized... Maybe there is any problem with my sdk (its v6.0A) ?
Going to check other sdk i have here (Windows Server 2003 R2). Maybe thise would help...
Edit:
Tested, same problem.
Last edited by jen140; Jul 31st, 2009 at 10:54 pm.
![]() |
Similar Threads
- Got a Problem with winapi calls (C++)
- Problem with WinAPI (C++)
- Problem Creating Window (C)
- Windows GUI - problem with dialog box (C++)
- CreateMenu problem (C++)
- WinApi GUI Menu Problem (C)
Other Threads in the C++ Forum
- Previous Thread: need help
- Next Thread: sscanf output to array
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






