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