-1

i have a very specific coding problem with my engine. i've been following a book on how to programm an engine but now i wrote down the code(not the whole code, but only the necessary parts for it to start working.). but now i have to concert something really wierd, could anybody help me? Note: that this a directx 11 game engine i'm talking about. Thanks already.

The error is: 1 IntelliSense: argument of type "const wchar_t *" is incompatible with parameter of type "const char *"

and my code is: Header file:

 #ifndef ERROR_CHECKER_H
   #define ERROR_CHECKER_H
   #include "main.cpp"

   #if defined(DEBUG) ||defined (_DEBUG)
   #define _CRTDBG_MAP_ALLOC
   #include <crtdbg.h>
   #endif

   #if defined(DEBUG) | defined(_DEBUG)
          #ifndef HR
          #define HR(x)                                         \
          {                                                     \
              HRESULT hr = (x);                                 \
              if (FAILED(hr))                                   \
              {                                                 \
              DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true);\
              }                                                 \
          }
          #endif
          #else
          #ifndef HR
          #define HR(x) (x)
    #endif
    #endif

   #endif ERROR_CHECKER_H

The main.cpp file:

    #include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>
#include <DXErr.h>
#include <xnamath.h>
#include <iostream>
#include <string> 
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <vector>
#include "Tools.h"
#include "GameTimerClass.h"
#include "Error checker.h"

And the code where the problem is:

    void Framework_App::OnResize()
{
    assert(MainDevContext);
    assert(MainD3DDevice);
    assert(mSwapChain);

    ReleaseCOM(mRenderTargetView);
    ReleaseCOM(mDepthStencilView);
    ReleaseCOM(mDepthStencilBuffer);

    HR(mSwapChain->ResizeBuffers(1, mClientWitdh, mClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
}

}

I've build the same class to do resizes and other functions but up until this function there was no problem.

This string of the code is the problem:

HR(mSwapChain->ResizeBuffers(1, mClientWitdh, mClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
PVermillion
  • 11
  • 1
  • 3
  • 1
    The error message is pretty self-explanatory. Something takes a `char const*` but you're actually passing it a `wchar_t const*`. `DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true);` looks like the problem. Change that `L#x` to `#x`. – Simple Jul 24 '14 at 13:43
  • 1
    http://stackoverflow.com/questions/3227270/how-to-convert-wchar-t-to-char – Ricky Mutschlechner Jul 24 '14 at 13:44

1 Answers1

1

The definition of your HR macro is assuming you are using UNICODE rather than ASCII, but the legacy DirectX SDK (June 2010) version of DXERR.H has defined DXTrace as the ASCII version (DXTraceA) because you don't have UNICODE defined in your project.

HRESULT WINAPI DXTraceA( __in_z const char* strFile, __in DWORD dwLine, __in HRESULT hr, __in_z_opt const char* strMsg, __in BOOL bPopMsgBox );
HRESULT WINAPI DXTraceW( __in_z const char* strFile, __in DWORD dwLine, __in HRESULT hr, __in_z_opt const WCHAR* strMsg, __in BOOL bPopMsgBox );

#ifdef UNICODE
#define DXTrace DXTraceW
#else
#define DXTrace DXTraceA
#endif 

To make your HR macro robust for both cases you'd either have two versions of your HR macro, or you can explicitly call DXTraceW in your HR implementation with "L#x" or DXTraceA with "#x". Preferring the UNICODE version is better.

DXTraceW(__FILE__, (DWORD)__LINE__, hr, L#x, true);\

BTW, all new applications are strongly recommended to use UNICODE only and not ASCII. The various "modern" Microsoft platforms do not support ASCII Win32 APIs.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • The DXERR you are using is the old version from the legacy DirectX SDK (June 2010). You should be sure to read this [blog](http://blogs.msdn.com/b/chuckw/archive/2012/03/22/where-is-the-directx-sdk.aspx) post about the status of the DirectX SDK and the recommended newer Windows 8.x SDK. I have a new version of DXERR with source available (UNICODE only) [here](http://blogs.msdn.com/b/chuckw/archive/2012/04/24/where-s-dxerr-lib.aspx). – Chuck Walbourn Jul 24 '14 at 18:02