请教高手?

zjsunjifu 2003-12-12 10:17:57
我在dll中调用了activex控件--CMSComm,定义了一个CMSComm的对象m_Comm,并做了如下代码:

// SerialComDll.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "SerialComDll.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//

/////////////////////////////////////////////////////////////////////////////
// CSerialComDllApp

BEGIN_MESSAGE_MAP(CSerialComDllApp, CWinApp)
//{{AFX_MSG_MAP(CSerialComDllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSerialComDllApp construction
CMSComm m_Comm;//定义了一个全局对象

CSerialComDllApp::CSerialComDllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CSerialComDllApp object

CSerialComDllApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CSerialComDllApp initialization

BOOL CSerialComDllApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}

if(m_Comm.GetPortOpen())
m_Comm.SetPortOpen(FALSE);

m_Comm.SetCommPort(1); //选择com1
if( !m_Comm.GetPortOpen())
m_Comm.SetPortOpen(TRUE);//打开串口
else
AfxMessageBox("cannot open serial port");

m_Comm.SetSettings("9600,n,8,1"); //波特率9600,无校验,8个数据位,1个停止位

m_Comm.SetInputMode(1); //1:表示以二进制方式检取数据
m_Comm.SetRThreshold(1);
//参数1表示每当串口接收缓冲区中有多于或等于1个字符时将引发一个接收数据的OnComm事件
m_Comm.SetInputLen(0); //设置当前接收区数据长度为0
m_Comm.GetInput();//先预读缓冲区以清除残留数据

return TRUE;
}


extern "C" BOOL __declspec(dllexport) UpDataStream(CString *)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
//To add
return 0;
}
/*
extern "C" _declspec(dllexport) BOOL GetPortOpen()
{

AFX_MANAGE_STATE(AfxGetStaticModuleState());
BOOL result;
result = m_Comm.GetPortOpen();
return result;
}

extern "C" _declspec(dllexport) VARIANT GetInput()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
VARIANT result;
result = m_Comm.GetInput();
return result;
}

extern "C" _declspec(dllexport) short GetCommEvent()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
short result;
result = m_Comm.GetCommEvent();
return result;
}

extern "C" _declspec(dllexport) void SetCommPort(short nNewValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_Comm.SetCommPort(nNewValue);
}

extern "C" _declspec(dllexport) void SetPortOpen(BOOL bNewValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_Comm.SetPortOpen(bNewValue);
}

extern "C" _declspec(dllexport) void SetInputMode(long nNewValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_Comm.SetInputMode(nNewValue);
}

extern "C" _declspec(dllexport) void SetRThreshold(short nNewValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_Comm.SetRThreshold(nNewValue);
}

extern "C" _declspec(dllexport) void SetInputLen(short nNewValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_Comm.SetInputLen(nNewValue);
}

extern "C" _declspec(dllexport) void SetSettings(LPCTSTR lpszNewValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_Comm.SetSettings(lpszNewValue);
}*/

extern "C" void __declspec(dllexport) SetOutput(const VARIANT& newValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_Comm.SetOutput(newValue);
}
给程序加断点,每次在执行到m_Comm.的任何成员函数是都有如下错误发生:
Debug Assertin failed!
program G:\sjf\SerialComTest\debug\SerialComTest.exe
File:winocc.cpp
Line:345
跟踪断点后,进入到如下代码中

void AFX_CDECL CWnd::InvokeHelper(DISPID dwDispID, WORD wFlags, VARTYPE vtRet,
void* pvRet, const BYTE* pbParamInfo, ...)
{
ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)(此处为箭头所指的地方)

if (m_pCtrlSite == NULL)
return;

va_list argList;
va_start(argList, pbParamInfo);
m_pCtrlSite->InvokeHelperV(dwDispID, wFlags, vtRet, pvRet, pbParamInfo,
argList);
va_end(argList);
}
请问这是什么原因呀,
...全文
48 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
进程/线程/DLL
加入

1.5w+

社区成员

VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
申请成为版主
帖子事件
创建了帖子
2003-12-12 10:17
社区公告
暂无公告