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 ();
}