Getting started with Direct2D/Direct3D: The Secret of External Dependencies

You were sitting there thinking you were on top of the world, built some XNA stuff, maybe even read my blog or talked to me about the future of XNA.  I was optimistic.  And I may have been completely wrong.  XNA is now DirectXMath, and you have to consume it using C++.  Got that?  C++.  Now someone smart like Jerry Nixon will show you nifty stuff.  Me, I just show you my struggles.  This morning I was talking to a student about external dependencies and realized that many students likely have only used Java, C or C++ with Notepad or Notepad++ only.  VS 2012 is powerful, but sometimes with power comes confusion.  (For example ever try to travel in Europe without one of those plug sets?  See power and confusion.)

With Visual Studio 2012, if you are having to move from C# or VB, you might now have used VS with C++.  In C# you would set a reference and be done with it.  In C++ you have a different process.  First you set your general external dependencies in the pch.h header file.  So if you open a Blank XAML C++ project you will see under the external dependencies something like this, note that there are no DirectX dependencies (DDE really?):

image

Find PCH.H and the solution will look similar to the following:

image

Now add the following headers, (wrl/client.h isn’t part of the header files.  So you don’t have to include it:

 

 #include <wrl/client.h>
 #include <d3d11_1.h>
 #include <d2d1_1.h>
 #include <d2d1effects.h>
 #include <dwrite_1.h>
 #include <wincodec.h>

Now clean and build your app, you should see the following header files (actually you likely won’t need to clean and build your app, but just do it this time):

image

 

And there you go, External Dependencies added to your C++ project!  Nice.