找不到标识符、未声明的标识符

原文链接:http://www.cnblogs.com/SZxiaochun/p/7525396.html

1.error C3861: “_T”: 找不到标识符
  #include <tchar.h>

2.error C3861: “time”: 找不到标识符

  查看代码,发现已经包含了 time.h 头文件,不应该报这个错误啊。
  找了半天,发现项目文件中有一个叫 Time.h 的头文件,可能是和vs自带的time.h冲突了。
  将该 Time.h 头文件改名为 MyTime.h 之后,再把原来引用 Time.h 的地方 替换成 MyTime.h 就好了。

 

3.“ifstream” 未声明的标识符

  #include <fstream>
  还要加入:
  using namespace std;

4.error C2065: “BYTE”: 未声明的标识符

  #include <Windows.h>

转载于:https://www.cnblogs.com/SZxiaochun/p/7525396.html

展开阅读全文
博主设置当前文章不允许评论。

未声明标识符 的问题.

06-23

这是个DLL 挂钩rnrn// KeybdHook.cpp : 定义 DLL 的初始化例程。rn//rn#pragma data_seg(".SHARDAT")rnstatic HWND ghWndMain = 0;rnstatic HHOK ghKeyHook = NULL;rn#pragma data_seg()rn HINSTANCE ghInstance = 0;rn HOOKPROC glpfnHookProc = 0;rnrn#include "stdafx.h"rn#include "KeybdHook.h"rn#include ".\keybdhook.h"rnrn#ifdef _DEBUGrn#define new DEBUG_NEWrn#endifrnrnLRESULT EXPORTED_DLL_FUNCTION KbdHookProc (int nCode, WPARAM wParam, LPARAM lParam)rnrn BOOL bHandledKeystroke = FALSE;rnrn if(((DWORD)lParam & 0x40000000) && (HC_ACTION == nCode))rn rn switch (wParam)rn rn case VK_F10:rn AfxMessageBox("捕获F10");rn bHandledKeystroke = TRUE;rn break;rnrn default:rn break;rn rn rnrn return (bHandledKeystroke?TRUE:CallNextHookEx (ghKeyHook, nCode, wParam ,lParam));rnrnrnBOOL EXPORTED_DLL_FUNCTION InstallKeyboardHook (HWND hWnd)rnrn BOOL bSuccess = FALSE;rn if(!ghKeyHook)rn rn ghWndMain = hWnd;rn glpfnHookProc = (HOOKPROC)KbdHookProc;rnrn bSuccess = (NULL != (ghKeyHook = SetWindowsHookEx (WH_KEYBOARD, glpfnHookProc, ghInstance, NULL)));rn rnrn return bSuccess;rnrnrnBOOL EXPORTED_DLL_FUNCTION DeInstallKeyboardHook (HWND hWnd)rnrn if(ghKeyHook)rn rn if(TRUE == (0 != UnhookWindowsHookEx(ghKeyHook)))rn rn ghKeyHook = NULL;rn rn rnrn return ( NULL == ghKeyHook);rnrnrnc:\Documents and Settings\dyt\My Documents\Visual Studio Projects\KeybdHook\KeybdHook.cpp(36) : error C2065: “ghKeyHook” : 未声明的标识符rnc:\Documents and Settings\dyt\My Documents\Visual Studio Projects\KeybdHook\KeybdHook.cpp(42) : error C3861: “ghKeyHook”: 即使使用参数相关的查找,也未找到标识符rnc:\Documents and Settings\dyt\My Documents\Visual Studio Projects\KeybdHook\KeybdHook.cpp(44) : error C2065: “ghWndMain” : 未声明的标识符rnc:\Documents and Settings\dyt\My Documents\Visual Studio Projects\KeybdHook\KeybdHook.cpp(45) : error C2065: “glpfnHookProc” : 未声明的标识符rnc:\Documents and Settings\dyt\My Documents\Visual Studio Projects\KeybdHook\KeybdHook.cpp(47) : error C2065: “ghInstance” : 未声明的标识符rnrn我在顶头定义了,为什么说未声名 论坛

求助:“未声明标识符

07-06

一个实现邮件发送的程序。头文件和实现文件如下:rn头文件 IMapi.h :rn#pragma oncern#include "stdafx.h"rn#include rnclass CIMapirnrnpublic:rn CIMapi(void);rn ~CIMapi(void);rn enum errorCodesrn rn IMAPI_SUCCESS=0,rn IMPAI_LOADFAILED,rn IMPAI_INVALIDDLL,rn IMPAI_FAILTO,rn IMAPI_FAILCC,rn IMAPI_FAILATTACHrn ;rn void Subject(LPCTSTR text) //设置主题rn rn m_message.lpszSubject=(LPTSTR) subject;rn rn void Text(LPCTSTR text) //设置主文本rn rn m_text=text;rn rn UINT Error();rn void From (LPCTSTR) //发件人rn rn m_from.lpszName=(LPTSTR) from;rn rnrn static BOOL HasEamil();rnrn BOOL To (LPCTSTR recip); //收件人rn BOOL Cc (LPCTSTR recip);rn BOOL Attach(LPCTSTR attachment); //设置附件rn BOOL Send(ULONG flags=0); //发送邮件rnrnprivate:rn BOOL AllocNewTo();rn MapiMessage m_message;rn MapiRecipDesc m_from;rn UINT m_error;rn CString m_text;rnrn ULONG (PASCAL *m_lpfnSendMail)(ULONG,ULONG,MapiMessage*,FLAGS,ULONG);rnrn static HINSTANCE m_hInstMail;rn static BOOL m_isMailAvail;rn;rnrnrn实现文件:rnrn#include "stdafx.h"rn#include rn#include "IMapi.h"rnrnHINSTANCE CIMapi::m_hInstMail=(HINSTANCE) NULL;rnBOOL CIMapi::m_isMailAvail=(BOOL) -1;rnrnCIMapi::CIMapi(void)rnrn m_error=0; //初始化错误消息rnrn memset (&m_message,0,sizeof(MapiMessage));rn memset (&m_from,0,sizeof(MapiRecipDesc));rn m_message.lpOriginator=&m_from;rn m_from.ulRecipClass=MAPI_ORIG;rnrn if (m_hInstMail==(HINSTANCE) NULL) //载入MAPIrn m_hInstMail=::LoadLibraryA ("MAPI32.DLL");rnrnrn if (m_hInstMail==(HINSTANCE) NULL)rn AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);rn m_error=IMAPI_LOADFAILED;rn return;rnrn ASSERT (m_hInstMail!=(HINSTANCE)NULL);rn //取得发送函数的指针rn (FARPROC&)m_lpfnSendMail=GetProcAddress(m_hInstMail,"MAPISendMail");rnrn if (m_lpfnSendMail==NULL)rn rn AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL);rn m_error=IMAPI_INVALIDDLL;rn return;rn rn ASSERT (m_lpfnSendMail!=NULL);rnrnrnCIMapi::~CIMapi(void)rnrn if (m_hInstMail!=(HINSTANCE)NULL)rn ::FreeLibrary(m_hInstMail);rn m_hInstMail=(HINSTANCE)NULL;rnrn free (m_message.lpFiles);rn free (m_message.lpRecips);rnrnBOOL CIMapi::HasEamil()rnrn if(m_isMailAvail==(BOOL)-1)rn m_isMailAvail=::GetProfileInt(_T ("MAIL"),_T("MAPI"),0)!=0&&SearchPath(NULL,_T("MAPI32.DLL"),NULL,0,NULL,NULL)!=0;rn return m_isMailAvail;rnrn//对出错的处理rnUINT CIMapi::Error()rnrn UINT temp=m_error;rnrn m_error=IMAPI_SUCCESS;rn return temp;rnrnBOOL CIMapi::AllocNewTo()rnrn //对MapiRecipDesc分配内存,并初始化为0rn m_message.lpRecips=(MapiRecipDesc *) realloc(m_message.lpRecips,(m_message.nRecipCount+1)*sizeof(MapiRecipDesc));rn memset(&m_message.lpRecips[m_message.nRecipCount],0,sizeof(MapiRecipDesc));rn ASSERT(m_message.lpRecips);rn return m_message.lpRecips!=(MapiRecipDesc*)NULL;rnrn//实现收件人rnBOOL CIMapi::To(LPCTSTR recip)rnrn if (AllocNewTo())rn rn //内存分配成功rn m_message.lpRecips[m_message.nRecipCount].lpszName=(LPTSTR)recip;rn m_message.lpRecips[m_message.nRecipCount].ulRecipClass=MAPI_TO;rn rn m_error=IMAPI_FAILTO;rn return FALSE;rnrnrnBOOL CIMapi::Cc(LPCTSTR recip)rnrn if (AllocNewTo())rn rn m_message.lpRecips[m_message.nRecipCount].lpszName=(LPTSTR)recip;rn m_message.lpRecips[m_message.nRecipCount].ulRecipClass=MAPI_CC;rn m_message.nRecipCount++;rn return TRUE;rn rn m_error=IMAPI_FAILCC;rn return FALSE;rnrn //实现附件rn BOOL CIMapi::Attach(LPCTSTR attachment)rn rn //增加一个新的附件rn m_message.lpFiles=(MapiFileDesc *) realloc(m_message.lpFiles,(m_message.nFileCount+1)*sizeof(MapiFilesDesc));rn memset(&m_message.lpFiles[m_message.nFileCount],0,sizeof (MapiFileDesc));rnrn ASSERT(m_message.lpFiles);rnrn if(m_message.lpFiles==(MapiFileDesc*)NULL)rn rn m_error=IMAPI_FAILATTACH;rn return FALSE;rn rnrn m_message.lpFiles[m_message.nFileCount].lpszPathName=(LPTSTR)attachment;rn m_message.lpFiles[m_message.nFileCount].lpszFileName=(LPTSTR)NULL;rn m_message.nFileCount++;rn return TRUE;rn rnrn //发送邮件rn BOOL CIMapi::Send(ULONG flags)rn rn CWaitCursor wait;rn intoffset=m_text.GetLength();rnrn //在文本的后面给附件划分空间rn m_text +=CString(' ',m_message.nFileCount);rnrn //将附件放入文本后面rn for(UINT i=0;iEnableModeless(FALSE);rn HWND hWndTop;rn CWnd*pParentWnd=CWnd::GetSafeOwner(NULL,&hWndTop);rn pParentWnd->SetCapture();rn ::SetFocus(FULL);rn pParentWnd->m_nFlags|=WF_STAYDISABLED;rn int nError =m_lpfnSendMail(0,(ULONG)pParentWnd->GetSafeHwnd(),&m_message,MAPI_LOGON_UI|flags,0);rn ::ReleaseCapture();rn pParentWnd->m_nFlags&=-WF_STAYDISABLED;rn pParentWnd->EnableWindow(TRUE);rn ::SetActiveWindow(NULL);rn pParentWnd->SetActiveWindow();rn pParentWnd->SetFocus();rn if (hWndTop!=NULL)rn ::EnableWindow(hWndTop,TRUE);rn AfxGetApp()->EnableModeless(TRUE);rn if (nError!=SUCCESS_SUCCESS && nError!=MAPI_USER_ABORT&&nError!=MAPI_LOGIN_FAILURE)rn rn AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND);rn return FALSE;rn rn return TRUE;rn rnrnrnrn编译时报错:rnrnIMapi.cpprnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.h(20) : error C2065: “subject”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.h(29) : error C2065: “from”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(23) : error C2065: “IMAPI_LOADFAILED”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(33) : error C2065: “IMAPI_INVALIDDLL”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(76) : error C2440: “=”: 无法从“LPTSTR”转换为“LPSTR”rn 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(79) : error C2065: “IMAPI_FAILTO”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(87) : error C2440: “=”: 无法从“LPTSTR”转换为“LPSTR”rn 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(99) : error C2065: “MapiFilesDesc”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(99) : error C2070: “'unknown-type'”: 非法的 sizeof 操作数rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(110) : error C2440: “=”: 无法从“LPTSTR”转换为“LPSTR”rn 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(111) : error C2440: “=”: 无法从“LPTSTR”转换为“LPSTR”rn 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(120) : error C2065: “intoffset”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(127) : error C2065: “offset”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(135) : error C2065: “FULL”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(137) : warning C4311: “类型转换”: 从“HWND”到“ULONG”的指针截断rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.cpp(147) : error C2065: “MAPI_LOGIN_FAILURE”: 未声明的标识符rnSendEmailDlg.cpprnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.h(20) : error C2065: “subject”: 未声明的标识符rnc:\documents and settings\administrator\桌面\sendemail\sendemail\sendemail\imapi.h(29) : error C2065: “from”: 未声明的标识符rnrnrn请问大虾们是哪点出错?难道是还要包含什么头文件? 论坛

没有更多推荐了,返回首页