VC++ 2010 Express and Directx

Started by
11 comments, last by Kalthios 13 years, 8 months ago
I get an "Error: cannont open source file "d3dx10.h" when i try to "#include <d3dx10.h>".

I went to my project properties and added d3d10.lib to the additional dependencies under Linker, but that doesn't solve the problem.

I confess that I am not very good at understanding how libraries and includes work. I assume there is a directory path i need to input somewhere in the VC++ settings but i have no idea. Help please?
Advertisement
You have to add the directx include folder to your project's include dependencies. Although you'll need to add the library files as well for the linking process, your code won't compile as the include files are in the include folder, not the lib folder.

In general, the include files contain the functions/classes/etc definitions while the library files contain the compiled code. Thus, the include files are needed for your compiler to know your functions/classes/etc signatures, but once everything is compiled, it will need the actual code to run, and this is where the libraries come in play.
How do I include an Include folder to my project dependencies. Been looking through visual studio documentation to no avail.
1. Open one of your projects, any one of them.

2. Select View->Property Manager.

3. In the manager, expand your project.

4. Expand Debug | Win32

5. Now double click the file Microsoft.Cpp.Win32.user

6. Under common properties, choose VC++ Directories

7. Add the folder location for the include and the lib in the right side and save.

NOTE: This will make it permanent for all your projects not just this one.
What wicked357 said applies to Visual Studios before 2010. In 2010, the bindings are actually per project (although they did transition for me for some reason between projects).

For VS2010:

Go Project -> Properties (Alt+F7)
Expand Configuration Properties
Choose VC++ Directories
Click the right cell for Include Directories, choose Edit and add your DirectX SDK include folder (which is prolly something like /path-To-DirectX-SDK/June 2010/Include).
Quote:Original post by Ratslayer
What wicked357 said applies to Visual Studios before 2010. In 2010, the bindings are actually per project (although they did transition for me for some reason between projects).

For VS2010:

Go Project -> Properties (Alt+F7)
Expand Configuration Properties
Choose VC++ Directories
Click the right cell for Include Directories, choose Edit and add your DirectX SDK include folder (which is prolly something like /path-To-DirectX-SDK/June 2010/Include).


Actually what I posted is for VS2010 Pro, not before if you follow those steps you will set it up for the entire use of the program not per project as Ratslayer states. If you didn't know now you do Ratslayer, you can set them for all projects not just per.
I guess I do, lol. I thought it was fishy that it was more complicated than in VS9.
Thanks a lot guys. I actually was able to compile my first directx program! Red letter day! New problem though, program crashes when I press escape to close app but shuts down properly when I click the "x" in the top right. Here is my windows procedure and shutdown function:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
//Check for any available messages from the queue
switch (message)
{
//Allow the user to press the Escape key to end
//the application
case WM_KEYDOWN:
switch(wParam)
{
//Check if user hit Escape key
case VK_ESCAPE:
ShutdownDirect3D();
PostQuitMessage(0);
break;
}
break;

//The user hit the close button, close the app
case WM_DESTROY:
ShutdownDirect3D();
PostQuitMessage(0);
break;
}
//ALways return the message to the default winproc for
//further processing
return DefWindowProc(hWnd, message, wParam, lParam);
}



void ShutdownDirect3D()
{
//Release the rendertarget.
if (pRenderTargetView) pRenderTargetView->Release();
//Release the swapchain.
if (pSwapChain) pSwapChain->Release();
//Release the D3D Device.
if (pD3DDevice) pD3DDevice->Release();
}
The problem is that when you press escape, it shuts down d3d twice.

Remove the ShutdownDirect3D() call from your escape key press code and you should be G2G (:

Also you shouldn't need to post your quit message in wm_destroy, i believe at that point, your app is already shutting down and doesn't need to be told again.
Oh wait, I think I understand now:

So the app gets a msg that the escape key was pressed. Application does the code for that case, PostQuitMessage(0). So another message gets processed, PostQuitMessage(0), which is interpreted in the message switch as the WM_DESTROY case. WM_DESTROY case automatically ends the window, and you can put extra shutdown code, such as ShutdownDirect3d(), into its case code block.

So just do this:

switch (message)
{
//Allow the user to press the Escape key to end
//the application
case WM_KEYDOWN:
switch(wParam)
{
//Check if user hit Escape key
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
break;

//The user hit the close button, close the app
case WM_DESTROY:
ShutdownDirect3D();
break;

Am I understanding this correctly?

This topic is closed to new replies.

Advertisement