DirectX Tutoial issues

Started by
1 comment, last by Amr0 11 years, 10 months ago
Hi guys,

I've been trying to learn DirectX for a while now. I've tried to use the tutorials in the June 2010 sdk but the basic ones wouldnt compile in 2008 VC++ for some reason, so i look for some more tutorials and found this website http://www.directxtutorial.com/ . I really liked it, but I'm still having issues when i try to run a program. Here is the code

#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 = L"WindowClass1";

// register the window class
RegisterClassEx(&wc);

// create the window and use the result as the handle
hWnd = CreateWindowEx(NULL,
L"WindowClass1", // name of the window class
L"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);
}

and here are the errors i get
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Programming\Visual Studio 2008\Projects\DirectXWindow\Debug\DirectXWindow.exe : fatal error LNK1120: 1 unresolved externals

Please help, I really want to get into game programming but i'm starting to get a bit frustrated because I've been trying for weeks to get something working
Advertisement
Protip: If you highlight your code in the post editor and select the "code" button (symbol: <>) it'll be a lot easier for us to understand.

Like so:

public static void main()
{
Console.WriteLine("This is ugly");
}

or:



public static void main()
{
Console.WriteLine("This is beautiful");
}
Sole Creator of Pigment - a procedural, block-base space trading sim.

PhD student working on medical imaging at the University of Southampton.

Enjoyer of games, films, books and cider.
I guess it doesn't say so in the tutorial, but when you create a new project in VC++2008, you need to select "windows application" (or something like that) from the projects templates. This takes care of setting up the required linker options.

[size=2]P.S. Your post belongs in the "General Programming", or the "For Beginners" sections rather than DX & XNA since it practically has nothing to do with DirectX.

This topic is closed to new replies.

Advertisement