Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 233. DirectX 9 예제 프로젝트 빌드하는 방법 [링크 복사], [링크+제목 복사],
조회: 51179
글쓴 사람
정성태 (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)
13412정성태9/14/20237067닷넷: 2142. C# 12 - 인라인 배열(Inline Arrays) [1]
13411정성태9/12/20233560Windows: 252. 권한 상승 전/후 따로 관리되는 공유 네트워크 드라이브 정보
13410정성태9/11/20235096닷넷: 2141. C# 12 - Interceptor (컴파일 시에 메서드 호출 재작성) [1]
13409정성태9/8/20233929닷넷: 2140. C# - Win32 API를 이용한 모니터 전원 끄기
13408정성태9/5/20233902Windows: 251. 임의로 만든 EXE 파일을 포함한 ZIP 파일의 압축을 해제할 때 Windows Defender에 의해 삭제되는 경우
13407정성태9/4/20233625닷넷: 2139. C# - ParallelEnumerable을 이용한 IEnumerable에 대한 병렬 처리
13406정성태9/4/20233608VS.NET IDE: 186. Visual Studio Community 버전의 라이선스
13405정성태9/3/20234022닷넷: 2138. C# - async 메서드 호출 원칙
13404정성태8/29/20233593오류 유형: 876. Windows - 키보드의 등호(=, Equals sign) 키가 눌리지 않는 경우
13403정성태8/21/20233394오류 유형: 875. The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EB3E94ADBE1229CF
13402정성태8/20/20233495닷넷: 2137. ILSpy의 nuget 라이브러리 버전 - ICSharpCode.Decompiler
13401정성태8/19/20233746닷넷: 2136. .NET 5+ 환경에서 P/Invoke의 성능을 높이기 위한 SuppressGCTransition 특성 [1]
13400정성태8/10/20233582오류 유형: 874. 파이썬 - pymssql을 윈도우 환경에서 설치 불가
13399정성태8/9/20233513닷넷: 2135. C# - 지역 변수로 이해하는 메서드 매개변수의 값/참조 전달
13398정성태8/3/20234353스크립트: 55. 파이썬 - pyodbc를 이용한 SQL Server 연결 사용법
13397정성태7/23/20233835닷넷: 2134. C# - 문자열 연결 시 string.Create를 이용한 GC 할당 최소화
13396정성태7/22/20233618스크립트: 54. 파이썬 pystack 소개 - 메모리 덤프로부터 콜 스택 열거
13395정성태7/20/20233494개발 환경 구성: 685. 로컬에서 개발 중인 ASP.NET Core/5+ 웹 사이트에 대해 localhost 이외의 호스트 이름으로 접근하는 방법
13394정성태7/16/20233473오류 유형: 873. Oracle.ManagedDataAccess.Client - 쿼리 수행 시 System.InvalidOperationException
13393정성태7/16/20233645닷넷: 2133. C# - Oracle 데이터베이스의 Sleep 쿼리 실행하는 방법
13392정성태7/16/20233540오류 유형: 872. Oracle - ORA-01031: insufficient privileges
13391정성태7/14/20233563닷넷: 2132. C# - sealed 클래스의 메서드를 callback 호출했을 때 인라인 처리가 될까요?
13390정성태7/12/20233500스크립트: 53. 파이썬 - localhost 호출 시의 hang 현상
13389정성태7/5/20233545개발 환경 구성: 684. IIS Express로 호스팅하는 웹을 WSL 환경에서 접근하는 방법
13388정성태7/3/20233690오류 유형: 871. 윈도우 탐색기에서 열리지 않는 zip 파일 - The Compressed (zipped) Folder '[...].zip' is invalid. [1]파일 다운로드1
13387정성태6/28/20233744오류 유형: 870. _mysql - Commands out of sync; you can't run this command now
1  2  3  4  5  6  7  8  [9]  10  11  12  13  14  15  ...