Categories: Windows

How to use VB regex in VC6

1,Open “OLE/COM object viewer” from Tool menu of VC6.
2,Find “Microsoft VBScript Regular Expressions 5.5” under “Type Libraries”.

3, Double click the node to open with “ITypeLib Viewer”.
4, Choose “Save As” and save as “vbscript.IDL”.

5, Run “midl vbscript.idl” in Command Propmt. midl.exe is typically located under “C:\Program Files\Microsoft Visual Studio\VC98\Bin”.

This creates “vbscript.tlb”.
6, Move this file into your VC6’s project directory.

7, By coding #import “vbscript.tlb” in your source file, VB regex will be available.

#include "stdafx.h"

#import "vbscript.tlb" no_namespace named_guids

_bstr_t vbregReplace(LPCTSTR source,
      LPCTSTR replace, 
      LPCTSTR regex,
      BOOL bGlobal,
      BOOL bCaseInsensitive)
{
 IRegExpPtr pReg;
 pReg.CreateInstance(CLSID_RegExp);

 _bstr_t bstrSource(source);
 _bstr_t bstrReplace(replace);
 _bstr_t bstrRegex(regex);

 pReg->put_Global(bGlobal?VARIANT_TRUE:VARIANT_FALSE); 
 pReg->put_IgnoreCase(bCaseInsensitive?VARIANT_TRUE:VARIANT_FALSE); 
 pReg->put_Pattern(bstrRegex); 

 _bstr_t bstrRet = pReg->Replace(bstrSource, bstrReplace);

 return bstrRet;
}

int main(int argc, char* argv[])
{
 CoInitialize(NULL);
 _bstr_t t = vbregReplace(
  "abcdefg",
  "x",
  "[aceg]",
  TRUE,
  TRUE);

 puts(t);
 CoUninitialize();
 return 0;
}
admin

Share
Published by
admin
Tags: RegExVBVC6

Recent Posts

Obtain global IP in bash

In current Internet environment, every PC is assigned a private IP. If global IP is…

4 years ago

Create log file in the directory of the script in Python

__file__ is the script file itself. From python3.9 above, it is an absolute path, otherwise…

4 years ago

RichTextBox’s font changes automatically in C#

You need to clear these two flags IMF_DUALFONT and IMF_AUTOFONT to keep font unchanged.

4 years ago

Test post to check image URL

This is an image inserted by wordpress 'Add Media'

4 years ago

msbuild says ‘target does not exist’

I don't know what is going wrong but... How to fix it Open the solution…

4 years ago

Creating a break point that hits on calling win32 api

Create a break point that hits when CreateProcess was called Enter a Function Breakpoint Enter…

5 years ago