locked
Unresolved externals when trying to access DirectX from XAML

    Question

  • I am trying to create a hello world application which uses DirectX from XAML. I am working based on this guide: http://msdn.microsoft.com/en-us/library/windows/apps/hh825871.aspx and this sample: http://code.msdn.microsoft.com/windowsapps/Magazine-Sample-2a657289.

    I created the default Blank Application C++ Metro-style template, and I started writing the DirectX code in the code behind of BlankPage.xaml.cs (this is just for the sake of testing). I've written some of the initialization code given in the guide and the sample, however, when I try to build, I get the following two build errors:

    Error 1 error LNK2019: unresolved external symbol _D3D11CreateDevice@40 referenced in function "protected: virtual void __cdecl XamlDirectXTest2::BlankPage::OnNavigatedTo(class Windows::UI::Xaml::Navigation::NavigationEventArgs ^)" (?OnNavigatedTo@BlankPage@XamlDirectXTest2@@M$AAAXP$AAVNavigationEventArgs@Navigation@Xaml@UI@Windows@@@Z) c:\Users\Mark\documents\visual studio 11\Projects\XamlDirectXTest2\XamlDirectXTest2\BlankPage.xaml.obj XamlDirectXTest2

    Error 2 error LNK1120: 1 unresolved externals c:\users\mark\documents\visual studio 11\Projects\XamlDirectXTest2\Debug\XamlDirectXTest2\XamlDirectXTest2.exe 1 1 XamlDirectXTest2

    My pch.h file:

    #pragma once
    
    #include <objidl.h>
    #include <strsafe.h>
    #include <wrl.h>
    #include <windows.ui.xaml.media.dxinterop.h>
    #include <ppltasks.h>
    #include <initguid.h>
    #include <d3d11.h>
    #include <d3d11_1.h>
    #include <dxgi1_2.h>
    #include <d2d1_1.h>
    #include <d2d1effects.h>
    #include <dwrite_1.h>
    #include <wincodec.h>
    
    using namespace Microsoft::WRL;
    
    #include "App.xaml.h"

    I don't know whether it matters, but here is the code in the code behind (this does not draw anything yet, I just want to get it to compile):

    SurfaceImageSource^ surfaceImageSource = ref new SurfaceImageSource(200, 200);
    	
    ComPtr<ISurfaceImageSourceNative> sisNative;
    IInspectable* sisInspectable = (IInspectable*) reinterpret_cast<IInspectable*>(surfaceImageSource);
    sisInspectable->QueryInterface(__uuidof(ISurfaceImageSourceNative), (void **)&sisNative);
    
    ComPtr<ID3D11Device> d3dDevice;
    ComPtr<ID3D11DeviceContext> d3dContext;
    
    UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
    
    #if defined(_DEBUG)
    creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
    #endif
    
    D3D_FEATURE_LEVEL featureLevels[] = 
    {
        D3D_FEATURE_LEVEL_11_1,
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
    	D3D_FEATURE_LEVEL_9_3,
        D3D_FEATURE_LEVEL_9_2,
        D3D_FEATURE_LEVEL_9_1
    };
    
    D3D11CreateDevice(
    	NULL,
    	D3D_DRIVER_TYPE_HARDWARE,
    	NULL,
    	creationFlags,//flags,
    	featureLevels,
    	ARRAYSIZE(featureLevels),
    	D3D11_SDK_VERSION,
    	&d3dDevice,
    	NULL,
    	&d3dContext);
    
    ComPtr<IDXGIDevice> dxgiDevice;
    d3dDevice.As(&dxgiDevice);
    sisNative->SetDevice(dxgiDevice.Get());
    
    ComPtr<IDXGISurface> surface;
    
    RECT bounds;
    bounds.left = 10;
    bounds.right = 200;
    bounds.top = 10;
    bounds.bottom = 200;
    
    POINT offset;
    
    HRESULT beginDrawHR = sisNative->BeginDraw(bounds, &surface, &offset);
    if(beginDrawHR == DXGI_ERROR_DEVICE_REMOVED || beginDrawHR == DXGI_ERROR_DEVICE_RESET)
    {
    
    }
    else
    {
    		
    }
    
    sisNative->EndDraw();

    What can be the problem? Do I have to add a reference of some kind? I am quite new to C++, so I might made some beginner mistake.

    Thanks.

    Friday, March 09, 2012 11:12 AM

Answers

  • It seems I found the solution: some additional libs had to be added to the Linker settings on the properties page: "d2d1.lib;d3d11.lib;dxgi.lib;windowscodecs.lib;dwrite.lib" (I don't know whether all of these are needed, but these were in the sample Magazine app)

    • Proposed as answer by Jesse Jiang Monday, March 12, 2012 7:27 AM
    • Marked as answer by MarkVincze Tuesday, March 13, 2012 10:12 AM
    Friday, March 09, 2012 11:24 AM

All replies

  • It seems I found the solution: some additional libs had to be added to the Linker settings on the properties page: "d2d1.lib;d3d11.lib;dxgi.lib;windowscodecs.lib;dwrite.lib" (I don't know whether all of these are needed, but these were in the sample Magazine app)

    • Proposed as answer by Jesse Jiang Monday, March 12, 2012 7:27 AM
    • Marked as answer by MarkVincze Tuesday, March 13, 2012 10:12 AM
    Friday, March 09, 2012 11:24 AM
  • Hello,

    As far as I know, there is a Metro DirectX project template in Visual Studio 2011 Beta. You can create your DirectX project from that template next time.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 12, 2012 7:27 AM