Thread: [hopefully an] easy linker error

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    416

    [hopefully an] easy linker error

    I would like to capture video from my webcam and am trying to use vfw.h but seems to have some issues. I linked vfw32.lib and msvfw32.lib to my project, and it still gives me the error saying the function capCreateCaptureWindow() is undeclared. I have uninstalled, reinstalled, and installed 3 different compilers with different libraries (devcpp, codeblocks, LLC-win32). None of them work. What else could be causing this, and is there a fix? I am also looking for other/better ways to get video from an input device.

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    If it says the function is "undeclared" then that means it's not finding the function in the header, it didn't even try to link yet. Your header must be out of date, corrupt, or you have #define tags that are disrupting the declarations. If I were you, I'd try to find the actual declaration of capCreateCaptureWindow in the header, and trace it from there.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    I looked in the vfw.h file and there's no capCreateCaptureWindow() declared in there [the one i was using at least]. I googled for it and found a complete header file with the function declared, but I am not sure if I should add it to the header file already there. I "remade" the header file in to my own and declared it as #include "vfw.h" and added it to the project. It still gave me a weird error saying I need to turn on "Just-In-Time debugging" for visual studios, but I'm using codeblocks 1.0. I also found a couple other header files in my quartus program with the win32 libraries. Quartus' vfw.h file has the declared function(s) I am looking for, and it also has the .a library file to go with it, but it still comes up saying the functions are undeclared. I am so stumped right now.

    EDIT: just for reference i am linking libavicap32.a, libmsvfw32.a, and libvfw32.a. None of them seem to work. I have tried them all on the 3 different compilers above.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Try linking with Vfw32.lib, thats the only thing I am linking with in order to use the webcam (

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Quote Originally Posted by h3ro View Post
    Try linking with Vfw32.lib, thats the only thing I am linking with in order to use the webcam (
    I did. Nothing works . Would you mind sending me your vfw32.lib and the header file? Maybe I got a weird version... on 4 different compilers... What compiler are you using? I might download VB express just for the libraries and headers.

    EDIT: Ok so I found a snippet on here where someone loaded capCreateCaptureWindow() explicitly through loading the AVICAP32.DLL file, and used the process address for it. One problem down, it created the capture window. However, it will not recognize the other 3 functions needed in order to view images from the webcam. The messagebox's always come up saying "Error-function2" "Error-function3" "Error-function4"

    Code:
    #include <windows.h>
    //#include <vfw.h>
    
    #define VFWAPI WINAPI
    #define WND_ID	5010
    
    typedef HWND (VFWAPI *LDCAPWND)(LPCWSTR,DWORD,int,int,int,int,HWND,int);
    typedef HWND (VFWAPI *LDCAP)(HWND,int);
    typedef HWND (VFWAPI *LDCAPPRE)(HWND,bool);
    
    extern LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	HINSTANCE hInstance = GetModuleHandle(NULL);
    
    	//HWND hButtStartCam;
    	//HWND hButtStopCam;
    	//HWND hButtGetFrame;
    
        switch (message)                  /* handle the messages */
        {
    		case WM_CREATE:
    		{
                HWND hwndc;
                HMODULE hMod, hVFW;
                LDCAPWND _capCreateCaptureWindowW;
                LDCAP _capDriverConnect, _capPreviewRate;
                LDCAPPRE _capPreview;
    
    
                hMod = LoadLibrary("AVICAP32.DLL");
                hVFW = LoadLibrary("MSVFW32.dll");
    
                if(!hMod || !hVFW){
                    MessageBox(NULL,"Error - module",NULL,0);
                    return 1;
                }
    
                //Load CreateCaptureWindow
                _capCreateCaptureWindowW = (LDCAPWND)GetProcAddress(hMod,"capCreateCaptureWindowW");
    
                //See if CreateCaptureWindow loaded
                if(!_capCreateCaptureWindowW){
                    MessageBox(NULL,"Error - function1",NULL,0);
                    return 1;
                }
                //Create capture window
                hwndc = _capCreateCaptureWindowW((LPCWSTR) "Capture Window",
                    WS_CHILD | WS_VISIBLE | SS_SIMPLE,0, 0, 640, 480,HWND_DESKTOP,
                    (int) 32);
    
                _capDriverConnect = (LDCAP)GetProcAddress(hMod,"capDriverConnect");
                if(_capDriverConnect)
                    _capDriverConnect(hwndc,0);
                else MessageBox(NULL,"Error - function2",NULL,0);
    
                _capPreviewRate = (LDCAP)GetProcAddress(hMod,"capPreviewRate");
                if(_capPreviewRate)
                    _capPreviewRate(hwndc,100);
                else MessageBox(NULL,"Error - function3",NULL,0);
    
                _capPreview = (LDCAPPRE)GetProcAddress(hMod,"capPreview");
                if(_capPreview)
                    _capPreview(hwndc,TRUE);
                else MessageBox(NULL,"Error - function4",NULL,0);
    
                //Free AVICAP32.DLL
                FreeLibrary(hMod);
                FreeLibrary(hVFW);
    
                //These are the functions that are "undeclared"
                //capDriverConnect(hwndc,0);
    	    //capPreviewRate(hwndc,66);
    	    //capPreview(hwndc,TRUE);
    
    
    
    		}
    		break;
    Last edited by scwizzo; 08-05-2008 at 09:40 AM.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Im using visual studio.

    Try downloading the tutorials here:
    I used the first one to see how to setup a window

    They worked fine, but you need to change a few variables (cast them)
    and link with the lib i mentioned above


    http://uk.geocities.com/ecafin/index.html

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Quote Originally Posted by h3ro View Post
    That's exactly the site I went off of, and am trying to get the first tutorial to work. I will download VB 2008 and see if that fixes my problem. I found something on another forum saying you need the .NET framework in order for the libraries to link to the .dll files correctly. That means nothing to me other than I don't have that.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Did you try to ONLY link with Vfw32.lib? I got an error when I linked to the libraries the tutorial asked me to link to

  9. #9
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Yep. Like I said though, my vfw.h is missing the function declarations. They are in some of the headers (like the Quartus one, which isn't even used for C++ but for VHDL), and then they are missing in other. I don't have a VFW.DLL either, just a MSVFW.DLL hmm... Here are the exact errors I am getting when I link with only vfw32.lib and not load the .dll libraries, in case anyone was confused.

    Code:
    Switching to target: default
    Compiling: main.cpp
    main.cpp: In function `LRESULT WindowProcedure(HWND__*, UINT, WPARAM, LPARAM)':
    main.cpp:74: error: `capCreateCaptureWindowW' undeclared (first use this function)
    main.cpp:74: error: (Each undeclared identifier is reported only once for each function it appears in.)
    main.cpp:77: error: `capDriverConnect' undeclared (first use this function)
    main.cpp:78: error: `capPreviewRate' undeclared (first use this function)
    main.cpp:79: error: `capPreview' undeclared (first use this function)
    Process terminated with status 1 (0 minutes, 0 seconds)
    EDIT: Ok... I think I'm getting somewhere as to why none of this is working. Turns out (or so i've read) microsoft redistributed vfw32.dll as msvfw32.dll (explains why i have msvfw32 and not vfw32) and changed some of the functions around. I used depends.exe on msvfw32.dll to see what was in there, and the capXXX functions are not there (big surprise). I looked up DirectShow also, and my compiler doesn't know dshow.h either... so I have no idea what's going on now. Here is a list of the functions on msvfw32.dll

    Code:
    VideoForWindowsVersion
    DrawDibBegin
    DrawDibChangePalette
    DrawDibClose
    DrawDibDraw
    DrawDibEnd
    DrawDibGetBuffer
    DrawDibGetPalette
    DrawDibOpen
    DrawDibProfileDisplay
    DrawDibRealize
    DrawDibSetPalette
    DrawDibStart
    DrawDibStop
    DrawDibTime
    GetOpenFileNamePreview
    GetOpenFileNamePreviewA
    GetOpenFileNamePreviewW
    GetSaveFileNamePreviewA
    GetSaveFileNamePreviewW
    ICClose
    ICCompress
    ICCompressorChoose
    ICCompressorFree
    ICDecompress
    ICDraw
    ICDrawBegin
    ICGetDisplayFormat
    ICGetInfo
    ICImageCompress
    ICImageDecompress
    ICInfo
    ICInstall
    ICLocate
    ICMThunk32
    ICOpen
    ICOpenFunction
    ICRemove
    ICSendMessage
    ICSeqCompressFrame
    ICSeqCompressFrameEnd
    ICSeqCompressFrameStart
    MCIWndCreate
    MCIWndCreateA
    MCIWndCreateW
    MCIWndRegisterClass
    StretchDIB
    Last edited by scwizzo; 08-05-2008 at 01:45 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM