webcam开发过程中的一些错误

来源:互联网 发布:超好的淘宝女装店 编辑:程序博客网 时间:2024/05/06 11:54
 
1. 设置编译环境时,注意头文件的包含顺序,可以通过查看编译错误调整头文件顺序.
2. 关于VS2005中无法识别CSource,应添加头文件streams.h,而dshow.h没有用.
3. 改写Filter和Pin的构造函数.
4. Pin需要继承的两个纯虚拟函数:DecideBufferSize和FillBuffer.如果没改写,将出现编译错误,注意仔细查看这些编译错误,以找到问题所在.
5. DllCanUnloadNow和DllGetClassObject既然什么都不做,可否去掉?引起链接错误,不知怎么解决?居然是没有添加Strmbasd.lib引起的!我还以为是要自己实现呢!建议在开始写代码前就将几个需要的LIB添加到LINK中, Strmbasd.lib, Msvcrtd.lib, Winmm.lib,Strmiids.lib,注意在LINK中它们之间没有逗号,而是空格,否则会出现”can not find file “XXX.lib”的编译错误.
6. 出现CLSID_的链接错误(unresolved CLSID_MyFilter)也可以通过添加头文件”initguid.h”解决,出现undefined symbol CLSID_MyFilter也是添加头文件”initguid.h”
7. CLSID_NullRenderer需要包含头文件qedit.h,否则有编译错误.
8. 关于链接错误error LNK2001: unresolved external symbol "unsigned int (__stdcall*ATL::g_pfnGetThreadACP)(void)"(?g_pfnGetThreadACP@ATL@@3P6GIXZA),必须将atlconv.h换成atlbase.h,且需将LINKER->Input->Ignore all default libraries选为No.两个都要改,改一个不行. atlconv.h for vs2003 atlbase.h for vs2005
9. 关于can not open file MSVCRT.lib或MSVCRTD.lib或LIBCD.lib或LIBCMT.lib或LIBCMTD.lib或LIBC.lib的问题.需要Ignore specific library.
 
/NODEFAULTLIB:library:Ignore Libraries    This option removes the specified library or libraries from the list of libraries it searches when resolving external references.
/NODEFAULTLIB Ignore All Default Libraries    This option removes all default libraries from the list of libraries it searches when resolving external references.
 
关于在WIN32程序中使用MFC中的CString和CFile等的问题.因为要使用MFC中的CString和CFile,,所以必须包含MFC的afx.h头文件(因为建立的不是MFC程序所以必须手工添加,如果是MFC程序已经包含必要的头文件,可直接使用CString和CFile等),因此我们在stdafx.h中添加afx.h,这里需要注意的是afx.h必须放在所有手工添加的头文件的前面,否则将出现下面的错误: fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>,例如,如果我们象下面这样包含就会出现上面的错误:
#include "streams.h"
#include "afx.h"
应该改成:
#include "afx.h"
#include "streams.h"
其实将系统和类库框架的头文件放在前面是一种很好的习惯.
 
另外必须更改USE OF MFC选项,不能用use standard windows libraries,否则出现如下错误:
fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
 
选择use mfc in a static library出现很多错误.奇怪!!!!!!!!然后添加 /FORCE:MULTIPLE,错误只剩下一个拉,如下: fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d],将C/C++中的runtime library改为Debug Multithreaded,出现如下错误error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup,再将LINKER->INPUT->Additional dependencies中输入的Msvcrtd.lib改为libcmtd.lib,问题解决.
选择use mfc in a shared dll,只有一个错误,如下:
error LNK2005: _DllMain@12 already defined in 3602Webcam.obj
解决方法:添加 /FORCE:MULTIPLE
 
原因:主要是单线程和多线程不匹配的问题.有的链接的是单线程LIB,有的链接的是多线程LIB,解决方法: /FORCE:MULTIPLE
还有就是USE OF MFC的选择与RUNTIME Library选择不匹配的问题,两者是对应选择,下面是对应原则:
Debug, shared library MFC applications - "Debug Multithreaded Dll."
Release, shared library MFC applications - "Multithread Dll."
Debug, static library MFC applications - "Debug Multithreaded."
Release, static library MFC applications - "Multithreaded."
 
原创粉丝点击