I get a lot of macro redefinition when using Directx 10
Asked Answered
M

1

5

I'm Windows 7 using Visual Studio 2012 and Directx 10.

The problem is when I compiled, I get a lot of macro redefinition errors

This is my code:

#include <windows.h>
#include <tchar.h>
#include <d3d.h>
#include <d3d10.h>


HINSTANCE hInstance;        // Hold application instance
HWND wndHandle;     // Hold window instance
ID3D10Device *mDevice = NULL;
IDXGISwapChain *mSwapChain = NULL;
ID3D10RenderTargetView *mRenderTargetView = NULL;

int width = 1024;
int height = 1024;
bool InitWindow( HINSTANCE hInstance, int width, int height );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
bool initD3D();
void Render();

int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow )
{
// Initialize the window
if ( !InitWindow( hInstance, width, height ) )
{
return false;
}
// main message loop:
MSG msg = {0};
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Additional game logic can be called from here
}
return (int) msg.wParam;
}



bool InitWindow(HINSTANCE hInstance, int width, int height)
{
WNDCLASSEX wcex;
// Fill in the WNDCLASSEX structure. This describes how the window
// will look to the system
wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
wcex.style = CS_HREDRAW | CS_VREDRAW; // the class style
wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
wcex.cbClsExtra = 0; // extra bytes to allocate for this class
wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
wcex.hInstance = hInstance; // handle to the application instance
wcex.hIcon = 0; // icon to associate with the application
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); // the default cursor to use
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // the background color
wcex.lpszMenuName = NULL; // the resource name for the menu
wcex.lpszClassName = TEXT("DirectXExample"); // the class name being created
wcex.hIconSm = 0; // the handle to the small icon
RegisterClassEx(&wcex);

// Resize the window
RECT rect = { 0, 0, width, height };
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
// create the window from the class above
wndHandle = CreateWindow(TEXT("DirectXExample"),
TEXT("DirectXExample"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
if (!wndHandle)
{
return false;
}

// Display the window on the screen
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Check 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 the user hit the Escape key
case VK_ESCAPE:
PostQuitMessage(0);
    break;
}
break;
// The user hit the close button, close the application
case WM_DESTROY:
PostQuitMessage(0);
break;
}
// Always return the message to the default window procedure for further processing
return DefWindowProc(hWnd, message, wParam, lParam);
}

bool initD3D()
{
DXGI_SWAP_CHAIN_DESC sd;
sd.BufferDesc.Width = width; // use window's client area dims
sd.BufferDesc.Height = height;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// No multisampling.
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
sd.OutputWindow = wndHandle;
sd.Windowed = true;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Flags = 0;


if ( FAILED (D3D10CreateDeviceAndSwapChain ( NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL,         
0, D3D10_SDK_VERSION, &sd, mSwapChain, &mDevice ) ) )
{
MessageBox ( wndHandle, L"Failed to create device and swapchain", L"error", MB_OK );
    return FALSE;
}

// get the back buffer from the swap chain
ID3D10Texture2D *Backbuffer = NULL;
HRESULT hr = mSwapChain->GetBuffer (0, __uuidof(ID3D10Texture2D), (LPVOID*)&Backbuffer);

if ( hr != S_OK)
{
    return false;
}

// Create the render target view
hr = mDevice->CreateRenderTargetView ( Backbuffer, NULL, &mRenderTargetView);

// Release Back Buffer
Backbuffer -> Release();

// Make sure the render target view was created successfully
if ( hr!= S_OK)
{
    return false;
}

// Set render target
mDevice -> OMSetRenderTargets ( 1, &mRenderTargetView, NULL);

// Create Viewport
D3D10_VIEWPORT viewport;
viewport.Width = width;
viewport.Height = height;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;

// Set the Viewport
mDevice->RSSetViewports (1, &viewport);

return true;
}

void Render()
{
    if ( mDevice != NULL )
    {
        // Clear the back buffer
        mDevice->ClearRenderTargetView(mRenderTargetView, color);

        // Present
        mSwapChain->Present(0,0);
    }
}

When I compiled, I got a lot of macro redefinition errors:

1> Source.cpp 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(12): warning C4005: 'DXGI_STATUS_OCCLUDED' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49449) :'DXGI_STATUS_OCCLUDED' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(13): warning C4005: 'DXGI_STATUS_CLIPPED' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49458) : 'DXGI_STATUS_CLIPPED' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(14): warning C4005: 'DXGI_STATUS_NO_REDIRECTION' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49467) : 'DXGI_STATUS_NO_REDIRECTION' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(15): warning C4005: 'DXGI_STATUS_NO_DESKTOP_ACCESS' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49476) : 'DXGI_STATUS_NO_DESKTOP_ACCESS' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(16): warning C4005: 'DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49485) : 'DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(17): warning C4005: 'DXGI_STATUS_MODE_CHANGED' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49494) :'DXGI_STATUS_MODE_CHANGED' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(18): warning C4005: 'DXGI_STATUS_MODE_CHANGE_IN_PROGRESS' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49503) : 'DXGI_STATUS_MODE_CHANGE_IN_PROGRESS' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(21): warning C4005: 'DXGI_ERROR_INVALID_CALL' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49518) : 'DXGI_ERROR_INVALID_CALL' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(22): warning C4005: 'DXGI_ERROR_NOT_FOUND' : 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(26): warning C4005: 'DXGI_ERROR_DEVICE_HUNG' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49563) : 'DXGI_ERROR_DEVICE_HUNG' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(27): warning C4005: 'DXGI_ERROR_DEVICE_RESET' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49573) : 請'DXGI_ERROR_DEVICE_RESET' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(28): warning C4005: 'DXGI_ERROR_WAS_STILL_DRAWING' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49582) : 請'DXGI_ERROR_WAS_STILL_DRAWING' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(29): warning C4005: 'DXGI_ERROR_FRAME_STATISTICS_DISJOINT' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49592) : 請'DXGI_ERROR_FRAME_STATISTICS_DISJOINT' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(30): warning C4005: 'DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49601) : 'DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(33): warning C4005: 'DXGI_ERROR_NOT_CURRENTLY_AVAILABLE' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49629) :'DXGI_ERROR_NOT_CURRENTLY_AVAILABLE' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(34): warning C4005: 'DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49639) : 'DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(35): warning C4005: 'DXGI_ERROR_REMOTE_OUTOFMEMORY' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49648) : 'DXGI_ERROR_REMOTE_OUTOFMEMORY' 1>c:\program files\microsoft directx sdk (june 2010)\include\d3d10.h(608): warning C4005: 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49793) : 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS' 1>c:\program files\microsoft directx sdk (june 2010)\include\d3d10.h(609): warning C4005: 'D3D10_ERROR_FILE_NOT_FOUND' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49802) : 1>c:\users\peter\documents\visual studio 2012\projects\win32project2\win32project2\source.cpp(16): error C4430: 1>c:\users\peter\documents\visual studio 2012\projects\win32project2\win32project2\source.cpp(16): error C2146: 1>c:\users\peter\documents\visual studio 2012\projects\win32project2\win32project2\source.cpp(16): warning C4244: 1>c:\users\peter\documents\visual studio 2012\projects\win32project2\win32project2\source.cpp(190): error C2664: 'ID3D10Device::ClearRenderTargetView' :

Mountainous answered 12/10, 2013 at 17:1 Comment(0)
H
11

Those aren't really errors, but warnings. Still, they make feel you bad =)

Microsoft deprecation style

DirectX SDK has been merged into Windows SDK (starting with Windows 8 SDK). Some of the functionality has been deprecated and removed.

You are mixing 2 SDKs:

  • Old DirectX SDK in c:\program files\microsoft directx sdk (june 2010)\include\
  • New Windows SDK in c:\program files\windows kits\8.0\include\shared\

It is not recommended to use DirectX SDK headers or libraries in new project. So, in project settings -> "VC++ Directories" -> "Include Directories" remove references to DirectX SDK.

If you still need some old functionality (for example to compile old tutorial samples, or an old project), include DirectX SDK headers, but change in project settings -> "General" -> "Platform Toolset" to "Visual Studio 2012 - Windows XP (v110_xp)".

Want to know more? Yes / No.

Hadhramaut answered 12/10, 2013 at 18:29 Comment(6)
The instructions for successfully mixing the Windows 8 SDK (which comes with VS 2012) and the legacy DirectX SDK are covered on MSDN, but as noted by Drop ideally you shouldn't use the legacy DirectX SDK.Ryeland
You can use Direct3D 10, but there's no reason to use Direct3D 10. You should use Direct3D 11. Direct3D 11 supports everything that Direct3D 10 does plus more, and is better supported by modern utility code.Ryeland
For more on Drop's comment about the v110_xp platform toolset, see this blog post.Ryeland
@ChuckWalbourn Hi!, I know that you along with Alex St. John were pioneers of DirectX, I'm happy to have you here. I'm learning DX7 so I got some old projects built correctly with VS2015 (Win7) and one of those is this very OP C++ but now I'm having hard time trying to compile the project at bottom of this site, I tried adding all d3d...h headers as advised here, but just get C2511 _D3DVECTOR overloaded member function not found, please help.Leasia
@Ivanzinho Why in particular are you focused on such an ancient version of DirectX? No idea if headers that old build with VS 2015. I think Microsoft last supported DX7 headers with VS 2008. The answer I gave assumes you are using the DirectX SDK June 2010 which supports DirectX 9.0c development with legacy D3DX9.Ryeland
@ChuckWalbourn initially I tried GLUT and FreeGLUT (paradoxically I learned C by using those) and the opponent of that age was DX7, furthermore I saw a Nintendo64 emulator running on Win98 requiring DX7, I was overwhelmed so I always wanted to know how to make that, it's like I'm involved in retro computing. I compiled this OP C++ code using DX SDK August 2007 which includes old header files (I found this info in your website too) and I also have compiled other ancient projects but this one is killing me.Leasia

© 2022 - 2024 — McMap. All rights reserved.