• 0

C++ / DirectX 9: Visual Studio Setup


Question

This is strange. I'm trying to get back into C++ (well, Direct3D 9.0c writing). I've forgotten how to set up a simple project.

1.) Install DirectX 9.0b SDK

2.) Install DirectX 9.0c SDK - October 2005 Update

3.) Install Visual Studio .NET 2003 (7.0)

1.) Open Visual Studio .NET 2003 (7.0)

2.) Tools > Options > Projects Folder > VC++ Directories

3.) Library files - add: "C:\DXSDK\Lib"

Now I'm stuck. Basically, I wanna' learn to create a 3D FPS game like UT2004 / Half Life 2 (yes, yes, I'll never get that advanced...but still). Using C++ and DirectX 9.0c.

I'm going through this Intro to 3D Prog. w/DX 9.0 book and I'm supposed to add "d3d9.lib d3dx9.lib winmm.lib" to the project. However, there are so many different types of projects etc. I want to be able to add the following piece of code that came with the book and compile/run it (removed the comments to shrink the size of this post). I don't pretend to understand it, but it would be nice to see a result. I intend to touch up on C++ but as long as I can get these code examples working, I would then better understand the topic.

#include <windows.h>

HWND MainWindowHandle = 0; 

bool InitWindowsApp(HINSTANCE instanceHandle, int show); 

int  Run();			   

LRESULT CALLBACK WndProc(HWND hWnd,
						 UINT msg,
						 WPARAM wParam,
						 LPARAM lParam); 

int WINAPI WinMain(HINSTANCE hInstance,  
				   HINSTANCE hPrevInstance, 
				   PSTR	  pCmdLine, 
				   int	   nShowCmd)
{
	if(!InitWindowsApp(hInstance, nShowCmd)) 
	{
		::MessageBox(0, "Init - Failed", "Error", MB_OK);
		return 0;
	}
	return Run(); // enter message loop
}

bool InitWindowsApp(HINSTANCE instanceHandle, int show)
{
	WNDCLASS wc; 

	wc.style		 = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra	= 0;
	wc.cbWndExtra	= 0;
	wc.hInstance	 = instanceHandle;
	wc.hIcon		 = ::LoadIcon(0, IDI_APPLICATION);
	wc.hCursor	   = ::LoadCursor(0, IDC_ARROW);
	wc.hbrBackground = 
	static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH));
	wc.lpszMenuName  = 0;
	wc.lpszClassName = "Hello";

	if(!::RegisterClass(&wc)) 
	{
		::MessageBox(0, "RegisterClass - Failed", 0, 0);
		return false;
	}

	MainWindowHandle = ::CreateWindow(
						   "Hello",
						   "Hello",
						   WS_OVERLAPPEDWINDOW,
						   CW_USEDEFAULT, 
						   CW_USEDEFAULT,
						   CW_USEDEFAULT,
						   CW_USEDEFAULT,
						   0,
						   0, 
						   instanceHandle,
						   0);

	if(MainWindowHandle == 0)
	{
		::MessageBox(0, "CreateWindow - Failed", 0, 0);
		return false;
	}

	::ShowWindow(MainWindowHandle, show);
	::UpdateWindow(MainWindowHandle);

	return true;
}

int Run()
{
	MSG msg;
	::ZeroMemory(&msg, sizeof(MSG));

	while(::GetMessage(&msg, 0, 0, 0) )
	{
		::TranslateMessage(&msg);
		::DispatchMessage(&msg);
	}

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND   windowHandle,
						 UINT   msg,	 
						 WPARAM wParam,
						 LPARAM lParam)
{
	switch( msg )
	{
	case WM_LBUTTONDOWN:
		::MessageBox(0, "Hello, World", "Hello", MB_OK);
		return 0;

	case WM_KEYDOWN:
		if( wParam == VK_ESCAPE )
			::DestroyWindow(MainWindowHandle);
		return 0;

	case WM_DESTROY: 
		::PostQuitMessage(0); 
		return 0;
	}
	return ::DefWindowProc(windowHandle,
						   msg,
						   wParam,
						   lParam);
}

Any ideas on how I can accomplish this - every attempt results in error messages while building :(

Thanks in advance.

Link to comment
https://www.neowin.net/forum/topic/406186-c-directx-9-visual-studio-setup/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You need to create a Win32 application.

File->New->Project... Select the Win32 Project, name it, and click OK. In the Application Settings tab, select Empty Project.

Add a new C++ file(.cpp) to your Source folder in the Solution Explorer. Copy and paste your code into the file. Ctl-Shift-B to build, and F5 to debug, or Ctl-F5 to run without debugging.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I'm old I guess, first thing I think of is just regular input/output.
    • Now, kids, Dan O'Dowd is what we call a professional hater.
    • Billionaire slams 'Tesla Cultists' for praising Robotaxi, says it's 5+ years behind Waymo by David Uzondu Image via Depositphotos.com The Tesla Robotaxi program has kicked off in Austin, Texas, and reactions are pouring in from all corners of the internet. A select group of investors and influencers have been invited to try the service, which operates within a limited area of South Austin for a price of $4.20. While the vehicles are operating without anyone in the driver's seat, the program has specific rules for this pilot phase, including a human "safety monitor" who rides along in the passenger seat just in case things go sideways. Of course, the launch did not go unnoticed by Tesla's most vocal and well-funded critic, Dan O'Dowd. O'Dowd is the billionaire founder of a group called The Dawn Project, which has dedicated itself to highlighting what it calls critical safety failures in Tesla's Full Self-Driving software. He refers to himself as an expert in creating "unhackable" software for military and aerospace clients, and ran for U.S. Senate back in 2022 on a single-issue platform: to "make computers safe for humanity" by banning Tesla's FSD. In 2023, He was banned from advertising on X after He made promoted posts that show Tesla FSD among other things, failing to stop at Stop signs. Last year, his group, The Dawn Project, paid for a Super Bowl ad, where a Tesla equipped with FSD did not act on a child-sized mannequin in the road. That commercial ends with a message, urging parents to "boycott Tesla to keep your kids safe." Today, O'Dowd took to X to slam the launch of the Robotaxi service, saying the "Tesla Cultists are celebrating victory" over a system he believes is years behind the competition (especially Waymo). He pointed out that with only fourteen cars operating for half the day, the system was already making significant errors, a rate he claims is consistent with community-tracked FSD data. The videos shared by the creators (Rob Maurer and Ed Niedermeyer), O'Dowd mentioned in his post, appear questionable, depending on your perspective. In Maurer's video, a trip that was otherwise smooth had a few unnerving seconds of the vehicle slightly swerving into the wrong lane, correcting itself, swerving again, correcting itself, and then finally settling. The other video from Ed Niedermeyer shows something entirely different. Niedermeyer captured a Tesla Robotaxi approaching an "extensive crime scene" with multiple police vehicles parked on the side of the road. On his personal Bluesky account (Ed stopped posting on X late last year, in protest of Musk), He claims the Tesla braked hard twice for no clear reason. In his commentary, Niedermeyer argued the car "shouldn't react to any of these police vehicles," and that it was concerning how it reacted to some but not others, before stopping in the "middle of the road instead of defaulting to a minimal risk condition."
  • Recent Achievements

    • Week One Done
      ravenmanNE earned a badge
      Week One Done
    • Conversation Starter
      Brett76 earned a badge
      Conversation Starter
    • One Month Later
      Miguel Batista earned a badge
      One Month Later
    • Dedicated
      moojay67 earned a badge
      Dedicated
    • One Month Later
      Jim Dugan earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      663
    2. 2
      Michael Scrip
      229
    3. 3
      ATLien_0
      216
    4. 4
      Steven P.
      146
    5. 5
      Xenon
      140
  • Tell a friend

    Love Neowin? Tell a friend!