在 vc 中 引用 vbscript.dll 做正则表达式 IMatchCollection 类的问题?

天限天空 2003-03-01 03:51:32
再上帖中
http://expert.csdn.net/Expert/topic/1453/1453603.xml?temp=.921322

得到masterz 和 dispatchwengqun(≡≡★★郁闷★★≡≡) 2位大虾的帮助
顺利调试通过了 IRegExp 类的应用,但当我用 IMatchCollection类时,问题又出来了,我采用了多中写法,都不能通过。代码如下:


...全文
175 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaohyy 2003-03-24
  • 打赏
  • 举报
回复
修改向导生成的函数有什么需要学习的。。。直接改了就是。。。
masterz 2003-03-04
  • 打赏
  • 举报
回复
InvokeHelper(0x0, // use 0 here, not 0x00002711
harry202 2003-03-04
  • 打赏
  • 举报
回复
mark
天限天空 2003-03-04
  • 打赏
  • 举报
回复
还是一样的问题!
:(
天限天空 2003-03-02
  • 打赏
  • 举报
回复
copy masterz(MS MVP) 的代码,但运行到
int count = matches.GetCount();//count=2 判断 matches 应该是正确的
这部的时间就提示 访问共享错误.

InvokeHelper(0x00002711,//this ID is found by OLEView
?

修改向导生成的代码,学习的东西太多了,惭愧!
masterz 2003-03-02
  • 打赏
  • 举报
回复
1. modify wizard generated function
LPDISPATCH IMatchCollection::GetItem(const VARIANT& Index)
{
LPDISPATCH result;
static BYTE parms[] =
VTS_VARIANT;
InvokeHelper(0x0,//this ID is found by OLEView
DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, parms,
&Index);
return result;
}

2. correct your codes as the following
IRegExp * regExpPtr;//前面不用指针要出错
regExpPtr = new IRegExp();
regExpPtr->CreateDispatch("VBScript.RegExp");
regExpPtr->SetGlobal(TRUE);
regExpPtr->SetPattern(_T("(\\d+\\.?\\d*|\\.\\d+)"));
LPCTSTR testStr = _T("This 1dd2dd");
LPDISPATCH pdispcol = regExpPtr->Execute(testStr);//用指针要出错
IMatchCollection matches;
if(pdispcol)
matches.AttachDispatch(pdispcol);
int count = matches.GetCount();//count=0 判断 matches 应该是正确的
for(long i=0; i<count; i++)
{
long index=i;
IDispatch* pdisp =matches.GetItem(COleVariant((short)(index)));
if(pdisp)
{
IMatch match;
match.AttachDispatch(pdisp);
AfxMessageBox(match.GetValue());
}
}
天限天空 2003-03-02
  • 打赏
  • 举报
回复
再次谢谢masterz(MS MVP)的指点,
但再次请教 用直接 生成 类的方法,为什么不行呢?
masterz 2003-03-02
  • 打赏
  • 举报
回复
#include "stdafx.h"
//使用VC++以资源的方式打开VBScript.dll,在其中选择TypeLib,将第2个TypeLib输出为regexp.tlb, put it in your project's main directory


#import "regexp.tlb" no_namespace

int main(int argc, char* argv[])
{
CoInitialize(NULL);
{
IRegExpPtr regExpPtr(__uuidof(RegExp));
regExpPtr->PutGlobal(VARIANT_TRUE);
regExpPtr->PutPattern("(\\d+\\.?\\d*|\\.\\d+)");
LPCTSTR testStr = "This 1dd2d";
IMatchCollectionPtr matches = regExpPtr->Execute(testStr);//用指针要出错

int count = matches->GetCount();//count=0 判断 matches 应该是正确的
for(int i=0; i<count; i++)
{
IMatchPtr match=matches->GetItem((long)i);
if(match)
{
printf("%s\n",(LPCTSTR)match->GetValue());
}
}
}

CoUninitialize();
printf("Test of using regular expression in VC++!\n");
return 0;
}
天限天空 2003-03-01
  • 打赏
  • 举报
回复
修改
int count = matches.GetCount();//count=2 判断 matches 应该是正确的
天限天空 2003-03-01
  • 打赏
  • 举报
回复
修改代码后 提示早不到成员

IRegExp * regExpPtr;//前面不用指针要出错
regExpPtr = new IRegExp();
regExpPtr->CreateDispatch("VBScript.RegExp");
regExpPtr->SetGlobal(true);
regExpPtr->SetPattern("(\d+\.?\d*|\.\d+)");
CString testStr = "This 1dd2d";
//if(regExpPtr->Test(testStr)) AfxMessageBox("ddd");
IMatchCollection matches;
//matchesPtr = new IMatchCollection();
matches = regExpPtr->Execute(testStr);//用指针要出错

IMatch match;
int count = matches.GetCount();//count=0 判断 matches 应该是正确的
for(int i=0; i<count; i++){
AfxMessageBox(((IMatch)matches.GetItem(1)).GetValue()); //????
}
天限天空 2003-03-01
  • 打赏
  • 举报
回复
IRegExp regExp;
regExp.CreateDispatch("3F4DACA4-160D-11D2-A8E9-00104B365C9F");
//regExp.CreateDispatch("VBScript.MatchCollection");
regExp.SetGlobal(true);
regExp.SetPattern("(\d+\.?\d*|\.\d+)"); //选出其中的数字
CString testStr = "This 1dd3";
if(regExp.Test(testStr)) AfxMessageBox("ddd");

IMatchCollection** matches = ((IMatchCollection*)regExp.Execute(testStr));
IMatchCollection* matches = ((IMatchCollection**)regExp.Execute(testStr));
IMatchCollection matches = ((IMatchCollection)regExp.Execute(testStr));

matches 都是 0xcccccc
请再指教

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧