我正在尝试使用cscript
with执行脚本IActiveScriptParse
,ParseScriptText
但由于某种原因我收到错误:E_UNEXPECTED
.
这篇文章对我帮助很大。我getEngineGuid
在我的代码中使用它的功能。
下面的代码是我尝试过的。它打印:
-2147418113
-2147418113
意义activeScriptParse->ParseScriptText
归来E_UNEXPECTED
。那么我做错了什么?
#include <iostream>
#include <Windows.h>
#include <ObjBase.h>
#include <ActivScp.h>
using namespace std;
int main(int argc, char* argv[])
{
CoInitialize(NULL);
GUID guidBuffer;
// Find the script engine to use for files that end with a .js extension.
// This is implemented in the article I linked to.
getEngineGuid(".js", &guidBuffer);
IActiveScript *activeScript;
CoCreateInstance(guidBuffer, 0, CLSCTX_ALL,
IID_IActiveScript,
(void **)&activeScript);
IActiveScriptParse *activeScriptParse;
activeScript->QueryInterface(IID_IActiveScriptParse,
(void **)&activeScriptParse);
activeScriptParse->InitNew();
EXCEPINFO ei ={};
VARIANT result;
cout << E_UNEXPECTED << endl;
cout << activeScriptParse->ParseScriptText(OLESTR("(new Date()).getTime()"), NULL,
NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION,
&result, &ei) << endl;
activeScriptParse->Release();
return 0;
}
非常感谢!