c ++ LNK2001:未解析的外部符号错误

时间:2013-05-25 05:23:41

标签: c++ linker directx

我目前正在创建一个应用程序,它将来自网络摄像头的Feed上的多个图像元素叠加在一起。我按照本指南显示了网络摄像头Feed http://www.dreamincode.net/forums/topic/193519-win32-webcam-program/,并在将其与directx框架(基于http://www.youtube.com/user/ChiliTomatoNoodle教程)相结合后,我在第135行找到了链接错误(具体来说) ,'错误LNK2001:未解析的外部符号_capCreateCaptureWindowA @ 32')。

知道我做错了吗?

#include <windows.h>
#include <vfw.h>
#include <wchar.h>
#include "Game.h"
#include "resource.h"
#include "Mouse.h"

LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);

static KeyboardServer kServ;
static MouseServer mServ;

char szAppName [] = TEXT("Webcam");
HWND camhwnd;
HDC hdc ;
HDC hdcMem;
PAINTSTRUCT ps;
HBITMAP hbm;
RECT rc;

//WinMain -- Main Window
int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {

    HWND hwnd;
    MSG msg;

    WNDCLASS wc;
    wc.style = CS_HREDRAW|CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(GetModuleHandle(NULL), IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szAppName;

    RegisterClass (&wc);


    hwnd = CreateWindow (szAppName,szAppName,WS_POPUP | WS_VISIBLE,0,0,1920,1080,0,0,hInstance,0);


    ShowWindow (hwnd,SW_SHOW);
    UpdateWindow (hwnd);

    ShowWindow(camhwnd,SW_SHOW);
    SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
    SendMessage(camhwnd, WM_CAP_SET_SCALE, true , 0);
    SendMessage(camhwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
    SendMessage(camhwnd, WM_CAP_SET_PREVIEW, true , 0);



    Game theGame( hwnd,kServ,mServ );

    while( msg.message != WM_QUIT ) {
        if( PeekMessage( &msg,NULL,0,0,PM_REMOVE ) ) {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else {
            theGame.Go();
        }
    }

    return msg.wParam;
}

LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
    switch( msg ) {
        case WM_DESTROY:
            PostQuitMessage( 0 );
            break;

        // ************ KEYBOARD MESSAGES ************ //
        case WM_KEYDOWN:
            switch( wParam ) {
                case VK_UP:
                    kServ.OnUpPressed();
                    break;
                case VK_DOWN:
                    kServ.OnDownPressed();
                    break;
                case VK_LEFT:
                    kServ.OnLeftPressed();
                    break;
                case VK_RIGHT:
                    kServ.OnRightPressed();
                    break;
                case VK_SPACE:
                    kServ.OnSpacePressed();
                    break;
                case VK_RETURN:
                    kServ.OnEnterPressed();
                    break;
            }
            break;
        case WM_KEYUP:
            switch( wParam ) {
                case VK_UP:
                    kServ.OnUpReleased();
                    break;
                case VK_DOWN:
                    kServ.OnDownReleased();
                    break;
                case VK_LEFT:
                    kServ.OnLeftReleased();
                    break;
                case VK_RIGHT:
                    kServ.OnRightReleased();
                    break;
                case VK_SPACE:
                    kServ.OnSpaceReleased();
                    break;
                case VK_RETURN:
                    kServ.OnEnterReleased();
                    break;
            }
            break;
        // ************ END KEYBOARD MESSAGES ************ //
    }

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

//Main Window Procedure WindowProc
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    HINSTANCE hInstance = GetModuleHandle(NULL);

    switch (message) {
        case WM_CREATE: {

            camhwnd = capCreateCaptureWindow ("camera window", WS_CHILD , 0, 0, 1920, 1080, hwnd, 0);
            SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
            SendMessage(camhwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);

            break;

        }

        case WM_DESTROY: {
            SendMessage(camhwnd, WM_CAP_DRIVER_DISCONNECT, 0, 0);
            PostQuitMessage(0);
            break;
        }

        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}

1 个答案:

答案 0 :(得分:0)

documentation包含标题为要求的部分。这列出了调用函数所需的头文件和导入库。

  • 如果未能包含头文件,则编译器对象因为没有声明任何函数。
  • 如果您未能将导入库传递给链接器,则会失败且缺少引用。

您没有将导入库传递给链接器。将其添加到项目配置的链接器部分中的Additional Library Dependencies。

导入库的名称列在我上面链接的MSDN文档中。所有API函数都可以遵循此过程。