Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 233. DirectX 9 예제 프로젝트 빌드하는 방법 [링크 복사], [링크+제목 복사],
조회: 51172
글쓴 사람
정성태 (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)
13310정성태4/6/20234155C/C++: 162. Visual Studio - /NODEFAULTLIB 옵션 설정 후 수동으로 추가해야 할 library
13309정성태4/5/20234303.NET Framework: 2107. .NET 6+ FileStream의 구조 변화
13308정성태4/4/20234202스크립트: 47. 파이썬의 time.time() 실숫값을 GoLang / C#에서 사용하는 방법
13307정성태4/4/20233955.NET Framework: 2106. C# - .NET Core/5+ 환경의 Windows Forms 응용 프로그램에서 HINSTANCE 구하는 방법
13306정성태4/3/20233730Windows: 243. Win32 - 윈도우(cbWndExtra) 및 윈도우 클래스(cbClsExtra) 저장소 사용 방법
13305정성태4/1/20234125Windows: 242. Win32 - 시간 만료를 갖는 MessageBox 대화창 구현 (쉬운 버전)파일 다운로드1
13304정성태3/31/20234439VS.NET IDE: 181. Visual Studio - C/C++ 프로젝트에 application manifest 적용하는 방법
13303정성태3/30/20233815Windows: 241. 환경 변수 %PATH%에 DLL을 찾는 규칙
13302정성태3/30/20234443Windows: 240. RDP 환경에서 바뀌는 %TEMP% 디렉터리 경로
13301정성태3/29/20234570Windows: 239. C/C++ - Windows 10 Version 1607부터 지원하는 /DEPENDENTLOADFLAG 옵션파일 다운로드1
13300정성태3/28/20234209Windows: 238. Win32 - Modal UI 창에 올바른 Owner(HWND)를 설정해야 하는 이유
13299정성태3/27/20233966Windows: 237. Win32 - 모든 메시지 루프를 탈출하는 WM_QUIT 메시지
13298정성태3/27/20233947Windows: 236. Win32 - MessageBeep 소리가 안 들린다면?
13297정성태3/26/20234609Windows: 235. Win32 - Code Modal과 UI Modal
13296정성태3/25/20233930Windows: 234. IsDialogMessage와 협업하는 WM_GETDLGCODE Win32 메시지 [1]파일 다운로드1
13295정성태3/24/20234204Windows: 233. Win32 - modeless 대화창을 modal처럼 동작하게 만드는 방법파일 다운로드1
13294정성태3/22/20234375.NET Framework: 2105. LargeAddressAware 옵션이 적용된 닷넷 32비트 프로세스의 가용 메모리 - 두 번째
13293정성태3/22/20234441오류 유형: 853. dumpbin - warning LNK4048: Invalid format file; ignored
13292정성태3/21/20234553Windows: 232. C/C++ - 일반 창에도 사용 가능한 IsDialogMessage파일 다운로드1
13291정성태3/20/20234947.NET Framework: 2104. C# Windows Forms - WndProc 재정의와 IMessageFilter 사용 시의 차이점
13290정성태3/19/20234426.NET Framework: 2103. C# - 윈도우에서 기본 제공하는 FindText 대화창 사용법파일 다운로드1
13289정성태3/18/20233634Windows: 231. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 자식 윈도우를 생성하는 방법파일 다운로드1
13288정성태3/17/20233745Windows: 230. Win32 - 대화창의 DLU 단위를 pixel로 변경하는 방법파일 다운로드1
13287정성태3/16/20233923Windows: 229. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 윈도우를 직접 띄우는 방법파일 다운로드1
13286정성태3/15/20234365Windows: 228. Win32 - 리소스에 포함된 대화창 Template의 2진 코드 해석 방법
13285정성태3/14/20233936Windows: 227. Win32 C/C++ - Dialog Procedure를 재정의하는 방법파일 다운로드1
1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...