Failed to create empty document错误
我在VC的SDI单文本模式下使用MSComm串口通讯控件, 步骤如下:
1. 单击主菜单project的子菜单Add To project的Components and Controls选项,在弹出的"Components and Controls Gallery"对话框中选择Registered ActiveX Controls文件夹中的"Microsoft Communications Control,version 6.0"选项
单击其中的"Insert"按钮,MSComm控件就被增加到工程中了。与此同时,类CMSComm的相关文件mscomm.h和mscomm.cpp也一并被加入Project的Header Files和Source Files中
2.在我的view类中增加, 头文件包含#include "mscomm.h"
protected: // create from serialization only
....
CMSComm m_ComPort;
protected:
afx_msg void OnComm();
DECLARE_EVENTSINK_MAP()
3.在view.cpp中增加
BEGIN_EVENTSINK_MAP(CConsoleView, CView)
//{{AFX_EVENTSINK_MAP(CConsoleView)
ON_EVENT(CConsoleView,IDC_MSCOMM1,1,OnComm,VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
4.在view.cpp中的
int CxxxView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
DWORD style = WS_VISIBLE;
if (!m_ComPort.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM1))
{
AfxMessageBox("Failed to create OLE Communications Control\n"); // fail to create
}
...
}
程序运行时候, 发现一运行到(!m_ComPort.Create就弹出一个错误提示: Failed to create empty document.
试了在dubug模式和release模式下都这样. 请问哪里有问题?