如何在win32工程下使用MFC类 如CTypedPtrList,CMutex,CSingleLock拜谢,我很急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把你要用的类的头文件加上:#include <afxmt.h>#include <afxtempl.h> 我还要说明一下,我的VC下面选定了Ignore All Libraries这个选项 加上类的头文件,需要那个在MSDN里查一下就可以知道是那个文件了。 已经加上该类的头文件,主要是我选择了Ignore All Libraries,没法找到响应的库。另外还出现这样的一个错误:H:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxv_w32.h(14) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h> H:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxv_w32.h(14) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>上面说明Win32 App不能调用MFC。如果确实要用MFC的函数,看来只能写DLL调用。 我想试试:(1)把前面的MFC的类库中CTypedPtrList修改为标准C++库的对应的类,但不知道对应的类是什么。此外不知道此法可行否?(2)不知道除了MFC,同步线程应该使用什么类或者API函数 进入 Project-->Setting--> C/C++ Page --> Preprocessor definitions 加入 _AFXDLL 并修改 Project Options,将 /MT 或者 /ML 改为 /MD#include <afx.h>#include <afxwin.h> // MFC core and standard componentsextern "C" int WINAPI_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ int nRetCode = 0; if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { TRACE0("Fatal Error: MFC initialization failed.\n"); nRetCode = 1; } else { // Actual WinMain codes ... AfxWinTerm(); } return nRetCode;} 先#include <afx.h>#include <afxwin.h> 再选择rebuild all,输出窗口如下:Deleting intermediate files and output files for project 'PushSource - Win32 Debug Unicode'.--------------------Configuration: PushSource - Win32 Debug Unicode--------------------Compiling...DataAdmin.cppFilePack.cppPushSourceBitmapSet.cppsetup.cppLinking... Creating library Debug_Unicode/PushBmpSet.lib and object Debug_Unicode/PushBmpSet.expDataAdmin.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDEPushSourceBitmapSet.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDEDataAdmin.obj : error LNK2001: unresolved external symbol __afxForceUSRDLLPushSourceBitmapSet.obj : error LNK2001: unresolved external symbol __afxForceUSRDLLDataAdmin.obj : error LNK2001: unresolved external symbol "public: static void __stdcall CObject::operator delete(void *)" (??3CObject@@SGXPAX@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: __thiscall CMutex::CMutex(int,unsigned short const *,struct _SECURITY_ATTRIBUTES *)" (??0CMutex@@QAE@HPBGPAU_SECURITY_ATTRIBUTES@@@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: static void * __stdcall CObject::operator new(unsigned int)" (??2CObject@@SGPAXI@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CPtrList::~CPtrList(void)" (??1CPtrList@@UAE@XZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: void __thiscall CPtrList::RemoveAll(void)" (?RemoveAll@CPtrList@@QAEXXZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: struct __POSITION * __thiscall CPtrList::GetHeadPosition(void)const " (?GetHeadPosition@CPtrList@@QBEPAU__POSITION@@XZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: __thiscall CSingleLock::~CSingleLock(void)" (??1CSingleLock@@QAE@XZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CSingleLock::Unlock(void)" (?Unlock@CSingleLock@@QAEHXZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CPtrList::IsEmpty(void)const " (?IsEmpty@CPtrList@@QBEHXZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CSingleLock::IsLocked(void)" (?IsLocked@CSingleLock@@QAEHXZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CSingleLock::Lock(unsigned long)" (?Lock@CSingleLock@@QAEHK@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: __thiscall CSingleLock::CSingleLock(class CSyncObject *,int)" (??0CSingleLock@@QAE@PAVCSyncObject@@H@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CPtrList::GetCount(void)const " (?GetCount@CPtrList@@QBEHXZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CPtrList::Dump(class CDumpContext &)const " (?Dump@CPtrList@@UBEXAAVCDumpContext@@@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CPtrList::AssertValid(void)const " (?AssertValid@CPtrList@@UBEXXZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CObject::Serialize(class CArchive &)" (?Serialize@CObject@@UAEXAAVCArchive@@@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CPtrList::GetRuntimeClass(void)const " (?GetRuntimeClass@CPtrList@@UBEPAUCRuntimeClass@@XZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: struct __POSITION * __thiscall CPtrList::AddTail(void *)" (?AddTail@CPtrList@@QAEPAU__POSITION@@PAX@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: void * & __thiscall CPtrList::GetHead(void)" (?GetHead@CPtrList@@QAEAAPAXXZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: void * __thiscall CPtrList::RemoveHead(void)" (?RemoveHead@CPtrList@@QAEPAXXZ)DataAdmin.obj : error LNK2001: unresolved external symbol "public: void * & __thiscall CPtrList::GetNext(struct __POSITION * &)" (?GetNext@CPtrList@@QAEAAPAXAAPAU__POSITION@@@Z)DataAdmin.obj : error LNK2001: unresolved external symbol "public: __thiscall CPtrList::CPtrList(int)" (??0CPtrList@@QAE@H@Z)PushSourceBitmapSet.obj : error LNK2001: unresolved external symbol "int __stdcall AfxAssertFailedLine(char const *,int)" (?AfxAssertFailedLine@@YGHPBDH@Z)Debug_Unicode/PushBmpSet.ax : fatal error LNK1120: 25 unresolved externalsError executing link.exe.PushBmpSet.ax - 28 error(s), 0 warning(s)按照常理是缺少库文件,我应该加上什么库才好呢? unresolved external symbol这个错误明显是文件没包含进来,建议你查查,例如:CPtrList::GetNext在那个文件定义的,加进去,而且前面缺少cobject的定义 仔细研究 <afx.h>,发现应该加入mfc42ud.lib ,mfc42sud.lib ,现在已经下降为2errors,1warningDeleting intermediate files and output files for project 'PushSource - Win32 Debug Unicode'.--------------------Configuration: PushSource - Win32 Debug Unicode--------------------Compiling...DataAdmin.cppFilePack.cppPushSourceBitmapSet.cppsetup.cppLinking...mfcs42ud.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in setup.objmfcs42ud.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in setup.obj; second definition ignored Creating library Debug_Unicode/PushBmpSet.lib and object Debug_Unicode/PushBmpSet.expDebug_Unicode/PushBmpSet.ax : fatal error LNK1169: one or more multiply defined symbols foundError executing link.exe.PushBmpSet.ax - 2 error(s), 1 warning(s) http://expert.csdn.net/Expert/topic/1710/1710297.xml?temp=.5333368 谢谢上面各位友情跟贴。问题已经解决。要点:1、加入相关的头文件,尤其是afx.h 2、确保MFC库在CRT库之前被link,可参考微软的文章ID:KB148652 查看afx.h文件中库如何链接的部分,选择合理的preprocessor definitions 3、多问问题,集思广益to:webber84(***闭关修炼中***) 我在写一个directshow filter ,是Win32 DLL类型的to:o_racle(璐璐) ( ) 既然是link error,首先想到的不该是头文件没有include吧 :) 关于安装directx问题?为什么我安装的DirectX没有directshow windows socket send()和recv()问题? 类似QQ查看好友资料的对话框,ctabctrl 要有滚动条 文件拷贝到指定的路径处? 请问语音分帧的具体过程 求JPG缩略图(Thumbnail for jpg)源代码资源或建议 如何在VC中实现随机函数(在线等) 请问,MPEG流中存取单元和展现单元的区别?万分感谢 如何固定拆分的窗口的尺寸? 非模态对话框被激活时想做点事情,如何实现? 关于一个编译VC的一个有趣的问题! 如何在COM组件的中使用外部定义的类?
#include <afxtempl.h>
H:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxv_w32.h(14) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>上面说明Win32 App不能调用MFC。
如果确实要用MFC的函数,看来只能写DLL调用。
(1)把前面的MFC的类库中CTypedPtrList修改为标准C++库的对应的类,但不知道对应的类是什么。此外不知道此法可行否?
(2)不知道除了MFC,同步线程应该使用什么类或者API函数
修改 Project Options,将 /MT 或者 /ML 改为 /MD#include <afx.h>
#include <afxwin.h> // MFC core and standard componentsextern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
int nRetCode = 0; if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
TRACE0("Fatal Error: MFC initialization failed.\n");
nRetCode = 1;
}
else
{
// Actual WinMain codes ... AfxWinTerm();
} return nRetCode;
}
#include <afxwin.h>
再选择rebuild all,输出窗口如下:
Deleting intermediate files and output files for project 'PushSource - Win32 Debug Unicode'.
--------------------Configuration: PushSource - Win32 Debug Unicode--------------------
Compiling...
DataAdmin.cpp
FilePack.cpp
PushSourceBitmapSet.cpp
setup.cpp
Linking...
Creating library Debug_Unicode/PushBmpSet.lib and object Debug_Unicode/PushBmpSet.exp
DataAdmin.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDE
PushSourceBitmapSet.obj : error LNK2001: unresolved external symbol __afxForceEXCLUDE
DataAdmin.obj : error LNK2001: unresolved external symbol __afxForceUSRDLL
PushSourceBitmapSet.obj : error LNK2001: unresolved external symbol __afxForceUSRDLL
DataAdmin.obj : error LNK2001: unresolved external symbol "public: static void __stdcall CObject::operator delete(void *)" (??3CObject@@SGXPAX@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: __thiscall CMutex::CMutex(int,unsigned short const *,struct _SECURITY_ATTRIBUTES *)" (??0CMutex@@QAE@HPBGPAU_SECURITY_ATTRIBUTES@@@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: static void * __stdcall CObject::operator new(unsigned int)" (??2CObject@@SGPAXI@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CPtrList::~CPtrList(void)" (??1CPtrList@@UAE@XZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: void __thiscall CPtrList::RemoveAll(void)" (?RemoveAll@CPtrList@@QAEXXZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: struct __POSITION * __thiscall CPtrList::GetHeadPosition(void)const " (?GetHeadPosition@CPtrList@@QBEPAU__POSITION@@XZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: __thiscall CSingleLock::~CSingleLock(void)" (??1CSingleLock@@QAE@XZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CSingleLock::Unlock(void)" (?Unlock@CSingleLock@@QAEHXZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CPtrList::IsEmpty(void)const " (?IsEmpty@CPtrList@@QBEHXZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CSingleLock::IsLocked(void)" (?IsLocked@CSingleLock@@QAEHXZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CSingleLock::Lock(unsigned long)" (?Lock@CSingleLock@@QAEHK@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: __thiscall CSingleLock::CSingleLock(class CSyncObject *,int)" (??0CSingleLock@@QAE@PAVCSyncObject@@H@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: int __thiscall CPtrList::GetCount(void)const " (?GetCount@CPtrList@@QBEHXZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CPtrList::Dump(class CDumpContext &)const " (?Dump@CPtrList@@UBEXAAVCDumpContext@@@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CPtrList::AssertValid(void)const " (?AssertValid@CPtrList@@UBEXXZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CObject::Serialize(class CArchive &)" (?Serialize@CObject@@UAEXAAVCArchive@@@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CPtrList::GetRuntimeClass(void)const " (?GetRuntimeClass@CPtrList@@UBEPAUCRuntimeClass@@XZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: struct __POSITION * __thiscall CPtrList::AddTail(void *)" (?AddTail@CPtrList@@QAEPAU__POSITION@@PAX@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: void * & __thiscall CPtrList::GetHead(void)" (?GetHead@CPtrList@@QAEAAPAXXZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: void * __thiscall CPtrList::RemoveHead(void)" (?RemoveHead@CPtrList@@QAEPAXXZ)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: void * & __thiscall CPtrList::GetNext(struct __POSITION * &)" (?GetNext@CPtrList@@QAEAAPAXAAPAU__POSITION@@@Z)
DataAdmin.obj : error LNK2001: unresolved external symbol "public: __thiscall CPtrList::CPtrList(int)" (??0CPtrList@@QAE@H@Z)
PushSourceBitmapSet.obj : error LNK2001: unresolved external symbol "int __stdcall AfxAssertFailedLine(char const *,int)" (?AfxAssertFailedLine@@YGHPBDH@Z)
Debug_Unicode/PushBmpSet.ax : fatal error LNK1120: 25 unresolved externals
Error executing link.exe.PushBmpSet.ax - 28 error(s), 0 warning(s)
按照常理是缺少库文件,我应该加上什么库才好呢?
这个错误明显是文件没包含进来,建议你查查,例如:CPtrList::GetNext在那个文件定义的,加进去,而且前面缺少cobject的定义
warningDeleting intermediate files and output files for project 'PushSource - Win32 Debug Unicode'.
--------------------Configuration: PushSource - Win32 Debug Unicode--------------------
Compiling...
DataAdmin.cpp
FilePack.cpp
PushSourceBitmapSet.cpp
setup.cpp
Linking...
mfcs42ud.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in setup.obj
mfcs42ud.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in setup.obj; second definition ignored
Creating library Debug_Unicode/PushBmpSet.lib and object Debug_Unicode/PushBmpSet.exp
Debug_Unicode/PushBmpSet.ax : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.PushBmpSet.ax - 2 error(s), 1 warning(s)
谢谢上面各位友情跟贴。
问题已经解决。要点:1、加入相关的头文件,尤其是afx.h
2、确保MFC库在CRT库之前被link,可参考微软的文章ID:KB148652
查看afx.h文件中库如何链接的部分,选择合理的preprocessor
definitions
3、多问问题,集思广益to:webber84(***闭关修炼中***)
我在写一个directshow filter ,是Win32 DLL类型的
to:o_racle(璐璐) ( )
既然是link error,首先想到的不该是头文件没有include吧 :)