MFC串口通信 GPS定位实现 VC MFC

  • 注册MSCOMM
    • MFC实现
      • 测试

一. 注册MSCOMM

1.下载控件MSCOMM32.OCX(32位)
百度网盘链接链接:

https://pan.baidu.com/s/1pf8js-BNhL1Mh1XvYoFetw

提取码:

z45s

2.把这个ocx文件放在c盘WIndows的system32里,打开cmd执行:

regsvr32 MSCOMM32.OCX

(32位)
3.在c盘WIndows的syswow64里,打开cmd执行:

regsvr32 c:\windows\syswow64\mswnisck.OCX

(64位)
4.在上面三步之后,如果还是有问题,可以执行下面的操作
把内容存为.reg文件。

Windows Registry Editor Version 5.00.reg

双击导入注册表即可。

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Licenses]
@="Licensing: Copying the keys may be a violation of established copyrights."
[HKEY_CLASSES_ROOT\Licenses\096EFC40-6ABF-11cf-850C-08002B30345D]
@="knsgigmnmngnmnigthmgpninrmumhgkgrlrk"
[HKEY_CLASSES_ROOT\Licenses\12B142A4-BD51-11d1-8C08-0000F8754DA1]
@="aadhgafabafajhchnbchehfambfbbachmfmb"
[HKEY_CLASSES_ROOT\Licenses\190B7910-992A-11cf-8AFA-00AA00C00905]
@="gclclcejjcmjdcccoikjlcecoioijjcjnhng"
[HKEY_CLASSES_ROOT\Licenses\1F3D5522-3F42-11d1-B2FA-00A0C908FB55]
@="gcfjdjecpchcncdjpdejijgcrdoijjfcieod"
[HKEY_CLASSES_ROOT\Licenses\1FB639E1-771F-11d1-8FD4-00A0C91E29D5]
@="ldaskjeinankjgbnkcejnkrgnkvntkhzkhbtnkste"
[HKEY_CLASSES_ROOT\Licenses\2AC5863D-48B9-490c-ACD3-B7723A1FEB9E]
@="wrtgfdsbvxgfsdyuihjknmvcxgasdwqersdfdfsdyu"
[HKEY_CLASSES_ROOT\Licenses\2c49f800-c2dd-11cf-9ad6-0080c7e7b78d]
@="mlrljgrlhltlngjlthrligklpkrhllglqlrk"
[HKEY_CLASSES_ROOT\Licenses\38911DA0-E448-11D0-84A3-00DD01104159]
@="mcpckchcdchjcjcclidcgcgchdqdcjhcojpd"
[HKEY_CLASSES_ROOT\Licenses\4250E830-6AC2-11cf-8ADB-00AA00C00905]
@="kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\43478d75-78e0-11cf-8e78-00a0d100038e]
@="imshohohphlmnhimuinmphmmuiminhlmsmsl"
[HKEY_CLASSES_ROOT\Licenses\46D504D7-557F-4C19-A4DD-6605411EF496]
"6A7693BA-3139-41fd-BF3D-299961C965D5"="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b0cfa8651eed814ea8aa77984d1819530400000018000000560053002000500049004400200049006e0066006f00000003660000a80000001000000056a66542c85db014774bffecdc56384e0000000004800000a000000010000000b10a1f771bc4b05515b611500ced2faf10000000263d1b0a183042c62cd7792b75683b4e14000000f30b3972d0fa2871120efa9fba18a3c245e584c2"
@="gknalnanccemnhitviluhawerycnonilwjawreacop"
"CCF5A555-D92E-457b-9235-2B326B64035A"="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b0cfa8651eed814ea8aa77984d1819530400000018000000560053002000500049004400200049006e0066006f00000003660000a8000000100000003311a4ed781bba0eb740244ec6be37e10000000004800000a0000000100000000ef4da56cd76cee7c81f1227b555434f080000000beff2eed562c9a114000000b389c01205cde0aa29234083954295bef840a8c3"
[HKEY_CLASSES_ROOT\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905]
@="gfjmrfkfifkmkfffrlmmgmhmnlulkmfmqkqj"
[HKEY_CLASSES_ROOT\Licenses\4F86BADF-9F77-11d1-B1B7-0000F8753F5D]
@="iplpwpnippopupiivjrioppisjsjlpiiokuj"
[HKEY_CLASSES_ROOT\Licenses\556C75F1-EFBC-11CF-B9F3-00A0247033C4]
@="xybiedobrqsprbijaegcbislrsiucfjdhisl"
[HKEY_CLASSES_ROOT\Licenses\57CBF9E0-6AA7-11cf-8ADB-00AA00C00905]
@="aahakhchghkhfhaamghhbhbhkbpgfhahlfle"
[HKEY_CLASSES_ROOT\Licenses\5BCBC240-27DF-49C1-8C1C-27B8463009A9]
"6A7693BA-3139-41fd-BF3D-299961C965D5"="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b0cfa8651eed814ea8aa77984d18195304000000560000004d006900630072006f0073006f00660074002000560069007300750061006c002000530074007500640069006f00200054007200690061006c002000450064006900740069006f006e0020006400610074006100000003660000a800000010000000c7e1d2e887c57b9814ce91d6c44249ae0000000004800000a00000001000000035f65ddd0c11d820b0b7a72d384e4f08100000006e568533309b0e78012ede394f29e6d81400000080691310641b0c5f28070f7f29fe3acb3d3531a9"
@="iqtdwslvccydcyhxabrcudupqdcalezvinyxwsdjgb"
"CCF5A555-D92E-457b-9235-2B326B64035A"="01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b0cfa8651eed814ea8aa77984d18195304000000560000004d006900630072006f0073006f00660074002000560069007300750061006c002000530074007500640069006f00200054007200690061006c002000450064006900740069006f006e0020006400610074006100000003660000a800000010000000157910d280b079e9030212f831ef8dd00000000004800000a00000001000000091b4ddfcf5198d358efe2a227e391200080000008943decdf61422b0140000006eafe0247bfe0b38ba34c5a3fc6106d9bae97edb"
[HKEY_CLASSES_ROOT\Licenses\6000720D-F342-11D1-AF65-00A0C90DCA10]
@="kefeflhlhlgenelerfleheietfmflelljeqf"
[HKEY_CLASSES_ROOT\Licenses\6FB38640-6AC7-11cf-8ADB-00AA00C00905]
@="gdjkokgdldikhdddpjkkekgknesjikdkoioh"
[HKEY_CLASSES_ROOT\Licenses\72E67120-5959-11cf-91F6-C2863C385E30]
@="ibcbbbebqbdbciebmcobmbhifcmciibblgmf"
[HKEY_CLASSES_ROOT\Licenses\73A4C9C1-D68D-11d0-98BF-00A0C90DC8D9]
[HKEY_CLASSES_ROOT\Licenses\73A4C9C1-D68D-11d0-98BF-00A0C90DC8D9\11.0]
[HKEY_CLASSES_ROOT\Licenses\73A4C9C1-D68D-11d0-98BF-00A0C90DC8D9\11.0\Retail]
@="sbbcdcprktpjtapmmfdacmupasbhscddncgp"
[HKEY_CLASSES_ROOT\Licenses\743A8267-4958-460e-B757-7110EED3D53C]
@="erwreffdrtetyuiopupoinjxsdfwdxvdgwertdxoui"
[HKEY_CLASSES_ROOT\Licenses\74872840-703A-11d1-A3AF-00A0C90F26FA]
@="mninuglgknogtgjnthmnggjgsmrmgniglish"
[HKEY_CLASSES_ROOT\Licenses\74872841-703A-11d1-A3AF-00A0C90F26FA]
@="klglsejeilmereglrfkleeheqkpkelgejgqf"
[HKEY_CLASSES_ROOT\Licenses\78E1BDD1-9941-11cf-9756-00AA00C00908]
@="yjrjvqkjlqqjnqkjvprqsjnjvkuknjpjtoun"
[HKEY_CLASSES_ROOT\Licenses\7C35CA30-D112-11cf-8E72-00A0C90F26F8]
@="whmhmhohmhiorhkouimhihihwiwinhlosmsl"
[HKEY_CLASSES_ROOT\Licenses\80E80EF0-DBBE-11D0-BCE2-00A0C90DCA10]
@="qijimitpmpnpxplpvjnikpkpqoxjmpkpoivj"
[HKEY_CLASSES_ROOT\Licenses\899B3E80-6AC6-11cf-8ADB-00AA00C00905]
@="wjsjjjlqmjpjrjjjvpqqkqmqukypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\9DF1A470-BA8E-11D0-849C-00A0C90DC8A9]
@="cchcqjejhcgcqcfjpdfcdjkckiqikchcojpd"
[HKEY_CLASSES_ROOT\Licenses\9E799BF1-8817-11cf-958F-0020AFC28C3B]
@="uqpqnqkjujkjjjjqwktjrjkjtkupsjnjtoun"
[HKEY_CLASSES_ROOT\Licenses\A133F000-CCB0-11d0-A316-00AA00688B10]
@="cibbcimbpihbbbbbnhdbeidiocmcbbdbgdoc"
[HKEY_CLASSES_ROOT\Licenses\a8a9f020-b426-11cf-bf3b-00a0d10003fa]
@="eesjgjnekjeeheijrfheiegepftigeljfepi"
[HKEY_CLASSES_ROOT\Licenses\AC0871D0-6ACC-11cf-8ADB-00AA00C00905]
@="knjnpgognginknggsmnnhnjnumvmlngnrlrk"
[HKEY_CLASSES_ROOT\Licenses\AEA64E56-7C97-4a1c-8974-4E0BB4E48FCD]
@="reuikcxsdrecfgfbvnhjkjlpouiyuqwsdrtrtbvgcv"
[HKEY_CLASSES_ROOT\Licenses\B1692F60-23B0-11D0-8E95-00A0C90F26F8]
@="mjjjccncgjijrcfjpdfjfcejpdkdkcgjojpd"
[HKEY_CLASSES_ROOT\Licenses\B1EFCCF0-6AC1-11cf-8ADB-00AA00C00905]
@="qqkjvqpqmqjjpqjjvpqqkqmqvkypoqjquoun"
[HKEY_CLASSES_ROOT\Licenses\BC96F860-9928-11cf-8AFA-00AA00C00905]
@="mmimfflflmqmlfffrlnmofhfkgrlmmfmqkqj"
[HKEY_CLASSES_ROOT\Licenses\C4145310-469C-11d1-B182-00A0C922E820]
@="konhqhioohihphkouimonhqhvnwiqhhhnjti"
[HKEY_CLASSES_ROOT\Licenses\CDE57A55-8B86-11D0-b3C6-00A0C90AEA82]
@="ekpkhddkjkekpdjkqemkfkldoeoefkfdjfqe"
[HKEY_CLASSES_ROOT\Licenses\CEDD4F80-B43C-11cf-837C-00AA00573EDE]
@=hex(2):67,00,78,00,77,00,61,00,65,00,7a,00,75,00,63,00,66,00,79,00,71,00,70,\
00,77,00,6a,00,67,00,71,00,62,00,63,00,6d,00,74,00,73,00,6e,00,63,00,75,00,\
68,00,77,00,73,00,6e,00,79,00,68,00,69,00,6f,00,68,00,77,00,78,00,7a,00,00,\
00
[HKEY_CLASSES_ROOT\Licenses\D015B071-D2ED-11d0-A31A-00AA00688B10]
@="gjdcfjpcmjicjcdcoihcechjlioiccechepd"
[HKEY_CLASSES_ROOT\Licenses\DC4D7920-6AC8-11cf-8ADB-00AA00C00905]
@="iokouhloohrojhhhtnooiokomiwnmohosmsl"
[HKEY_CLASSES_ROOT\Licenses\E32E2733-1BC5-11d0-B8C3-00A0C90DCA10]
@="kmhfimlflmmfpffmsgfmhmimngtghmoflhsg"
[HKEY_CLASSES_ROOT\Licenses\ED4B87C4-9F76-11d1-8BF7-0000F8754DA1]
@="knlggnmntgggrninthpgmnngrhqhnnjnslsh"
[HKEY_CLASSES_ROOT\Licenses\

二. MFC实现

1.首先创建MFC 对话框的项目,在对话框中添加按钮,输出框这些
右键点击对话框,选择

Insert ActiveX Control

选择其中的

MFC串口通信 GPS定位实现 VC MFC
然后点击ok结束
MFC串口通信 GPS定位实现 VC MFC
然后给控件添加变量,可以参考下面的链接
用vc给控件添加变量

  1. 给电话形式的控件添加变量,变量名为m_mscom,之后项目中会出现对应.h和.cpp文件
  2. 加Eidit Control控件用于接受消息,绑定变量m_EditReveive
  3. 添加串口控件事件处理处理程序(点击电话,选择event,点击Oncomm,完成)
  4. 给按钮添加一个点击事件(在event中添加)OnBnClickedButtonOpen()

代码

  1. 在主cpp中找到点击按钮的事件,添加打开串口函数
void CMyDlg::OnDoubleclickedButton1() 
{
	// TODO: Add your control notification handler code here
	//初始化
	if (!m_mscom.get_PortOpen())     //初始化串口
    {
        m_mscom.put_CommPort(4); //选择串口
        m_mscom.put_InputMode(1);     //设置输入方式为二进制方式
        m_mscom.put_Settings(_T("9600"));   //波特率为(波特率组A合框)无校验,8数据位,1个停止位
        m_mscom.put_InputLen(1024);   //设置当前接收区数据长度为1024
        m_mscom.put_RThreshold(1);    //缓冲区一个字符引发事件
        m_mscom.put_RTSEnable(1);     //设置RT允许
        m_mscom.put_PortOpen(true);   //打开串口
    }
}

在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
    //



  1. 添加自动接收代码(项目中通信协议是测试结果自动上传),并直接显示在接收控件中,代码如下:
void CMyDlg::OnOnCommMscomm1() 
{
	// TODO: Add your control notification handler code here
	//判断是否有数据接受
    if (m_mscom.get_CommEvent() == 2)
    {

        char str[1024] = { 0 };            
        long k;
        VARIANT InputData = m_mscom.get_Input(); //读缓冲区
        COleSafeArray fs;
        fs = InputData; //VARIANT型变量转换为COleSafeArray型变量
        for (k = 0; k<fs.GetOneDimSize(); k++)
			fs.GetElement(&k, str + k);	//转换为BYTE型数组
 
		m_EditReveive += str;      //	接收到编辑框里面
		//SetTimer(1,10,NULL);		//延时10ms
		UpdateData(false); //更新到控件
	}
}

三. 测试

上一篇:v-model 双向绑定原理 及其在 Vue2 和 Vue3 中的区别


下一篇:Inno Setup软件 打包多个安装包程序