locked
Why do I get get LNK2019 error? RRS feed

  • Question

  •  

    Hi! I do not understand, why do i get this error here:

    error LNK2019: unresolved external symbol D3DMXCreateTextureFromResourceExW referenced in function "long __cdecl InitVB(void)" (?InitVB@@YAJXZ)

    Everything is linked properly! Why is it wrong?

     

     

    pragma comment(linker, "/nodefaultlib:oldnames.lib")

    #include <windows.h>

    #include <d3dm.h>

    #include <d3dmx.h>

    #include "resource.h"

    #include <aygshell.h>

    //-----------------------------------------------------------------------------

    // Global variables

    //-----------------------------------------------------------------------------

    LPDIRECT3DMOBILE g_pD3DM = NULL; // Used to create the // D3DMDevice

    LPDIRECT3DMOBILEDEVICE g_pd3dmDevice = NULL; // Our rendering // device

    HMODULE g_hRefDLL = NULL; // DLL handle for // d3dmref.dll

    bool g_bUseRef = false; // Flag denoting use // of d3dmref

    LPDIRECT3DMOBILEVERTEXBUFFER g_pVB = NULL; // Buffer to hold // vertices

    LPDIRECT3DMOBILETEXTURE g_pTexture = NULL; // Our texture

    // A structure for our custom vertex type

    struct CUSTOMVERTEX

    {

    FLOAT x, y, z, rhw; // The transformed position for the vertex

    DWORD color; // The vertex color

    float tu, tv;

    };

    // Our custom FVF, which describes our custom vertex structure

    #define D3DMFVF_CUSTOMVERTEX (D3DMFVF_XYZRHW_FLOAT | D3DMFVF_DIFFUSE)

     

     

     

    BOOL IsScreenRotated()

    {

    DEVMODE devMode = {0};

    devMode.dmSize = sizeof(DEVMODE);

    devMode.dmFields = DM_DISPLAYORIENTATION;

    ChangeDisplaySettingsEx(NULL, &devMode, NULL, CDS_TEST, NULL);

    if (devMode.dmDisplayOrientation != DMDO_0)

    {

    MessageBox(

    NULL,

    TEXT("This D3DM sample will not work on a rotated screen.\nThe application will now exit."),

    TEXT("Notice"),

    MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND

    );

    return TRUE;

    }

    return FALSE;

    }

    HRESULT InitD3DM( HWND hWnd )

    {

    // Create the D3DM object, which is needed to create the // D3DMDevice.

    if( NULL == ( g_pD3DM = Direct3DMobileCreate( D3DM_SDK_VERSION ) ) )

    return E_FAIL;

    // Set up the structure used to create the D3DMDevice. Most // parameters are zeroed out. We set Windowed to TRUE, since we want // to do D3DM in a window, and then set the SwapEffect to // "discard", which is the most efficient method of // presenting the back buffer to the display. And we request a back // buffer format that matches the current desktop display

    // format.

    D3DMPRESENT_PARAMETERS d3dmpp;

    memset( &d3dmpp, 0, sizeof(d3dmpp) );

    d3dmpp.Windowed = TRUE;

    d3dmpp.SwapEffect = D3DMSWAPEFFECT_DISCARD;

    d3dmpp.BackBufferFormat = D3DMFMT_UNKNOWN;

    // Create the Direct3D Mobile device.

    UINT uAdapter;

    if (g_bUseRef)

    {

    // Load the D3DM reference driver DLL

    g_hRefDLL = (HMODULE)LoadLibrary(TEXT("d3dmref.dll"));

    if (NULL == g_hRefDLL)

    {

    OutputDebugString(TEXT("Unable to load D3DM reference driver DLL.\n"));

    return E_FAIL;

    }

    // Get the reference driver's entry point

    void* pfnD3DMInit = GetProcAddress(g_hRefDLL, TEXT("D3DM_Initialize"));

    if( NULL == pfnD3DMInit )

    {

    OutputDebugString(TEXT("Unable to retrieve D3DM reference driver entry point.\n"));

    return E_FAIL;

    }

    // Register the software device

    if( FAILED( g_pD3DM->RegisterSoftwareDevice(pfnD3DMInit) ) )

    {

    OutputDebugString(TEXT("Unable to register D3DM reference driver.\n"));

    return E_FAIL;

    }

    uAdapter = D3DMADAPTER_REGISTERED_DEVICE;

    }

    else

    {

    // Use the default system D3DM driver

    uAdapter = D3DMADAPTER_DEFAULT;

    }

    if( FAILED( g_pD3DM->CreateDevice( uAdapter,

    D3DMDEVTYPE_DEFAULT,

    hWnd, 0,

    &d3dmpp, &g_pd3dmDevice ) ) )

    {

    OutputDebugString(TEXT("Unable to create a D3DM device.\n"));

    return E_FAIL;

    }

    // Turn off culling

    g_pd3dmDevice->SetRenderState( D3DMRS_CULLMODE, D3DMCULL_NONE );

    // Turn off D3D lighting

    g_pd3dmDevice->SetRenderState( D3DMRS_LIGHTING, FALSE );

    // Turn on the zbuffer

    // g_pd3dmDevice->SetRenderState( D3DMRS_ZENABLE, TRUE );

    return S_OK;

    }

    //-----------------------------------------------------------------------------

    // Name: InitVB()

    // Desc: Creates a vertex buffer and fills it with our vertices. The // vertex buffer is basically just a chuck of memory that holds // vertices. After creating it, we must Lock()/Unlock() it to // fill it. For indices, D3DM also uses index buffers.

    //-----------------------------------------------------------------------------

    HRESULT InitVB()

    {

    // Initialize three vertices for rendering a triangle

    CUSTOMVERTEX vertices[] =

    {

    { 0.0f, 0.0f, 0.5f, 1.0f, 0x00000000, 0.0f, 0.0f}, // x, y, z, rhw, color

    { 480.0f, 640.0f, 0.5f, 1.0f, 0x00000000, 1.0f, 1.0f },

    { 0.0f, 640.0f, 0.5f, 1.0f, 0x00000000, 0.0f, 1.0f },

    { 0.0f, 0.0f, 0.5f, 1.0f, 0x00000000, 0.0f, 0.0f }, // x, y, z, rhw, color

    { 480.0f, 0.0f, 0.5f, 1.0f, 0xff00ff00, 1.0f, 0.0f },

    { 480.0f, 640.0f, 0.5f, 1.0f, 0xff00ffff, 1.0f, 1.0f }

    };

    //------------------------------------------------------

    // Determine if the device can create textures in video memory

    // by testing the device caps bits.

    D3DMCAPS caps;

    if( FAILED( g_pd3dmDevice->GetDeviceCaps(&caps) ) )

    {

    return E_FAIL;

    }

    D3DMPOOL texpool;

    if (caps.SurfaceCaps & D3DMSURFCAPS_VIDTEXTURE)

    {

    texpool = D3DMPOOL_VIDEOMEM;

    }

    else

    {

    texpool = D3DMPOOL_SYSTEMMEM;

    }

    //--------------------------------------------------------------------------

    // Determine if the device can create vertex buffers in video // memory by testing the device caps bits.

    D3DMPOOL pool;

    if (caps.SurfaceCaps & D3DMSURFCAPS_VIDVERTEXBUFFER)

    {

    pool = D3DMPOOL_VIDEOMEM;

    }

    else

    {

    pool = D3DMPOOL_SYSTEMMEM;

    }

    // Create the vertex buffer. Here we are allocating enough // memory (from the default pool) to hold all our 3 custom vertices. // We also specify the FVF, so the vertex buffer knows what // data it contains.

    if( FAILED( g_pd3dmDevice->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX),

    0, D3DMFVF_CUSTOMVERTEX,

    pool, &g_pVB ) ) )

    {

    return E_FAIL;

    }

     

    // Load the texture map resource (banana.bmp)

    if( FAILED( D3DMXCreateTextureFromResourceEx( g_pd3dmDevice, GetModuleHandle(NULL),

    MAKEINTRESOURCE(IDB_WINDOW), D3DMX_DEFAULT, D3DMX_DEFAULT, 1, 0,

    D3DMFMT_UNKNOWN, texpool, D3DMX_FILTER_POINT, D3DMX_FILTER_POINT,

    0, NULL, NULL, &g_pTexture ) ) )

    {

    return E_FAIL;

    }

     

    // Now we fill the vertex buffer. To do this, we need to Lock() // the VB to gain access to the vertices. This // mechanism is required becuase vertex buffers may be in device // memory.

    void* pVertices;

    if( FAILED( g_pVB->Lock( 0, sizeof(vertices), &pVertices, 0 ) ) )

    return E_FAIL;

    memcpy( pVertices, vertices, sizeof(vertices) );

    g_pVB->Unlock();

    return S_OK;

    }

    VOID Cleanup()

    {

    if( g_pTexture != NULL )

    g_pTexture->Release();

    if( g_pVB != NULL )

    g_pVB->Release();

     

     

    if( g_pd3dmDevice != NULL)

    g_pd3dmDevice->Release();

    if( g_pD3DM != NULL)

    {

    if (g_hRefDLL)

    {

    g_pD3DM->RegisterSoftwareDevice(NULL);

    FreeLibrary(g_hRefDLL);

    }

    g_pD3DM->Release();

    }

    }

    VOID Render()

    {

    if( NULL == g_pd3dmDevice )

    return;

    // Clear the backbuffer to a blue color

    g_pd3dmDevice->Clear( 0, NULL, D3DMCLEAR_TARGET, D3DMCOLOR_XRGB(0,0,255),

    1.0f, 0 );

    // Begin the scene

    if( SUCCEEDED( g_pd3dmDevice->BeginScene() ) )

    {

    g_pd3dmDevice->SetTexture( 0, g_pTexture );

    g_pd3dmDevice->SetTextureStageState( 0, D3DMTSS_COLOROP, D3DMTOP_MODULATE );

    g_pd3dmDevice->SetTextureStageState( 0, D3DMTSS_COLORARG1, D3DMTA_TEXTURE );

    g_pd3dmDevice->SetTextureStageState( 0, D3DMTSS_COLORARG2, D3DMTA_DIFFUSE );

    g_pd3dmDevice->SetTextureStageState( 0, D3DMTSS_ALPHAOP, D3DMTOP_DISABLE );

    // Draw the triangles in the vertex buffer. This is broken // into a few steps. We are passing the vertices down a // "stream", so first we need to specify the source of // that stream, which is our vertex buffer.

    // Then, we call DrawPrimitive() which does the actual // rendering of our geometry (in this case, just one triangle).

    g_pd3dmDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );

    g_pd3dmDevice->DrawPrimitive( D3DMPT_TRIANGLELIST, 0, 2 );

    // End the scene

    g_pd3dmDevice->EndScene();

    }

    // Present the backbuffer contents to the display

    g_pd3dmDevice->Present( NULL, NULL, NULL, NULL );

    }

     

     

    LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )

    {

    switch( msg )

    {

    case WM_LBUTTONUP:

    PostMessage(hWnd, WM_CLOSE, 0, 0);

    break;

    case WM_KEYDOWN:

    if (VK_ESCAPE == wParam)

    {

    PostMessage(hWnd, WM_CLOSE, 0, 0);

    }

    break;

    case WM_CLOSE:

    Cleanup();

    break;

    case WM_DESTROY:

    PostQuitMessage( 0 );

    return 0;

    case WM_PAINT:

    {

    PAINTSTRUCT ps;

    HDC hDC = BeginPaint(hWnd, &ps);

    Render();

    EndPaint(hWnd, &ps);

    return 0;

    }

    case WM_SETTINGCHANGE:

    //make sure the screen is not rotated - if it is then abort //the app

    if (IsScreenRotated())

    {

    PostMessage(hWnd, WM_CLOSE, 0, 0);

    }

    break;

    }

    return DefWindowProc( hWnd, msg, wParam, lParam );

    }

    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPTSTR szCmd, INT )

    {

    // Parse command line to determine if user wants to use

    // the D3DM reference driver instead of the default system // driver

    if (0 == lstrcmp(szCmd, TEXT("-ref")))

    g_bUseRef = true;

    //we don't support a rotated screen

    if (IsScreenRotated())

    {

    return 0;

    }

    // Register the window class

    WNDCLASS wc = { 0L, MsgProc, 0L, 0L,

    hInst, NULL, NULL, NULL, NULL,

    TEXT("D3DM Tutorial") };

    RegisterClass( &wc );

    int iScreenWidth = GetSystemMetrics(SM_CXSCREEN);

    int iScreenHeight = GetSystemMetrics(SM_CYSCREEN);

    // Create the application's window

    HWND hWnd = CreateWindow( TEXT("D3DM Tutorial"),

    TEXT("D3DM Tutorial 02: Vertices"),

    WS_VISIBLE,

    0, 0, iScreenWidth, iScreenHeight,

    NULL, NULL, wc.hInstance, NULL );

    SHFullScreen(hWnd, SHFS_HIDESIPBUTTON | SHFS_HIDETASKBAR);

    // Initialize Direct3D Mobile

    if( SUCCEEDED( InitD3DM( hWnd ) ) )

    {

    // Create the vertex buffer

    if( SUCCEEDED( InitVB() ) )

    {

    // Show the window

    ShowWindow( hWnd, SW_SHOWNORMAL );

    UpdateWindow( hWnd );

    // Enter the message loop

    MSG msg;

    memset( &msg, 0, sizeof(msg) );

    while( msg.message!=WM_QUIT )

    {

    if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )

    {

    TranslateMessage( &msg );

    DispatchMessage( &msg );

    }

    else

    Render();

    }

    }

    }

    return 0;

    }

     

    Thursday, October 5, 2006 3:22 PM

Answers

  • you can add the full path of the library into the source file.

    check out to see if it works

    Friday, October 6, 2006 7:26 AM