0

我目前正在创建一个应用程序,该应用程序在来自网络摄像头的提要上覆盖多个图像元素。我按照本指南显示网络摄像头提要http://www.dreamincode.net/forums/topic/193519-win32-webcam-program/,并将其与 directx 框架(基于http:// www.youtube.com/user/ChiliTomatoNoodle tutorials),我在第 135 行遇到了一个链接错误(具体来说,'error LNK2001: unresolved external symbol _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;
}
4

1 回答 1

0

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

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

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

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

于 2013-05-25T06:21:38.953 回答