Call the regularexpression of VBScript. dll in vc8

Source: Internet
Author: User

1. Select Add class-MFC class in typelib.
2. Select Add from the registry at c: \ windows \ system32 \ VBScript. dll.
3. Generate the class file cmatch. h cmatch2.h cmatchcollection. h cmatchcollection2.h cregexp. h cregexp2.h
Csubmatches. h
4. Set # import "C: \ WINDOWS \ system32 \ VBScript. dll \ 3" no_namespace
Change to # import "progid: VBScript. Regexp" no_namespace. Otherwise, the system will prompt that the file cannot be found.

Add statement
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. The call method is as follows:
Void test ()
{
Coinitialize (null );

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 yuan "));

If (pmatch)
Cout <"^ \ D {4}-\ D {4} \ u8881 $ match 3233-3456 yuan is true" <Endl;
Else
Cout <"^ \ D {4}-\ D {4} \ u8881 $ match 3233-3456 yuan is false" <Endl;

Pmatch = pobj-> test (_ T ("3233 S-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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.