Need some help with this Visula Studio error

Started by
3 comments, last by Smarkus 6 years, 10 months ago

#include <Windows.h>
#include <stdlib.h>
#include <time.h>

#define APPTITLE "Hello World!"

//function prototypes
BOOL InitInstance(HINSTANCE, int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);

//Event callback function
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	char *szHello = "Hello World!";
	RECT rt;
	int x, y, n;
	COLORREF c;

	switch (message)
	{
	case WM_PAINT:
		//get dimensions of the window
		GetClientRect(hWnd, &rt);

		//start drawing on device
		hdc = BeginPaint(hWnd, &ps);

		//drawText
		DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);

		//draw 1000 random pixels
		for (n = 0; n < 3000; n++)
		{
			x = rand() % (rt.left - rt.right);
			y = rand() % (rt.bottom - rt.top);
			c = RGB(rand() % 256, rand() % 256, rand() % 256);
			SetPixel(hdc, x, y, c);
		}

		//stopdrawing
		EndPaint(hWnd, &ps);
		break;

	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}

//helper function to set up windows properties
ATOM MyRegisterclass(HINSTANCE hInstance)
{
	// create struucture
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);

	//fill the structure with information
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = (WNDPROC)WinProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = NULL;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = APPTITLE;
	wc.hIconSm = NULL;

	//set up the window with the class info
	return RegisterClassEx(&wc);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	HWND hWnd;

	//create New window
	hWnd = CreateWindow(
		APPTITLE,
		APPTITLE,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		500,
		400,
		NULL,
		NULL,
		hInstance,
		NULL);

	//if error
	if (!hWnd)
		return FALSE;

	//display the window
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);

	return TRUE;
}

//Entry point for a windows program
int WINAPI WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int    nCmdShow)
{
	MSG msg;

	MyRegisterClass(hInstance);

	if (!InitInstance(hInstance, nCmdShow))
	{
		return FALSE;
	}

	//set random number seed
	srand(time(NULL));

	// main message loop
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}

Severity Code Description Project File Line Suppression State

Error LNK1120 1 unresolved externals MyDirectX C:\Users\conta\Documents\ONE\PersonalProjects\MyDirectX Book\\MyDirectXDebug.exe 1
Error LNK2019 unresolved external symbol "unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@YAGPAUHINSTANCE__@@@Z) referenced in function _WinMain@16 MyDirectX C:\Users\conta\Documents\ONE\PersonalProjects\MyDirectX Book\main.obj 1

I have some linker errors here, can someone help me out?

Advertisement

ATOM MyRegisterclass(HINSTANCE hInstance)

should be


ATOM MyRegisterClass(HINSTANCE hInstance)

What's wrong with it though?


ATOM MyRegisterclass(HINSTANCE hInstance)

should be


ATOM MyRegisterClass(HINSTANCE hInstance)

One has lower case c in class, the proper is upper case Class in you function name. C++ is case sensitive.

Oh thanks!

This topic is closed to new replies.

Advertisement