Webcam Program Error

Moved from Tutorials

Page 1 of 1

12 Replies - 4424 Views - Last Post: 25 October 2012 - 05:44 PM Rate Topic: -----

#1 MrCAT22  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 27-June 12

Webcam Program Error

Posted 16 October 2012 - 09:13 PM

Hi, I think I already create the following code correctly and link it correctly to vfw32.lib and gdi32.lib. But it always show the following error:

Quote

undefined reference to `capCreateCaptureWindow@32'


here is the code:
HWND camhwnd = capCreateCaptureWindow ("camera window", WS_CHILD , 0, 100, 300, 300, hwnd, 0);
SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);




So, I try to use capCreateCaptureWindow from avicap32.dll with the following code. I can compile it into file *.exe but when I try to run it's *.exe, always show the following error:
Posted Image

And here is the code:
			hMod = LoadLibrary("avicap32.dll");
			if(!hMod)
			{
				MessageBox(NULL,"Error - module","Error",MB_OK | MB_IConerror);
			}
			else
			{
				_capCreateCaptureWindowW = (LDCAPWND)GetProcAddress(hMod,"capCreateCaptureWindowW");
				if(!_capCreateCaptureWindowW)
				{
					MessageBox(NULL,"Error - function","Error",MB_OK | MB_IConerror);
				}
				else
				{
					HWND hCam = _capCreateCaptureWindowW((LPCWSTR) "Capture Window",WS_CHILD | WS_VISIBLE | SS_SIMPLE,10,100,200,200,hwnd,0);
				}
			}
			FreeLibrary(hMod);
			SendMessage (hCam, WM_CAP_DRIVER_CONNECT, 0 /* wIndex */, 0L);





I use Dev Cpp 4.9.9.2 and WindowsXP.
I give up, and have no idea. :surrender:
I really need to use it's. :tt1:
But How? :helpsmilie:
Please help me :helpsmilie:

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Webcam Program Error

#2 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 778
  • View blog
  • Posts: 2,310
  • Joined: 20-March 10

Re: Webcam Program Error

Posted 17 October 2012 - 12:28 PM

Are you following this tutorial ??

http://www.dreaminco...webcam-program/

If so and you say you are using Dev C

have you included these list of defines either in a header file or

before your list of includes

#define WM_CAP_START  0x0400
#define WM_CAP_DRIVER_CONNECT  (WM_CAP_START + 10)
#define WM_CAP_DRIVER_DISCONNECT  (WM_CAP_START + 11)
#define WM_CAP_EDIT_COPY (WM_CAP_START + 30)
#define WM_CAP_GRAB_FRAME (WM_CAP_START + 60)
#define WM_CAP_SET_SCALE (WM_CAP_START + 53)
#define WM_CAP_SET_PREVIEWRATE (WM_CAP_START + 52)
#define WM_CAP_SET_PREVIEW (WM_CAP_START + 50)
#define WM_CAP_DLG_VIDEOSOURCE  (WM_CAP_START + 42)
#define WM_CAP_STOP (WM_CAP_START+ 68)



These WM's are not included as part of MinGW's vfw.h include file
for some reason you must include these by hand if you are using
Dev C++.

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#3 MrCAT22  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 27-June 12

Re: Webcam Program Error

Posted 19 October 2012 - 05:47 PM

Hi snoopy11,

Off course, I already include it.
But still show:

Quote

undefined reference to `capCreateCaptureWindowA'


:helpsmilie: :surrender:

I wonder how you and others can run it :tt1:

I found another person who have same problem with me in here:
http://social.msdn.m...a8-6e7ab7be4e83

It maybe vfw32.lib is out of date. And suggest to use DirectShow Development.

This post has been edited by MrCAT22: 19 October 2012 - 05:50 PM

Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1347
  • View blog
  • Posts: 4,638
  • Joined: 19-February 09

Re: Webcam Program Error

Posted 19 October 2012 - 06:25 PM

Quote

undefined reference to `capCreateCaptureWindowA'


This suggests you are trying to compile as an ASCII/MBCS program.


08	    _capCreateCaptureWindowW = (LDCAPWND)GetProcAddress(hMod,"capCreateCaptureWindowW");



This suggest you want to compile as UNICODE.
Was This Post Helpful? 0
  • +
  • -

#5 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 778
  • View blog
  • Posts: 2,310
  • Joined: 20-March 10

Re: Webcam Program Error

Posted 21 October 2012 - 06:49 AM

Hi,

In that case you have not linked correctly to libvfw32.a

I saw that you mentioned vfw32.lib this is a Microsoft compiler library

Dev C uses the MinGW version of the gcc compiler.

all the libs you need to link against are

libvfw32.a
libgdi32.a

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#6 MrCAT22  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 27-June 12

Re: Webcam Program Error

Posted 22 October 2012 - 03:00 AM

Hi snoopy11,

Yes I already do it.

I put mysource.c in C:\Dev-Cpp\bin
and
needed library in C:\Dev-Cpp\bin\libs

Then, I compile mysource.c with this:
gcc mysource.c -o mysource libs/comdlg32.lib libs/wininet.lib libs/gdi32.lib libs/comctl32.lib libs/vfw32.lib libs/netapi32.lib libs/mpr.lib libs/iphlpapi.lib libs/ole32.lib libs/winspool.lib libs/setupapi.lib libs/shlwapi.lib libs/wtsapi32.lib libs/oleaut32.lib -lmysql -lodbc32 -lodbccp32 -lws2_32 -lwinmm -lpsapi -luuid -lole32 -lvfw32 -lgdi32



and still get the following error:

Quote

undefined reference to `capCreateCaptureWindow'


Here is my complete source code:
#define WM_CAP_START  0x0400
#define WM_CAP_DRIVER_CONNECT  (WM_CAP_START + 10)
#define WM_CAP_DRIVER_DISCONNECT  (WM_CAP_START + 11)
#define WM_CAP_EDIT_COPY (WM_CAP_START + 30)
#define WM_CAP_GRAB_FRAME (WM_CAP_START + 60)
#define WM_CAP_SET_SCALE (WM_CAP_START + 53)
#define WM_CAP_SET_PREVIEWRATE (WM_CAP_START + 52)
#define WM_CAP_SET_PREVIEW (WM_CAP_START + 50)
#define WM_CAP_DLG_VIDEOSOURCE  (WM_CAP_START + 42)
#define WM_CAP_STOP (WM_CAP_START+ 68)
#define WM_CAP_FILE_SET_CAPTURE_FILE	(WM_CAP_START+ 20)
#define WM_CAP_FILE_SAVEDIB		(WM_CAP_START+  25)
#define WM_CAP_SEQUENCE 		(WM_CAP_START + 62)

#include <windows.h>
#include <vfw.h>
#include <stdio.h>
#pragma comment(lib,"vfw32.lib")
#pragma comment(lib,"gdi32.lib")

LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp);
void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC);

char szAppName [] = TEXT("Motion Tracker");
HWND camhwnd;
HDC hdc ;
HDC hdcMem;
PAINTSTRUCT ps;
HBITMAP hbm;
RECT rc;
//Globals for the frame comparison
HBITMAP curFrame, lasFrame = NULL, bakFrame;
//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 = GetSysColorBrush(COLOR_3DFACE);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szAppName;

    RegisterClass (&wc);

// Create the window
    hwnd = CreateWindow (szAppName,
		                 szAppName,
						 WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
						 CW_USEDEFAULT,
						 CW_USEDEFAULT,
						 775,525,0,0,
						 hInstance,0);

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

    while (GetMessage(&msg,0,0,0))
    {
        if (!IsDialogMessage(hwnd, &msg))
        {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
    }
    return msg.wParam;
}

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

//some buttons
    HWND hButtStartCam;
    HWND hButtStopCam;
    HWND hButtGrabFrame;

    switch (message)                  /* handle the messages */
    {

	    case WM_CREATE:
	    {
	        hButtStartCam = CreateWindowEx(0,"BUTTON","Start Camera",WS_CHILD | WS_VISIBLE,
	                                       10,120,100,20,hwnd,(HMENU)1,hInstance, 0);
	        hButtStopCam = CreateWindowEx(0,"BUTTON","Stop Camera",WS_CHILD | WS_VISIBLE,
	                                      10,160,100,20,hwnd,(HMENU)2,hInstance, 0);
	        hButtGrabFrame = CreateWindowEx(0,"BUTTON","Grab Frame",WS_CHILD | WS_VISIBLE,
	                                        10,200,100,20,hwnd,(HMENU)3,hInstance, 0);
	        camhwnd = (HWND) capCreateCaptureWindow ("camera window", WS_CHILD , 10, 10, 100, 100, hwnd, 0);
			SendMessage(camhwnd,WM_CAP_DRIVER_CONNECT,0,0);
	        SendMessage(camhwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);
	        break;
	    }
	    default:              /* for messages that we don't deal with */
	        return DefWindowProc(hwnd, message, wParam, lParam);
   }
    return 0;
}




:surrender: :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 778
  • View blog
  • Posts: 2,310
  • Joined: 20-March 10

Re: Webcam Program Error

Posted 22 October 2012 - 11:10 AM

Well as I said before,

you are using a gcc compiler with .lib's when all gcc libraries end in .a's

the compiler wont be able to link against vfw32.lib or gdi32.lib

the libraries you need to link to are

libvfw32.a and libgdi32.a

Do Not and repeat Do Not

link against vfw32.lib and gdi32.lib

See how you go with linking against the gcc libraries ie .a's

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#8 MrCAT22  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 27-June 12

Re: Webcam Program Error

Posted 22 October 2012 - 06:49 PM

Hi snoopy11,

Yes I already do it. I only link with libvfw32.a and libgdi32.a
But still same error:

Quote

C:\Dev-Cpp\bin>gcc mysource.c -o mysource libs/comdlg32.lib libs/wininet.lib lib
s/comctl32.lib libs/netapi32.lib libs/mpr.lib libs/iphlpapi.lib libs/ole32.lib l
ibs/winspool.lib libs/setupapi.lib libs/shlwapi.lib libs/wtsapi32.lib libs/oleau
t32.lib -lmysql -lodbc32 -lodbccp32 -lws2_32 -lwinmm -lpsapi -luuid -lole32 -lvf
w32 -lgdi32
mysource.c:108:2: warning: no newline at end of file
C:\DOCUME~1\fritz1\LOCALS~1\Temp/cc4Oaaaa.o(.text+0x329):mysource.c: undefined r
eference to `capCreateCaptureWindow'
collect2: ld returned 1 exit status




:helpsmilie: :surrender:
Was This Post Helpful? 0
  • +
  • -

#9 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 778
  • View blog
  • Posts: 2,310
  • Joined: 20-March 10

Re: Webcam Program Error

Posted 22 October 2012 - 09:25 PM

Hi,

Ok you say your using XP which version SP1, SP2 or SP3 ?


Thanks...
Was This Post Helpful? 0
  • +
  • -

#10 MrCAT22  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 27-June 12

Re: Webcam Program Error

Posted 22 October 2012 - 10:12 PM

Hi snoopy11,

Yes, I use WinXP SP1.

:helpsmilie: :surrender:
Was This Post Helpful? 0
  • +
  • -

#11 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 778
  • View blog
  • Posts: 2,310
  • Joined: 20-March 10

Re: Webcam Program Error

Posted 23 October 2012 - 01:01 PM

Ahh,

Well there is your problem right there

the tutorial requires XP SP3 or above.....

It says it in the Tutorial below 'links to sdk'

so upgrade to SP3 would be my advice :)

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#12 MrCAT22  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 27-June 12

Re: Webcam Program Error

Posted 23 October 2012 - 04:54 PM

Hi snoopy11,

Thank you.

Yes, I already upgraded it. But it's error still same. :cry:
Posted Image

Quote

undefined reference to `capCreateCaptureWindow'


:helpsmilie: :surrender:
Was This Post Helpful? 0
  • +
  • -

#13 MrCAT22  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 32
  • Joined: 27-June 12

Re: Webcam Program Error

Posted 25 October 2012 - 05:44 PM

Hello,

anybody here have same problem with me?
:helpsmilie:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1