当为 WinHTTPRequest 指定事件处理程序前缀时,WScript.CreateObject 使 Windows 脚本宿主崩溃 [英] WScript.CreateObject crashes Windows Scripting Host when event handler prefix is specified for WinHTTPRequest

查看:61
本文介绍了当为 WinHTTPRequest 指定事件处理程序前缀时,WScript.CreateObject 使 Windows 脚本宿主崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 MSDN 文档 WinHTTPRequest 有四个事件处理程序,它们应该可以通过指定事件处理程序前缀来访问.不幸的是,这样做会导致 Windows Scripting Host 崩溃.

以下代码使 Windows Scripting Host 崩溃:

Set oHTTP = WScript.CreateObject( "WinHttp.WinHttpRequest.5.1", "oHTTP_" )

此代码工作正常:

Set oHTTP = WScript.CreateObject("WinHttp.WinHttpRequest.5.1")

对原因有什么想法吗?

解决方案

它无论如何都不是规范的一部分.一厢情愿的编程很少奏效.

<块引用>

创建并返回对自动化对象的引用.

 CreateObject(servername.typename [, location])

<块引用>

参数

服务器名称

必填.提供对象的应用程序的名称.

类型名称

必填.要创建的对象的类型或类.

位置

可选.要在其中创建对象的网络服务器的名称.

如果你想自己编一个如意的规格,看看能不能把你自己的参数加进去.

来自 GetRef 的帮助

<块引用>

返回对可以绑定到事件的过程的引用.

Set object.eventname = GetRef(procname)

<块引用>

参数

对象

必填.与事件关联的对象的名称.

活动

必填.函数绑定的事件名称.

程序名

必填.包含与事件关联的 Sub 或 Function 过程名称的字符串.

According to the MSDN documentation WinHTTPRequest has four event handlers which should be accessible by specifying an event handler prefix. Unfortunately, doing so causes Windows Scripting Host to crash.

The following code crashes Windows Scripting Host:

Set oHTTP = WScript.CreateObject( "WinHttp.WinHttpRequest.5.1", "oHTTP_" )

This code works just fine:

Set oHTTP = WScript.CreateObject( "WinHttp.WinHttpRequest.5.1" )

Any thoughts as to why?

解决方案

It's not part of the specification in any way. Wishful programming rarely works.

Creates and returns a reference to an Automation object.

 CreateObject(servername.typename [, location])

Arguments

servername

Required. The name of the application providing the object.

typename

Required. The type or class of the object to create.

location

Optional. The name of the network server where the object is to be created.

If you want to make up your own wishful specifications, see if you can add your own parameters to this one.

From Help for GetRef

Returns a reference to a procedure that can be bound to an event.

Set object.eventname = GetRef(procname)

Arguments

object

Required. Name of the object with which event is associated.

event

Required. Name of the event to which the function is to be bound.

procname

Required. String containing the name of the Sub or Function procedure being associated with the event.

这篇关于当为 WinHTTPRequest 指定事件处理程序前缀时,WScript.CreateObject 使 Windows 脚本宿主崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆