error line 1:expected unqualified-id before numeric constant

I created a resource file (.rc) and a .h file.
in the .h file I experienced an error on line 1: expected unqualified-id before numeric constant.

the code in .h file

#define IDR_MYMENU 101 //line 1
#define IDI_MYICON 201
#define ID_FILE_EXIT 9001
#define ID_STUFF_GO


the in .rc

#include "resource.h"

IDR_MYMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Stuff"
BEGIN
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o somewhere else", 0, GRAYED
END
BEGIN

IDI_MYICON ICON "menu_one.ico"

the code in .c
#include "resource.h"

#include "myrc.rc"
#include <windows.h>


const char g_szClassName[] = "myWindowClass";


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN:
{
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance,szFileName,MAX_PATH);
MessageBox(hwnd,szFileName,"This program is: ",MB_ICONINFORMATION|MB_OK);
}

break;

case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

//step 1: Registering the window class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wc.lpszClassName= g_szClassName;
wc.hIconSm = (HICON)LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_MYICON),IMAGE_ICON,16,16,0);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}


hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,g_szClassName,"The title of my window",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,600,300,NULL,NULL,hInstance,NULL);

if(hwnd==NULL)
{
MessageBox(NULL,"Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}

ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);

while (GetMessage(&Msg,NULL,0,0)>0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;

}

I went ahead to change #define MY_MENU 101 to const int MY_MENU = 101;
then a new error message: redeclaration of const int MY_MENU
which am very sure I initialized once.
I don't know where I've goon wrong, any help would be appreciated.Tnx
Last edited on
Do not #include "myrc.rc" anywhere.
If I leave out "myrc.rc" from the .c headers, my menu items won't load. the window will be created without my menu items (FILE,STUFF)
You cannot include .rc file in .c (which is of course not a header). You need to add the .rc to your project.

What you have is basically what you get when you create a new win32 project. I've something similar and it works [only] without including the .rc into the .c
Ok, so what do I do to make 'File' and 'Stuff' display on my window?
I'd say something is wrong with your .rc:
1
2
3
4
5
6
7
8
9
10
11
12
IDR_MYMENU MENU
BEGIN // <-- Where's the matching END?
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Stuff"
BEGIN
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o somewhere else", 0, GRAYED
END
BEGIN // <-- Isn't this supposed to be END? 
oops, my error.
with that corrected, 'File' and 'Stuff' still didn't display on the window.
You have probably more problems.
I'd say make a win32 project from scratch and make your changes there.
A general addition to the comments above:

You've included file a in file b, then you've included both files a and b in file c. You've defined everything in file a twice.

In legitimate header files, try to use include guards to get around this problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// file.h
#ifndef _FILE_H_
#define _FILE_H_

// declarations ...

#endif


// file2.h
#ifndef _FILE2_H_
#define _FILE2_H_

#include "file.h"

// declarations ...

#endif


// file3.c

#include "file.h"
#include"file2.h"

// source code ... 
Topic archived. No new replies allowed.