Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 233. DirectX 9 예제 프로젝트 빌드하는 방법 [링크 복사], [링크+제목 복사],
조회: 51177
글쓴 사람
정성태 (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)
13488정성태12/18/20232112오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
13487정성태12/16/20232415개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행 [1]
13486정성태12/15/20232229개발 환경 구성: 695. Nuget config 파일에 값 설정/삭제 방법
13485정성태12/15/20232121오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/20232201개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/20232334닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/20233004닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/20232309개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/20232701개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/20232373개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232621닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232311닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/20232407닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/20232227개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232494닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232249C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232347Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232679닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232440닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232335닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232434오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232608닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232344개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232489닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232401오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
13462정성태11/27/20232414오류 유형: 880. Visual Studio - error CS0246: The type or namespace name '...' could not be found
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...