Sign in to follow this  

Stupid Windows Resources

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason, I get the error, ".\directx.h(8) : fatal error RC1004: unexpected end of file found" whenever I try to build with MSVC++ .NET 2003. Here's the source code: directx.h:
#include <windows.h> // Include the Windows API Header File
#include <d3d8.h> // Include the Direct3D 8 Header File

#define IDI_DIRECTX 1

bool D3DSetup(void); // Direct3D Setup Function
void D3DRender(void); // Direct3D Function Used to Render or Draw the Screen
void D3DShutdown(void); // Direct3D Shutdown Function

main.cpp:
#include "directx.h" // Include the Header Where We Define the DirectX Functions, Classes, Etc.

HWND hWindow; // Handle to the Window
MSG Message; // Structure That Handles Windows Messages

LRESULT CALLBACK WndProc(HWND, unsigned int, WPARAM, LPARAM); // The Window Message Handler

// The Main Function of the Program

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{

	WNDCLASSEX WindowClass; // Class Used to Set Window Settings

	WindowClass.cbClsExtra = 0; // No Extra Class Settings
	WindowClass.cbSize = sizeof(WNDCLASSEX); // Size of the Class
	WindowClass.cbWndExtra = 0; // No Extra Window Settings
	WindowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // Set the Background Color to Black
	WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Set the Cursor to the Windows Arrow
	WindowClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DIRECTX)); // Set the Icon to Look Like a Windows Application
	WindowClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DIRECTX)); // Set the Icon Displayed on the Window to Look Like a Windows Application
	WindowClass.hInstance = hInstance; // Set the Handle to the Instance of the Application
	WindowClass.lpfnWndProc = WndProc; // Use the Function We Define Later as the Windows Message Handler
	WindowClass.lpszClassName = "DirectX"; // Set the Class Name
	WindowClass.lpszMenuName = NULL; // No Menu for the Program
	WindowClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; // Set Style Options

	if (!RegisterClassEx(&WindowClass)) // Make Sure the Class Gets Register; if Not, Then Alert the User and Exit
	{

		MessageBox(NULL, "Window Class Registration Failed", "Error", MB_OK);
		return 0;

	}
	
	if (MessageBox(NULL, "Would you like to run in fullscreen mode?", "DirectX", MB_YESNO) == IDYES) // See if the User Wants to Run the Program in Fullscreen or Windowed Mode
	{

		if (!(hWindow = CreateWindowEx(NULL, "DirectX", "DirectX", WS_POPUP | WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL))) // Make Sure the Window is Created; if Not, Then Alert the User and Exit
		{

			MessageBox(NULL, "Window Creation Failed", "Error", MB_OK);
			return 0;

		}

	}
	else
	{

		if (!(hWindow = CreateWindowEx(NULL, "DirectX", "DirectX", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 640, 480, NULL, NULL, hInstance, NULL))) // Make Sure the Window is Created; if Not, Then Alert the User and Exit
		{

			MessageBox(NULL, "Window Creation Failed", "Error", MB_OK);
			return 0;

		}

	}

	if (!D3DSetup()) // Make Sure Direct3D Sets Up; if Not, Then Alert the User and Exit
	{

		MessageBox(NULL, "Direct3D Setup Failed", "Error", MB_OK);
		PostQuitMessage(0);

	}

	ZeroMemory(&Message, sizeof(Message)); // Clear the MSG Structure Before We Use it

	// The Main Loop

	while (Message.message != WM_QUIT) // The Program Will Exit if the Window Message Received is the Quit Message
	{

		if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) // If a Message is Received, Then Process it
		{

			TranslateMessage(&Message);
			DispatchMessage(&Message);

		}

		if (GetAsyncKeyState(VK_ESCAPE)) // If the User Presses ESCAPE, Then Make Sure the User Wants to Exit
		{

			if (MessageBox(NULL, "Are you sure you want to quit?", "DirectX", MB_YESNO) == IDYES)
			{

				PostQuitMessage(0);

			}

		}

		D3DRender(); // Render the Screen

	}

	D3DShutdown(); // Shutdown Direct3D

	UnregisterClass("DirectX", hInstance); // Unregister the Window Class

	return 0; // Return to Windows

}

// The Window Message Handler

LRESULT CALLBACK WndProc(HWND hWindow, unsigned int Message, WPARAM wParam, LPARAM lParam)
{

	switch (Message)
	{

	case WM_CLOSE: // If We Receive the Close Message, Then Exit

		PostQuitMessage(0);
		break;

	case WM_DESTROY: // If We Receive the Destroy Message, Then Exit

		PostQuitMessage(0);
		break;

	default:

		break;

	}

	return DefWindowProc(hWindow, Message, wParam, lParam); // Return to WinMain

}

directx.rc:
#include "directx.h"

ICON IDI_DIRECTX "icon.ico"

I would include directx.cpp, but it just defines those three functions in directx.h (which for now do nothing). I'll give any other information you want.

Share this post


Link to post
Share on other sites
Ive not used .net but perhaps the problem is this:
You have included directx.h in your resource file. This means
function prototypes are in your resouce file and are not valid.

Share this post


Link to post
Share on other sites
I'm going to hazard a guess and suggest using

#pragma once

or

#ifndef DIRECTX_H
#define DIRECTX_H
[ code ]
#endif

in directx.h

It may also be that you have to implement your functions in the h file, but I'm not sure of that since I rarely put functions in h files.

Regards,
jflanglois

Share this post


Link to post
Share on other sites

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this