Public Group

# Setting up Dx9 with VS2008?

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

## Recommended Posts

##### Share on other sites
It's set by default.

Otherwise, your book is probably telling you how to do it under Visual C++ 2008 Express, not Visual Studio 2008 (they're different!). If so, you might want to download it (free at microsoft.com) and try it out.

##### Share on other sites
Quote:
 Original post by PlasticineGuyVisual C++ 2008 Express, not Visual Studio 2008 (they're different!)

Sure, they're different, but for all intents and purposes, Visual C++ 2008 Express and Visual Studio 2008 Professional are exactly the same. Its just the professional version has a bunch of features you probably will never use; you'll encounter the exact same problem as the OP describes in the Express edition.

Quote:
 Original post by otreumThe problem is, I do not have a folder in the project properties called C/C++, nor could I find anything in any of the folders that had a Code Generation option.

It's an oddity of Visual Studio 2008. You need to add a C/C++ file to your project before you are able edit the C/C++ project settings.

Quote:
 d3dx9d.lib (debugger version?)

Yes, libraries suffixed with a "d" typically stand for debug version.

Quote:
 dinput8.lib (direct input 8? isn't this for directX 8?)

Yes, because there wasn't any changes since DirectX8. However, DirectInput is now deprecated in favor of XInput.

##### Share on other sites
Just a little point. If I can remember correctly there is no more library called:
DxErr9.lib

Now that library is common between dx9 and 10 and it's called:
DxErr.lib

##### Share on other sites
Well i'd just like to get my project set up correctly for directX before I even start trying to compile any code.

The book is actually saying how to do the steps for Visual Studio 6.0 and extra steps for Visual Studio .NET .
The visual studio .NET steps are closer to what I need but obviously there are differences between Visual Studio 2008 and .NET so now i'm stuck.

_fastcall hit the nail on the head.
All the problem was, that I had not yet added a .cpp file to the project yet, and therefore there was no C/C++ settings to edit for the project.

Thanks _fastcall, I appreciate you pointing this out as it's probably solved alot of headaches! :)

Also I changed a few of my linked library files based on what has been said by repka3, so now I have the following files linked:
d3d9.lib d3dx9d.lib d3dxof.lib dxguid.lib XInput.lib DxErr.lib winmm.lib dinput8.lib

I changed some others there after actually having a look at the library names in my directX SDK folder.

Now I can continue....actually...no, I can't continue.
I can't because this book sortof just throws code at the reader and says "It's too complex to explain, but just type this code in anyway".

So I figured I should google around and see what I could find online, I found a place called www.directxtutorial.com and another website here:
http://gregs-blog.com/2008/02/20/directx-9-c-graphics-tutorial-1-getting-started/

Which are some starters to directX, however when I use this code:

#include <windows.h> // include the basic windows header file

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
// create a "Hello World" message box using MessageBox()
MessageBox(NULL,
L"Hello World!",
L"Just another Hello World program!",
MB_ICONEXCLAMATION | MB_OK);

// return 0 to Windows
return 0;
}

I get the following error: (btw, the online lib file linked is now just d3d9.lib)

1>------ Build started: Project: compiler_setup, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>f:\gamedev\1\compiler_setup\compiler_setup\main.cpp(12) : error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'const wchar_t [13]' to 'LPCSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://f:\Gamedev\1\compiler_setup\compiler_setup\Debug\BuildLog.htm"
1>compiler_setup - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

[Edited by - otreum on April 11, 2010 8:41:59 AM]

##### Share on other sites
Anyway i'm reading that book right now, and yes is full of "it's too hard to explain, this is the code and that's all. Ok the code is quite self-explanatory, but for example for mesh animation , first i don't like at all his data structures, second he dont explain nothing about blend verticies and blend animation.
If can i suggest you a book try Introduction to 3d programming with directx 9.0: a shader approach. by Frank Luna.

bye.

##### Share on other sites
Quote:
 Original post by otreum1>------ Build started: Project: compiler_setup, Configuration: Debug Win32 ------1>Compiling...1>main.cpp1>f:\gamedev\1\compiler_setup\compiler_setup\main.cpp(12) : error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'const wchar_t [13]' to 'LPCSTR'1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast1>Build log was saved at "file://f:\Gamedev\1\compiler_setup\compiler_setup\Debug\BuildLog.htm"1>compiler_setup - 1 error(s), 0 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Tell the compiler you want use Multi-byte character sets
Property->General->Character Set->Use Multi-Byte Character Set.

##### Share on other sites
Hmmm, it is already using Multi-byte character set :(

I think it was either the code is dodgy, or when it copied across, it copied the quotation marks with italics, and thus did not actually copy across as quotation marks.
I just copied the code from:
http://gregs-blog.com/2008/02/20/directx-9-c-graphics-tutorial-1-getting-started/

And it all had errors, until I fixed up some of the quotation marks.

However, while it compiles perfectly fine, when I actually try to run the program, it crashes, so I debug the code, it gets to this line:
g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);

and it then jumps to:
g_pDirect3D_Device->Release();

shows an unhandled exception error at the line saying:

The error itself says:
Quote:
 Unhandled exception at 0x0122178a in compiler_setup.exe: 0xC0000005: Access violation reading location 0x00000000.

Below is the final code:
#include <windows.h>#include <d3d9.h>  // globalsLPDIRECT3D9       g_pDirect3D = NULL;LPDIRECT3DDEVICE9 g_pDirect3D_Device = NULL;LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow){   MSG msg;   WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_VREDRAW|CS_HREDRAW|CS_OWNDC,                     WndProc, 0, 0, hInstance, NULL, NULL, (HBRUSH)(COLOR_WINDOW+1),                     NULL, "DX9_TUTORIAL1_CLASS", NULL};    RegisterClassEx(&wc);   HWND hMainWnd = CreateWindow("DX9_TUTORIAL1_CLASS","DirectX 9 Bare Bones Tutorial 1?",	   WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,NULL, NULL,hInstance,NULL);   g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);D3DPRESENT_PARAMETERS PresentParams;memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));PresentParams.Windowed = TRUE;PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWnd,                          D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParams,						  &g_pDirect3D_Device);   ShowWindow(hMainWnd, nShow);   UpdateWindow(hMainWnd);   while(GetMessage(&msg, NULL, 0, 0))   {      TranslateMessage(&msg);      DispatchMessage(&msg);   }   return(0);}  LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){   switch(msg)   {      case WM_DESTROY:         PostQuitMessage(0);         return(0);	  case WM_PAINT: // <— ADD THIS BLOCK      g_pDirect3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255),                           1.0f, 0);g_pDirect3D_Device->Present(NULL, NULL, NULL, NULL);      ValidateRect(hwnd, NULL);      return(0);   }	g_pDirect3D_Device->Release();	g_pDirect3D->Release();   return(DefWindowProc(hwnd, msg, wParam, lParam));}

##### Share on other sites
Use a debugger to isolate where the exception occurs in your code.

##### Share on other sites
Quote:
 Original post by otreumHmmm, it is already using Multi-byte character set :(

Set it to Unicode. The Win32 API maps its functions, for example MessageBox, to either MessageBoxA (which take chars and char-strings) or MessageBoxW (which take wchar_ts and wchar_t-strings) depending on whether or not UNICODE and _UNICDOE are defined. You can define these macros manually before including windows-related headers, or you can set the character set to "Unicode", which does this for you as a project setting.

Quote:
 D3DPRESENT_PARAMETERS PresentParams;memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));

In C++, this is written as: D3DPRESENT_PARAMETERS PresentParams = {};

Also:
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){	switch(msg)	{	case WM_DESTROY:		PostQuitMessage(0);		return(0);		 	case WM_PAINT: // <— ADD THIS BLOCK		g_pDirect3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);		g_pDirect3D_Device->Present(NULL, NULL, NULL, NULL);		ValidateRect(hwnd, NULL);		return(0);	}		// Wait what?	// Are you sure you want to destroy your Direct3D devices when	// a message wasn't handled by the code above, such as a WM_MOUSEMOTION?	g_pDirect3D_Device->Release();	g_pDirect3D->Release();		return(DefWindowProc(hwnd, msg, wParam, lParam));}

This is, indeed, a problem with the code, however, it may not be the problem you're experiencing. As older1s suggested, use the debugging features of Visual Studio to determine where your code is going wrong. I noticed that the DirectX calls aren't being tested for success/failures. You might want to start there. For example, Direct3DCreate9 returns 0 on failure, and IDirect3D9::CreateDevice returns D3D_OK on success.

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
15
5. 5

• 9
• 9
• 13
• 9
• 33
• ### Forum Statistics

• Total Topics
632592
• Total Posts
3007284

×