Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get a lot of macro redefinition when using Directx 10

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' :

like image 790
user2874454 Avatar asked Oct 12 '13 17:10

user2874454


1 Answers

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.

like image 141
Ivan Aksamentov - Drop Avatar answered Oct 06 '22 00:10

Ivan Aksamentov - Drop