• 在VC8里调用VBScript.dll的RegularExpression


    1、选择添加类--TypeLib中的MFC类。
    2、选择从注册表中添加,位置为C:\windows\system32\vbscript.dll
    3、生成类文件CMatch.h CMatch2.h CMatchCollection.h CMatchCollection2.h CRegExp.h CRegExp2.h
    CSubMatches.h
    4、将#import "c:\\windows\\system32\\vbscript.dll\\3" no_namespace
    改为#import "progid:VBScript.RegExp" no_namespace,不然会提示找不到文件

    加声明
    const GUID LIBID_VBScript_RegExp_55 = {0x3F4DACA7, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID IID_IRegExp = {0x3F4DACA0, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID IID_IMatch = {0x3F4DACA1, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID IID_IMatchCollection = {0x3F4DACA2, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID IID_IRegExp2 = {0x3F4DACB0, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID IID_IMatch2 = {0x3F4DACB1, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID IID_IMatchCollection2 = {0x3F4DACB2, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID IID_ISubMatches = {0x3F4DACB3, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID CLSID_RegExp = {0x3F4DACA4, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID CLSID_Match = {0x3F4DACA5, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID CLSID_MatchCollection = {0x3F4DACA6, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };
    const GUID CLSID_SubMatches = {0x3F4DACC0, 0x160D, 0x11D2,{ 0xA8, 0xE9, 0x00,0x10, 0x4B, 0x36,0x5C, 0x9F} };

    5、调用方法如下:
    void Test()
    {
    CoInitialize(NULL);

    CLSID clsid;
    HRESULT hr = ::CLSIDFromProgID(_T("VBScript.RegExp"), &clsid);
    if ( FAILED( hr ))
    {
      CoUninitialize();
      return;
    }

    IClassFactory* pCF;
    hr = CoGetClassObject(clsid, CLSCTX_INPROC, NULL, IID_IClassFactory, (void**) &pCF);
    if ( FAILED( hr ))
    {
      CoUninitialize();
      return;
    }

    IRegExp2* pObj;
    hr = pCF->CreateInstance(NULL, IID_IRegExp2, (void**) &pObj);
    pCF->Release();
    if ( FAILED( hr ))
    {
      CoUninitialize();
      return;
    }

    pObj->Pattern = _T("^\\d{4}-\\d{4}\\u8881$");
    VARIANT_BOOL pMatch = 0;

    pMatch = pObj->Test(_T("3233-3456袁"));

    if (pMatch)
      cout << "^\\d{4}-\\d{4}\\u8881$ match 3233-3456袁 is true" << endl;
    else
      cout << "^\\d{4}-\\d{4}\\u8881$ match 3233-3456袁 is false" << endl;

    pMatch = pObj->Test(_T("3233s-3456"));

    if (pMatch)
      cout << "^\\d{4}-\\d{4}$ match 3233s-3456 is true" << endl;
    else
      cout << "^\\d{4}-\\d{4}$ match 3233s-3456 is false" << endl;

    CoUninitialize();
    }

  • 相关阅读:
    2018-06-20 利用随机数组进行36选7(不重复)
    2018-06-20 js字符串函数
    2018-06-19 js DOM对象
    2018-06-19 Javascript 基础2
    《我们应当怎样做需求分析》阅读笔记
    《软件需求模式》阅读笔记03
    《软件需求模式》阅读笔记02
    《软件需求模式》阅读笔记01
    java总结:double取两位小数的多种方法
    梦断代码阅读笔记03
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1332917.html
Copyright © 2020-2023  润新知