1

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?

  • The first example works fine for me on Windows 7 x64. What exactly do you mean by "crashing"? Are there any errors in the Event Viewer? How are you running the script? – Helen Dec 12 '14 at 12:12
  • I'm seeing this, as well, on Windows 10 x64. It generates a C0000005 GPF. – jveazey Aug 19 '16 at 23:07
  • I found another reference to this happening in another language on Windows XP. So, it sounds like this is a problem with WinHttp events. https://autohotkey.com/board/topic/72839-comobjconnect-crashes-script-on-events/ – jveazey Aug 19 '16 at 23:19

1 Answers1

-3

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.

Community
  • 1
  • 1
  • 2
    There is a difference between CreateObject and WScript.CreateObject. Please note that I specified WScript.CreateObject. You can read about the differences here: http://blogs.msdn.com/b/ericlippert/archive/2004/06/01/145686.aspx – Chris M. Wilson Dec 10 '14 at 18:07