Thread: Stuck and looking for help

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    3

    Stuck and looking for help

    I am learning about GUIs and using a tutorial to create a menu bar on a window. While compiling I am receiving the error "error LNK1107: invalid or corrupt file: cannot read at 0x104" for my resource.rc file.

    I included the code below for the file. Could you please help me determine what I am missing or doing wrong? I also have a resource.h and Window.cpp file if that code is needed as well.

    Code:
    #include "resource.h"
    
    
    IDR_MENU 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
    END
    
    
    IDI_ICON ICON "menu_one.ico"

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,664
    Is - is this actually C++?

    The only thing I recognize is the include statement lol.

    Is this just like nothing but macros?

  3. #3
    Registered User
    Join Date
    Mar 2017
    Posts
    3
    I believe this is the part that builds the items on the menu bar. I am actually a little confused as to why the tutorial mentions to define the items in a header file with numbers then create this resource file so it would help if someone could explain that too. Maybe it will help if I add the other two files.

    resource.h file

    Code:
    #define IDR_MENU 101
    #define IDI_ICON 201
    
    
    #define ID_FILE_EXIT 9001
    #define ID_STUFF_GO 9002
    Window.cpp file

    Code:
    #include <Windows.h>
    #include "resource.h"
    
    
    const char window[] = "myWindow";
    
    
    LRESULT CALLBACK WndProc(HWND winHandle, UINT msg, WPARAM wParam, LPARAM lParam){
    	switch (msg){
    	case WM_LBUTTONDOWN:
    		MessageBox(winHandle, "Surpise", "Secret Window", MB_OK | MB_ICONINFORMATION);
    		break;
    	case WM_CLOSE:
    		DestroyWindow(winHandle);
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    	default:
    		return DefWindowProc(winHandle, msg, wParam, lParam);
    	}
    	return 0;
    }
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
    	WNDCLASSEX wnd;
    	HWND winHandle;
    	MSG Msg;
    
    
    	wnd.cbSize = sizeof(WNDCLASSEX);
    	wnd.style = 0;
    	wnd.lpfnWndProc = WndProc;
    	wnd.cbClsExtra = 0;
    	wnd.cbWndExtra = 0;
    	wnd.hInstance = hInstance;
    	wnd.hIcon = LoadIcon(NULL, IDI_SHIELD);
    	wnd.hCursor = LoadCursor(NULL, IDC_HAND);
    	//wnd.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    	wnd.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW + 1);
    	wnd.lpszMenuName = NULL;
    	wnd.lpszClassName = window;
    	wnd.hIconSm = LoadIcon(NULL, IDI_QUESTION);
    	wnd.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
    	wnd.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON));
    	wnd.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
    
    
    	if (!RegisterClassEx(&wnd)){
    		MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    
    	winHandle = CreateWindowEx(
    		WS_EX_CLIENTEDGE,
    		window,
    		"WindBag",
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT, 720, 360,
    		NULL, NULL, hInstance, NULL
    		);
    
    
    	if (winHandle == NULL){
    		MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    
    	ShowWindow(winHandle, nCmdShow);
    	UpdateWindow(winHandle);
    
    
    	while (GetMessage(&Msg, NULL, 0, 0) > 0){
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,615
    You haven't told us how you're compiling.
    You need to use rc to comile the .rc file into a .res file, which is then linked with the executable.

    Alternatively, there could be a hidden bad character in the .rc file. You might try retyping it.

  5. #5
    Registered User
    Join Date
    Mar 2017
    Posts
    3
    Thank you algorism. Your post helped me figure out what I needed to do. I was using Visual Studio 2013 and I thought it would compile the .rc file, just like it does with the header and cpp files. I did some research and located rc.exe and compiled the .rc file into a .res file in the command line. I ran the program again and it worked!

  6. #6
    Registered User
    Join Date
    Dec 2010
    Location
    Shamokin PA (middle of nowhere)
    Posts
    128
    Command line compiling is great and its my favorite method but in most IDEs for Windows that I know of, if you include the *.rc file in the project with the other files, i.e., *.h, *.cpp files, the IDE will automagically compile and link the *.rc file into the exe for you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stuck
    By shukiren in forum C Programming
    Replies: 22
    Last Post: 09-27-2011, 07:46 PM
  2. very stuck please help!
    By dac in forum C++ Programming
    Replies: 25
    Last Post: 05-07-2006, 02:45 AM
  3. stuck again
    By luigi40 in forum C# Programming
    Replies: 6
    Last Post: 12-08-2005, 02:16 AM
  4. Stuck
    By goosematt in forum C Programming
    Replies: 1
    Last Post: 11-10-2003, 07:44 AM
  5. Stuck with '\b'
    By pratip in forum C++ Programming
    Replies: 5
    Last Post: 10-28-2003, 07:49 AM

Tags for this Thread