如何动态生成MSComm控件
choge 2011-01-04 10:47:37 新建一个工程,添加一个Unit2.代码如下:
Unit2.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include "Unit2.h"
#include <vcl.h>
#pragma package(smart_init)
#pragma link "MSCommLib_OCX"
//---------------------------------------------------------------------------
Test test1;
//---------------------------------------------------------------------------
Test::Test()
{
CoInitialize(NULL);
MSComm1 = new TMSComm((void*)(0));
MSComm1->CommPort=1;
MSComm1->RThreshold=1;
MSComm1->Settings="9600,e,8,1";
MSComm1->InputMode=0;
}
Unit2.h
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
#include "MSCommLib_OCX.h"
#include <OleCtrls.hpp>
//---------------------------------------------------------------------------
class Test
{
public:
Test();
private:
TMSComm *MSComm1;
};
//---------------------------------------------------------------------------
extern PACKAGE Test test1;
//---------------------------------------------------------------------------
#endif
可以通过Build,但一运行就报错。如果去掉.h文件中的extern PACKAGE Test test1;
和.cpp文件中的Test test1;则可以运行
请各位帮忙分析解决