我在程序中包含了<afx.h>,用了CString对象,链接时提示:nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex,为什么?
CPP文件:
#include "updategen.h"
void main()
{

initial();
}
//Get current directory
CString initial()
{
CString strDirName;
GetCurrentDirectory(50,strDirName.GetBuffer(50));  //the longest file directory is 50 
cout<<strDirName;
userDir=getchar();
return strDirName+userDir;
}
//Recurse all files not include subdirectories
void search(CString sDir)
{
CFile FileCreate;
CFileException Flag;
char *pFileName = "update.lst.txt";  //Created  file named is update.lst.txt
char *pbuf;
CString WriteContent;
CString FilePath;                   //file's path. example:"c:\my document\hello.dat"
CTime FileCreateTime;                //file's creating time. example:"2003-03-29 10:05"
CString CreatTime;
CString FileSize;
long lFilelength;                    //file's length. example:34k 
BOOL bSearchFileResult;              
CFileFind FileFinder;
//Creat update.lst.txt
if( !FileCreate.Open( pFileName, CFile::modeCreate, &Flag ) )
   {
#ifdef _DEBUG
afxDump << "File could not be Creat " << Flag.m_cause << "\n";
#endif
   }
//search files and get their shuxing
bSearchFileResult=FileFinder.FindFile(sDir); 
while(bSearchFileResult)
{
FileFinder.FindNextFile();
FilePath=FileFinder.GetFilePath();
FileFinder.GetCreationTime(FileCreateTime);
lFilelength=FileFinder.GetLength();
//write content to the update.lst.txt
FileSize.Format("   %ld   ",lFilelength);

CreatTime=FileCreateTime.Format("%D,%H,%M,%s");
WriteContent=FilePath+FileSize+CreatTime+"\n";
pbuf=WriteContent.GetBuffer(100);
FileCreate.Write(pbuf,100);
}
FileFinder.Close();
}
updategen.h:
#include<stdio.h>
#include<iostream.h>
#include<afx.h>
CString userDir;
CString initial();
void setDirector();
void search(CString sDir);
void getFileCreateTime();
void creatList();

解决方案 »

  1.   

    你可以选择一个 支持mfc 的 控制台 程序, 
     再试试看
      

  2.   

    我要的就是一个命令行的效果,要求不能用MFC的
      

  3.   

    如何选择一个 支持mfc 的 控制台 程序?
      

  4.   

    project->setting->C++->gategory:code grneration->use run time library:multithread dll
      

  5.   

    Preprocessor definitions 中定义 _AFXDLL ,Project Options 中把 /ML 改为 /MD然后在 main 中调用 AfxWinInit / AfxWinTerm
    if (AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
    // 实际代码 ... AfxWinTerm();
    }
      

  6.   

    i think you are using MFC in a Win32-App.
    Under Project - Settings - General "Microsoft Foundation Classes" choose
    "Use MFC in a shared DLL"
    and build your project.If you already had a MFC-Project, then you are probably linking with the
    single-threaded run-time library instead of multithreaded version.
    Q126646 PRB: Error Msg: LNK2001 on __beginthreadex and __endthreadex
    http://support.microsoft.com/support/kb/articles/Q126/6/46.ASP