Visual Studio错误:未定义标识符

时间:2016-01-08 10:28:14

标签: c++ visual-studio visual-studio-2012

我在尝试执行以下C ++代码时遇到问题(在Windows 7 x64上使用microsoft visual studio Enterprise 2015):

//Test704.cpp : Defines the entry point for the console application.

//#include "StdAfx.h"
#include "704IO.h"
#include "Test704.h"

#ifdef _DEBUG
  #define new DEBUG_NEW
#endif

/////////////////////////////////////////////////////////////////////////////

CWinApp theApp;  // The one and only application object

/////////////////////////////////////////////////////////////////////////////

using namespace std;
/////////////////////////////////////////////////////////////////////////////

int _tmain(int argc, TCHAR *argv[], TCHAR *envp[])
{
int     nRetCode(0);
HMODULE hModule(::GetModuleHandle(NULL));
short   valueRead;

  if (hModule != NULL)
  {
    // Initialize MFC and print and error on failure
    if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
    {
      // TODO: change error code to suit your needs
      _tprintf(_T("Fatal Error: MFC initialization failed\n"));
      nRetCode = 1;
    }
    else
    {
      while(true)
      {
        valueRead = PortRead(1, 780, -1);
        _tprintf(_T("Value Read = %i\n"), valueRead);
        Sleep(1000);  // Sleep for 1s so we can see the value on the screen
      }
    }
  }
  else
  {
    // TODO: change error code to suit your needs
    _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
    nRetCode = 1;
  }

  return nRetCode;
}

/////////////////////////////////////////////////////////////////////////////

我有以下16个错误:

Identifier "CWinApp" not defined (line 13)
Identifier "TCHAR" not defined (line 20)
Identifier "TCHAR" not defined (line 20)
Identifier "HMODULE" not defined (line 23)
The global scope doesn't have "GetModuleHandle" (line 23)
Identifier "NULL" not defined (23)
Identifier "AfxWinInit" not defined (29)
The global scope doesn't have "GetCommandLine" (line 29)
Identifier "_tprintf" not defined (line 32)
Identifier "_T" not defined (line 32)
Identifier "_tprintf" not defined (line 40)
Identifier "_T" not defined (line 40)
Identifier "Sleep" not defined (line 41)
Identifier "_tprintf" not defined (line 48)
Identifier "_T" not defined (line 48)
TRK0005: Failed to localize "CL.exe": The specified file cannot be found (line 1)

但是我已经在Windows 7 x32计算机上使用另一个版本的visual studio(2012)执行了此代码,并且它运行良好。我怀疑错误与我的配置有关......你有什么想法吗?

0 个答案:

没有答案