A problem with ScriptControl

使用AddCode方法将一些代码(JScript)添加到ScriptControl的global模块中,然后使用如下两句话来得到代码中的过程记数。
IScriptProcedureCollectionPtr pIProcedures = m_pScript->GetProcedures();
long count = pIProcedures->GetCount();

当添加的代码中没有全局变量而只有函数的时候没有问题,JScript代码示例如下:
function calc(a, b){return a + b;}

而当添加的代码中包含全局变量的时候会在GetCount那一句抛出0x8002802c的异常,JScript代码示例如下:
var a = 10;
function calc(b){return a + b;}

如果是采用VBScript就可以将过程和变量混合定义在global模块中而不会影响取得过程基本信息。不知道微软为什么会搞成这样?

你可能感兴趣的:(VBScript)