热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MFC安装MSCOMM控件(解决没有put_PortOpen、get_PortOpen等函数的问题)

MFC安装MSCOMM控件(解决没有put_PortOpen、get_PortOpen等函数的问题)1.下载MSCOMM2.注册MsComm控件3.在程


MFC安装MSCOMM控件(解决没有put_PortOpen、get_PortOpen等函数的问题)

    • 1.下载MSCOMM
    • 2.注册MsComm控件
    • 3.在程序里添加控件
    • 4.解决没有put_PortOpen()、get_PortOpen()等函数的问题


1.下载MSCOMM

网上有很多博客的资源要么收费、要么百度网盘的资源被和谐、要么就没有,这里贴出一个我找到的可以下载的链接。
https://www.ocxme.com/files/mscomm32_ocx


2.注册MsComm控件

下载完解压后就是MSCOMM32.0CX,然后将其复制到

C:\Windows\SysWOW64目录下(64位系统),32位系统为C:\Windows\system32目录,然后以管理员身份运行cmd,进入对应目录输入指令regsvr32 MSCOMM32.OCX。(如下图所示、注意要以管理员身份运行)
在这里插入图片描述
网上有些教程修改了注册表,但是我发现注册表已经修改了,无需手动修改。


3.在程序里添加控件

首先插入控件,在资源视图中打开_DIALOG结尾的文件,出现可视化的界面,右键,点击“插入ActiviteX控件”,如下图所示。
在这里插入图片描述
在这里插入图片描述
是一个小电话的图标,如下图所示。
在这里插入图片描述
接下来为控件添加变量。
在这里插入图片描述
在这里插入图片描述
上面操作是创建了一个类,类名为CMscomm。

上述过程与网上大部分教程大同小异,我不再多说,我一步一步跟着别人的教程做的时候,在主对话框的cpp文件中调用m_comm.put_PortOpen()、m_mscom.get_PortOpen()等函数的时候出现了未定义的情况,但网上大部分未给出解决的办法,我很纳闷,难道大家都没出现这种情况么?于是我下载了好几个不同的MSCOMM,发现都出现了这个情况,可能是我的安装出现了问题??我也不太清楚,反正最后找的的解决办法如下。


4.解决没有put_PortOpen()、get_PortOpen()等函数的问题

在CMscomm.h中找的如下代码

// 操作
public:

在public中添加下述代码

// IMSComm// Functions//void put_CDHolding(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_CDHolding(){BOOL result;InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_CDTimeout(long newValue){static BYTE parms[] = VTS_I4;InvokeHelper(0x2, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}long get_CDTimeout(){long result;InvokeHelper(0x2, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);return result;}void put_CommID(long newValue){static BYTE parms[] = VTS_I4;InvokeHelper(0x3, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}long get_CommID(){long result;InvokeHelper(0x3, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);return result;}void put_CommPort(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0x4, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_CommPort(){short result;InvokeHelper(0x4, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put__CommPort(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0x0, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get__CommPort(){short result;InvokeHelper(0x0, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_CTSHolding(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0x5, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_CTSHolding(){BOOL result;InvokeHelper(0x5, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_CTSTimeout(long newValue){static BYTE parms[] = VTS_I4;InvokeHelper(0x6, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}long get_CTSTimeout(){long result;InvokeHelper(0x6, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);return result;}void put_DSRHolding(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0x7, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_DSRHolding(){BOOL result;InvokeHelper(0x7, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_DSRTimeout(long newValue){static BYTE parms[] = VTS_I4;InvokeHelper(0x8, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}long get_DSRTimeout(){long result;InvokeHelper(0x8, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);return result;}void put_DTREnable(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0x9, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_DTREnable(){BOOL result;InvokeHelper(0x9, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_Handshaking(long newValue){static BYTE parms[] = VTS_I4;InvokeHelper(0xa, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}long get_Handshaking(){long result;InvokeHelper(0xa, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);return result;}void put_InBufferSize(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0xb, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_InBufferSize(){short result;InvokeHelper(0xb, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_InBufferCount(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0xc, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_InBufferCount(){short result;InvokeHelper(0xc, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_Break(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0xd, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_Break(){BOOL result;InvokeHelper(0xd, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_InputLen(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0xe, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_InputLen(){short result;InvokeHelper(0xe, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_Interval(long newValue){static BYTE parms[] = VTS_I4;InvokeHelper(0xf, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}long get_Interval(){long result;InvokeHelper(0xf, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);return result;}void put_NullDiscard(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0x10, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_NullDiscard(){BOOL result;InvokeHelper(0x10, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_OutBufferSize(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0x11, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_OutBufferSize(){short result;InvokeHelper(0x11, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_OutBufferCount(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0x12, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_OutBufferCount(){short result;InvokeHelper(0x12, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_ParityReplace(LPCTSTR newValue){static BYTE parms[] = VTS_BSTR;InvokeHelper(0x13, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}CString get_ParityReplace(){CString result;InvokeHelper(0x13, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);return result;}void put_PortOpen(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0x14, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_PortOpen(){BOOL result;InvokeHelper(0x14, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_RThreshold(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0x15, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_RThreshold(){short result;InvokeHelper(0x15, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_RTSEnable(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0x16, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_RTSEnable(){BOOL result;InvokeHelper(0x16, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_Settings(LPCTSTR newValue){static BYTE parms[] = VTS_BSTR;InvokeHelper(0x17, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}CString get_Settings(){CString result;InvokeHelper(0x17, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);return result;}void put_SThreshold(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0x18, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_SThreshold(){short result;InvokeHelper(0x18, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_Output(VARIANT newValue){static BYTE parms[] = VTS_VARIANT;InvokeHelper(0x19, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, &newValue);}VARIANT get_Output(){VARIANT result;InvokeHelper(0x19, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL);return result;}void put_Input(VARIANT newValue){static BYTE parms[] = VTS_VARIANT;InvokeHelper(0x1a, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, &newValue);}VARIANT get_Input(){VARIANT result;InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL);return result;}void put_CommEvent(short newValue){static BYTE parms[] = VTS_I2;InvokeHelper(0x1b, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}short get_CommEvent(){short result;InvokeHelper(0x1b, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);return result;}void put_EOFEnable(BOOL newValue){static BYTE parms[] = VTS_BOOL;InvokeHelper(0x1c, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}BOOL get_EOFEnable(){BOOL result;InvokeHelper(0x1c, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);return result;}void put_InputMode(long newValue){static BYTE parms[] = VTS_I4;InvokeHelper(0x1d, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);}long get_InputMode(){long result;InvokeHelper(0x1d, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);return result;}void AboutBox(){InvokeHelper(DISPID_ABOUTBOX, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);}// Properties//

并在主对话框的头文件中添加

#include "CMscomm.h"

至此便可解决MFC没有put_PortOpen、get_PortOpen等函数的问题。

参考:
https://www.jianshu.com/p/a2020b4f2a9f
https://www.jianshu.com/p/5c54338b67b2


推荐阅读
author-avatar
的撒旦
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有