0

I am currently creating an application that overlays multiple image elements on a feed from a webcam. I followed this guide in order to display the webcam feed http://www.dreamincode.net/forums/topic/193519-win32-webcam-program/, and after combining it with a directx framework (based on the http://www.youtube.com/user/ChiliTomatoNoodle tutorials), I ended up with a linking error, on line 135 (Specifically, 'error LNK2001: unresolved external symbol _capCreateCaptureWindowA@32').

Any idea what I did wrong?

#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;
}
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Jerry Coffin May 25 '13 at 05:25

1 Answers1

0

The documentation contains a section titled Requirements. This lists the header file and import library required to call the function.

  • If you fail to include the header file, the compiler objects because no function has been declared.
  • If you fail to pass the import library to the linker it fails with a missing reference.

You did not pass the import library to the linker. Add it to the Additional Library Dependencies in the linker section of your project configuration.

The name of the import library is listed in the MSDN documentation that I linked to above. This procedure can be followed for all API functions.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490