Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 233. DirectX 9 예제 프로젝트 빌드하는 방법 [링크 복사], [링크+제목 복사],
조회: 51175
글쓴 사람
정성태 (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)
13539정성태1/26/20242372개발 환경 구성: 703. Visual Studio - launchSettings.json을 이용한 HTTP/HTTPS 포트 바인딩
13538정성태1/25/20242426닷넷: 2211. C# - NonGC(FOH) 영역에 .NET 개체를 생성파일 다운로드1
13537정성태1/24/20242527닷넷: 2210. C# - Native 메모리에 .NET 개체를 생성파일 다운로드1
13536정성태1/23/20242601닷넷: 2209. .NET 8 - NonGC Heap / FOH (Frozen Object Heap) [1]
13535정성태1/22/20242474닷넷: 2208. C# - GCHandle 구조체의 메모리 분석
13534정성태1/21/20242260닷넷: 2207. C# - SQL Server DB를 bacpac으로 Export/Import파일 다운로드1
13533정성태1/18/20242485닷넷: 2206. C# - TCP KeepAlive의 서버 측 구현파일 다운로드1
13532정성태1/17/20242366닷넷: 2205. C# - SuperSimpleTcp 사용 시 주의할 점파일 다운로드1
13531정성태1/16/20242276닷넷: 2204. C# - TCP KeepAlive에 새로 추가된 Retry 옵션파일 다운로드1
13530정성태1/15/20242211닷넷: 2203. C# - Python과의 AES 암호화 연동파일 다운로드1
13529정성태1/15/20242088닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법
13528정성태1/14/20242232Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20242156오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242242닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20242209오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20242296오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20242098오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
13522정성태1/11/20242241닷넷: 2200. C# - HttpClient.PostAsJsonAsync 호출 시 "Transfer-Encoding: chunked" 대신 "Content-Length" 헤더 처리
13521정성태1/11/20242302닷넷: 2199. C# - 한국투자증권 KIS Developers OpenAPI의 WebSocket Ping, Pong 처리
13520정성태1/10/20242072오류 유형: 888. C# - Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`....'
13519정성태1/10/20242129닷넷: 2198. C# - Reflection을 이용한 ClientWebSocket의 Ping 호출파일 다운로드1
13518정성태1/9/20242383닷넷: 2197. C# - ClientWebSocket의 Ping, Pong 처리
13517정성태1/8/20242218스크립트: 63. Python - 공개 패키지를 이용한 위성 이미지 생성 (pystac_client, odc.stac)
13516정성태1/7/20242339닷넷: 2196. IIS - AppPool의 "Disable Overlapped Recycle" 옵션의 부작용
13515정성태1/6/20242618닷넷: 2195. async 메서드 내에서 C# 7의 discard 구문 활용 사례 [1]
13514정성태1/5/20242301개발 환경 구성: 702. IIS - AppPool의 "Disable Overlapped Recycle" 옵션
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...