Building RenderSystem_Direct3D9 with Visual Studio 2015

Problems building or running the engine, queries about how to use features etc.
Post Reply
PBY
Halfling
Posts: 47
Joined: Tue Jul 16, 2013 12:57 pm
x 1

Building RenderSystem_Direct3D9 with Visual Studio 2015

Post by PBY »

As some have already seen, RenderSystem_Direct3D9 don't link when building with Visual Studio 2015:

Code: Select all

DxErr.lib(dxerra.obj) : error LNK2019: unresolved external symbol _vsnprintf referenced in function "long __cdecl StringVPrintfWorkerA(char *,unsigned __int64,unsigned __int64 *,char const *,char *)" (?StringVPrintfWorkerA@@YAJPEAD_KPEA_KPEBD0@Z)
Sure, DxErr.lib was build (DirectX SDK June 2010) with an older version of VS. But _vsnprintf is still there: https://msdn.microsoft.com/en-us/library/1kt27hek.aspx

And removing

Code: Select all

#include <DxErr.h>
in OgreD3D9Prerequisites.h don't help (it must be included by other DirectX headers).

Was anyone able to resolve this issue? Or are we stuck to use VS2013 forever (Microsoft only support DirectX 9 in WPF :evil: )
GrafZahl
Gnoblar
Posts: 10
Joined: Wed Sep 02, 2015 5:12 pm

Re: Building RenderSystem_Direct3D9 with Visual Studio 2015

Post by GrafZahl »

Hello,

I have exactly the same issue by using VS2015. Is there any workaround available?

Best regards,
GrafZahl
GrafZahl
Gnoblar
Posts: 10
Joined: Wed Sep 02, 2015 5:12 pm

Re: Building RenderSystem_Direct3D9 with Visual Studio 2015

Post by GrafZahl »

Hi again,

I think I found a workaround. The issue is, that the DX9 SDK is compiled with a much older version of visual studio and static libraries are not fully compatible to each other. Unfortunately M$ does not support this old SDK for new compilers, so the only way is to recompile the dxerr library by yourself. Of course you cannot access the original code from M$, but there is a very interesting wrapper available, that make the original dxerr.h functions available by using inside the new FormatMessage function instead of vprintf.

This is the link to the blog and files: http://blogs.msdn.com/b/chuckw/archive/ ... r-lib.aspx
(you find the files as ZIP at the end of this blog entry, copy them to a folder named "src" and use cmake with the following cmake file to compile a dxerr.lib out of it)

cmake-file:

Code: Select all

# -*- cmake -*-
cmake_minimum_required(VERSION 3.3)
PROJECT(dxerr)

## section: include directory
#INCLUDE_DIRECTORIES(
#  includes
#  src
#  )

## section: source files
# Add your source files here (one file per line), please SORT in alphabetical order for future maintenance
SET (DXERR_SOURCE_FILES
	src/dxerr.cpp
	)

## section: header files
# Add your header files here(one file per line), please SORT in alphabetical order for future maintenance!
SET(DXERR_HEADER_FILES
	src/dxerr.h
	)

SET_SOURCE_FILES_PROPERTIES(DXERR_HEADER_FILES
                            PROPERTIES HEADER_FILE_ONLY TRUE)
LIST(APPEND DXERR_SOURCE_FILES ${DXERR_HEADER_FILES})

## section: add definitions
# 	add prefix -D. example> -DSHP
#  - DO NOT add  the following definitions(already defined in ${OSP_DEFINITIONS}:
# 	-DSHP, -DWIN32, -D_WINDOWS, -D_DEBUG, -D_USRDLL, -D_CRT_SECURE_NO_DEPRECATE
ADD_DEFINITIONS(
	-D_LIB;-D_STLP_DEBUG;
	)

## section: add target
ADD_LIBRARY (dxerr ${DXERR_SOURCE_FILES} )

## section: add dependency
# dependency determines overall build order.
#ADD_DEPENDENCIES(${this_target} dxguid dinput8 xinput)
		
INSTALL(TARGETS dxerr
		ARCHIVE DESTINATION  "lib" CONFIGURATIONS Debug Release MinSizeRel RelWithDebInfo
		LIBRARY DESTINATION  "lib" CONFIGURATIONS Debug Release MinSizeRel RelWithDebInfo
		RUNTIME DESTINATION  "bin" CONFIGURATIONS Debug Release MinSizeRel RelWithDebInfo
		)
INSTALL(FILES ${DXERR_HEADER_FILES} DESTINATION "includes")		
Unfortunately DXGetErrorDescription function prototype is different here and Ogre3D is using the non Unicode-Function, that is not supported by this dxerr-wrapper.
However I was able to adapt the wrapper code in a way that it fits to the original prototype and I also added a non Unicode version.
Due to license reasons I cannot offer the full code to you, but as a fast solution you can simply use a static WCHAR[32000] array inside the function and return the pointer to that array. This is not a nice approach but the easiest one.
For adapting to non-Unicode, you can use this code (is also using a static array):

Code: Select all

const char*  WINAPI DXGetErrorDescriptionA(__in HRESULT hr)
{
	WCHAR const * pUnicodeStr = DXGetErrorDescriptionW(hr);
	static char ASCIIStr[32000];
	wcstombs(ASCIIStr, pUnicodeStr, 31999);
	return ASCIIStr;
}
I think for a first approach this is ok. Later I should have another look here to implement it in a more clean way.

BTW: Remember to add the ifdef/else/endif for the #define DXGetErrorDescription to the wrapper header like it was in the original DX9 dxerr.h
PBY
Halfling
Posts: 47
Joined: Tue Jul 16, 2013 12:57 pm
x 1

Re: Building RenderSystem_Direct3D9 with Visual Studio 2015

Post by PBY »

It sound quite good, I will try it when I have some time (we are now releasing a new version of our software, and we will make the complete switch to VS2015 after that, if Ogre compiles).

As FormatMessage seems to be the official Microsoft solution when DXErr disappears from Directx in Windows 8, this wrapper should be the best way to still use DirectX9.

Thanks a lot.
Pellaeon
Goblin
Posts: 230
Joined: Thu Apr 28, 2011 12:23 pm
x 28

Re: Building RenderSystem_Direct3D9 with Visual Studio 2015

Post by Pellaeon »

User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Building RenderSystem_Direct3D9 with Visual Studio 2015

Post by c6burns »

You just linked the thread your own post is in. I'm sure that doesn't help.
nickygs
Gnoblar
Posts: 15
Joined: Wed Jul 20, 2016 7:55 pm

Re: Building RenderSystem_Direct3D9 with Visual Studio 2015

Post by nickygs »

There is a section covering this issue here http://www.aupcgroup.com/blog/index.php ... -2015.html
Post Reply