Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 233. DirectX 9 예제 프로젝트 빌드하는 방법 [링크 복사], [링크+제목 복사],
조회: 51184
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 1개 있습니다.)

DirectX 9 예제 프로젝트 빌드하는 방법

아래와 같은 질문이 있군요.

WPF 에서 native dll 임포트가 불가능한가요? 
; http://lab.gamecodi.com/board/zboard.php?id=GAMECODILAB_QnA_etc&no=3136&z=

CodeProject에 공개된 닷넷 + native 예제가,

Introduction to D3DImage
; http://www.codeproject.com/Articles/28526/Introduction-to-D-DImage

실행이 안된다는 것인데요. 저도 해당 글에서 컴파일된 바이너리를 실행해 보니 오류가 발생합니다. 그래서 소스 코드를 다운로드 받았는데요.

Download sample - 360 KB
; http://www.codeproject.com/KB/WPF/D3DImage/D3DImageSample.zip

아쉽게도 빌드가 안됩니다. d3dx9.h 헤더 파일이 없다고 나옵니다.

error C1083: Cannot open include file: 'd3dx9.h': No such file or directory c:\...\d3d\d3dimagesample\d3dimagesample\d3dscene\main.cpp

어쩔 수 없죠. ^^ DirectX SDK를 다운로드 받아 설치했습니다.

DirectX Software Development Kit 
; http://www.microsoft.com/en-us/download/details.aspx?id=6812

참고로, 현재 대부분의 개발자 컴퓨터에서는 DirectX SDK (June 2010)을 설치하면 S1023 오류가 발생할 것입니다. 이에 대해서는 다음의 글을 보시고 해결하면 됩니다.

DXSDK_Jun10.exe 설치 시 "Error Code: S1023" 오류 해결하는 방법
; https://www.sysnet.pe.kr/2/0/1195

물론 이렇게 해도 빌드가 안됩니다. 왜냐하면 D3DScene C++ 프로젝트의 include/lib 폴더 경로를 프로젝트 설정에서 DirectX SDK 설치 경로를 포함해 주어야 하기 때문입니다.

[include 경로]
d3d_compile_1.png

[x86 라이브러리 경로]
d3d_compile_2.png

여기까지 맞춰주면 D3DImageSample 솔루션 파일이 전체적으로 컴파일이 잘 됩니다. 하지만 실행하면 다음과 같은 오류가 발생합니다.

System.Windows.Markup.XamlParseException occurred
  IsTransient=false
  Message=Cannot create instance of 'Window1' defined in assembly 'D3DImageSample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error in markup file 'Window1.xaml' Line 1 Position 9.
  Source=PresentationFramework
  LineNumber=1
  LinePosition=9
  StackTrace:
       at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
  InnerException: System.Reflection.TargetInvocationException
       _HResult=-2146232828
       _message=Exception has been thrown by the target of an invocation.
       IsTransient=false
       Message=Exception has been thrown by the target of an invocation.
       Source=mscorlib
       StackTrace:
            at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
            at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
            at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
            at System.Activator.CreateInstance(Type type, Boolean nonPublic)
            at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
       InnerException: System.BadImageFormatException
            _HResult=-2147024885
            _message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
            IsTransient=false
            Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
            Source=D3DImageSample
            StackTrace:
                 at D3DImageSample.Window1.InitializeScene()
                 at D3DImageSample.Window1.BeginRenderingScene() in c:\Users\SeongTae\Dropbox\articles\d3d\D3DImageSample\D3DImageSample\D3DImageSample\Window1.xaml.cs:line 82
                 at D3DImageSample.Window1..ctor() in c:\Users\SeongTae\Dropbox\articles\d3d\D3DImageSample\D3DImageSample\D3DImageSample\Window1.xaml.cs:line 54
            InnerException: 

중요한 것은 InnerException에 있는 "System.BadImageFormatException" 예외입니다. 즉, D3DImageSample 닷넷 프로젝트의 타겟이 "AnyCPU"로 되어 있는데 우리가 컴파일한 D3DScene C++ 프로젝트는 x86으로 되어 있기 때문입니다. 따라서 D3DImageSample 프로젝트의 속성 창에서 "Build" / "Platform target"을 "x86"으로 설정하고 실행하면 다음과 같이 아주 잘 실행됩니다.

d3d_compile_3.png

(첨부한 프로젝트는 "Introduction to D3DImage" 예제를 제가 테스트 하느라 Visual Studio 2013 프로젝트로 마이그레이션한 것입니다.)




"Introduction to D3DImage" 글에 포함된 바이너리가 실행이 안된 이유는 간단합니다. 해당 바이너리에 포함된 D3DScene.dll 파일이 d3dx9d_38.dll에 의존하고 있는데 제 컴퓨터에는 해당 파일이 없기 때문에 오류가 나는 듯 싶습니다. "DirectX Software Development Kit" 설치 후 확인해 보니 d3dx9d_33.dll과 d3dx9d_43.dll이 설치됩니다.

참고로 닷넷 응용 프로그램과 Native C++ 프로젝트의 코드에 모두 BP(BreakPoint)를 걸어 테스트하고 싶다면 EXE 측 (이 예제에서는 D3DImageSample이므로) 프로젝트의 속성 창에서 "Debug" / "Enable native code debugging" 옵션을 켜놓으면 PDB 로딩하느라 디버깅 시작 시간은 길어져도 Managed/Native 모두 디버깅이 가능합니다.

그나저나... 저는 언제까지 컴파일만 해보는 걸까요? 저도 마음만은 언제나 현란하게 3D 그래픽을 가지고 놀고 싶답니다. ^^;




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/23/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2014-08-21 12시38분
1. Setting up the base project with DirectX and DirectTK
; http://blogs.msdn.com/b/tess/archive/2014/08/13/bizzy-bees-xna-to-directx-directxtk-part-1.aspx

2. Creating the game assets (sprites and fonts)
; http://blogs.msdn.com/b/tess/archive/2014/08/13/bizzy-bees-xna-to-directx-directxtk-part-2.aspx

3. Drawing the scene ? Background/Foreground/HUD
; http://blogs.msdn.com/b/tess/archive/2014/08/13/bizzy-bees-xna-to-directx-directxtk-part-3.aspx

4. Adding flowers
; http://blogs.msdn.com/b/tess/archive/2014/08/13/bizzy-bees-xna-to-directx-directxtk-part-4.aspx

5. Making things move
; http://blogs.msdn.com/b/tess/archive/2014/08/13/bizzy-bees-xna-to-directx-directxtk-part-5.aspx

6. Adding bees
; http://blogs.msdn.com/b/tess/archive/2014/08/13/bizzy-bees-xna-to-directx-directxtk-part-6.aspx

7. User Interaction
; http://blogs.msdn.com/b/tess/archive/2014/08/13/bizzy-bees-xna-to-directx-directxtk-part-7.aspx

8. Tidying up and adding finishing touches
; http://blogs.msdn.com/b/tess/archive/2014/08/13/bizzy-bees-xna-to-directx-directxtk-part-8.aspx
정성태
2016-08-31 12시29분
WPF에서 DirectX 렌더링 예제
; http://blog.naver.com/sogangori/220800291624
정성태
2016-10-27 12시45분
윈도우 8 이후 버전에서 DirectX 11사용하기 (Converting legacy code in DirectX 11 to use it in windows 8 or higher version like windows 10)
; http://blog.naver.com/sorkelf/220846504837
정성태

1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13515정성태1/6/20242619닷넷: 2195. async 메서드 내에서 C# 7의 discard 구문 활용 사례 [1]
13514정성태1/5/20242304개발 환경 구성: 702. IIS - AppPool의 "Disable Overlapped Recycle" 옵션
13513정성태1/5/20242223닷넷: 2194. C# - WebActivatorEx / System.Web의 PreApplicationStartMethod 특성
13512정성태1/4/20242175개발 환경 구성: 701. IIS - w3wp.exe 프로세스의 ASP.NET 런타임을 항상 Warmup 모드로 유지하는 preload Enabled 설정
13511정성태1/4/20242197닷넷: 2193. C# - ASP.NET Web Application + OpenAPI(Swashbuckle) 스펙 제공
13510정성태1/3/20242120닷넷: 2192. C# - 특정 실행 파일이 있는지 확인하는 방법 (Linux)
13509정성태1/3/20242169오류 유형: 887. .NET Core 2 이하의 프로젝트에서 System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0.
13508정성태1/3/20242219오류 유형: 886. ORA-28000: the account is locked
13507정성태1/2/20242865닷넷: 2191. C# - IPGlobalProperties를 이용해 netstat처럼 사용 중인 Socket 목록 구하는 방법파일 다운로드1
13506정성태12/29/20232454닷넷: 2190. C# - 닷넷 코어/5+에서 달라지는 System.Text.Encoding 지원
13505정성태12/27/20232982닷넷: 2189. C# - WebSocket 클라이언트를 닷넷으로 구현하는 예제 (System.Net.WebSockets)파일 다운로드1
13504정성태12/27/20232571닷넷: 2188. C# - ASP.NET Core SignalR로 구현하는 채팅 서비스 예제파일 다운로드1
13503정성태12/27/20232439Linux: 67. WSL 환경 + mlocate(locate) 도구의 /mnt 디렉터리 검색 문제
13502정성태12/26/20232553닷넷: 2187. C# - 다른 프로세스의 환경변수 읽는 예제파일 다운로드1
13501정성태12/25/20232321개발 환경 구성: 700. WSL + uwsgi - IPv6로 바인딩하는 방법
13500정성태12/24/20232413디버깅 기술: 194. Windbg - x64 가상 주소를 물리 주소로 변환
13498정성태12/23/20233099닷넷: 2186. 한국투자증권 KIS Developers OpenAPI의 C# 래퍼 버전 - eFriendOpenAPI NuGet 패키지
13497정성태12/22/20232494오류 유형: 885. Visual Studiio - error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.
13496정성태12/21/20232484Linux: 66. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (gdb)
13495정성태12/20/20232414Linux: 65. clang++로 공유 라이브러리의 -static 옵션 빌드가 가능할까요?
13494정성태12/20/20232583Linux: 64. Linux 응용 프로그램의 (C++) so 의존성 줄이기(ReleaseMinDependency) - 두 번째 이야기
13493정성태12/19/20232711닷넷: 2185. C# - object를 QueryString으로 직렬화하는 방법
13492정성태12/19/20232383개발 환경 구성: 699. WSL에 nopCommerce 예제 구성
13491정성태12/19/20232267Linux: 63. 리눅스 - 다중 그룹 또는 사용자를 리소스에 권한 부여
13490정성태12/19/20232399개발 환경 구성: 698. Golang - GLIBC 의존을 없애는 정적 빌드 방법
13489정성태12/19/20232178개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...