Windows Vista Forums

Consuming a .NET event in VBScript
  1. #1


    Volker Hetzer Guest

    Consuming a .NET event in VBScript

    Hi!
    I'm pretty new to .NET and I am trying to have a VBScript consume an event created in a .NET component.
    I started out with http://msdn.microsoft.com/en-us/library/dd8bf0x3.aspx.
    I registered the assembly for COM interop and made it COM visible (checkboxes in the Visual Studio 2--8 project properties dialog).

    This is the .NET Code:
    using System.Runtime.InteropServices;
    namespace PureEvents
    {
    public delegate void ClickDelegate(int x, int y);
    public delegate void ResizeDelegate();

    // Step 1: Defines an event sink interface (ButtonEvents) to be
    // implemented by the COM sink.
    [GuidAttribute("1A585C4D-3371-48dc-AF8A-AFFECC1B0967")]
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
    public interface ButtonEvents
    {
    void Click(int x, int y);
    void Resize();
    }
    // Step 2: Connects the event sink interface to a class
    // by passing the namespace and event sink interface
    // ("EventSource.ButtonEvents, EventSrc").
    [ComSourceInterfaces(typeof(ButtonEvents))]
    public class PureEvents
    {
    public event ClickDelegate Click;
    public event ResizeDelegate Resize;
    public string getValue()
    {
    return "Normal method call";
    }
    public PureEvents()
    {
    }
    public void CauseClickEvent(int x, int y)
    {
    Click(x, y);
    }
    public void CauseResizeEvent()
    {
    Resize();
    }
    }
    }



    The VBScript code looks like this:
    sub X_Resize
    msgBox "Here"
    end sub
    set BFI=wscript.createobject("PureEvents.PureEvents","X_")
    msgBox BFI.GetValue()
    BFI.CauseResizeEvent
    msgBox "There"

    The getValue()-Method gets called properly, so the component itself works.
    However, when I call CauseResizeEvent, I get an 80004001 error (method or process not implemented".

    Am I missing anything obvious here?
    The script does not run in IIS or internet explorer, it just gets double clicked and then runs in wscript.exe.

    I appreciate any help.

    Lots of Greetings!
    Volker

    --
    For email replies, please substitute the obvious.

      My System SpecsSystem Spec

  2. #2


    mayayana Guest

    Re: Consuming a .NET event in VBScript

    You should ask in a .Net group about that
    part. You'll need to end up with a standard
    COM dispatch interface for VBS to see it.

    From the VBS end, you want to "consume
    events" from your "component solution"?
    (Why do they talk so silly in .Net?
    You have the right setup for creating the object,
    but you also need to have an event sub and
    you also need to keep the script alive until
    the event happens. So either you're missing
    two critical things or you haven't posted
    all of the code.


    > I'm pretty new to .NET and I am trying to have a VBScript consume an event
    created in a .NET component.

    > I started out with http://msdn.microsoft.com/en-us/library/dd8bf0x3.aspx.
    > I registered the assembly for COM interop and made it COM visible
    (checkboxes in the Visual Studio 2--8 project properties dialog).

    >
    > This is the .NET Code:
    > using System.Runtime.InteropServices;
    > namespace PureEvents
    > {
    > public delegate void ClickDelegate(int x, int y);
    > public delegate void ResizeDelegate();
    >
    > // Step 1: Defines an event sink interface (ButtonEvents) to be
    > // implemented by the COM sink.
    > [GuidAttribute("1A585C4D-3371-48dc-AF8A-AFFECC1B0967")]
    > [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
    > public interface ButtonEvents
    > {
    > void Click(int x, int y);
    > void Resize();
    > }
    > // Step 2: Connects the event sink interface to a class
    > // by passing the namespace and event sink interface
    > // ("EventSource.ButtonEvents, EventSrc").
    > [ComSourceInterfaces(typeof(ButtonEvents))]
    > public class PureEvents
    > {
    > public event ClickDelegate Click;
    > public event ResizeDelegate Resize;
    > public string getValue()
    > {
    > return "Normal method call";
    > }
    > public PureEvents()
    > {
    > }
    > public void CauseClickEvent(int x, int y)
    > {
    > Click(x, y);
    > }
    > public void CauseResizeEvent()
    > {
    > Resize();
    > }
    > }
    > }
    >
    > The VBScript code looks like this:
    > sub X_Resize
    > msgBox "Here"
    > end sub
    > set BFI=wscript.createobject("PureEvents.PureEvents","X_")
    > msgBox BFI.GetValue()
    > BFI.CauseResizeEvent
    > msgBox "There"
    >
    > The getValue()-Method gets called properly, so the component itself works.
    > However, when I call CauseResizeEvent, I get an 80004001 error (method or
    process not implemented".

    >
    > Am I missing anything obvious here?
    > The script does not run in IIS or internet explorer, it just gets double
    clicked and then runs in wscript.exe.

    >
    > I appreciate any help.
    >
    > Lots of Greetings!
    > Volker
    >
    > --
    > For email replies, please substitute the obvious.


      My System SpecsSystem Spec

  3. #3


    Volker Hetzer Guest

    Re: Consuming a .NET event in VBScript

    mayayana schrieb:

    > You should ask in a .Net group about that
    > part.
    Added crosspost.

    > You'll need to end up with a standard
    > COM dispatch interface for VBS to see it.
    I thought that VStudio does it correctly when
    applying the settings in the project properties.
    I have now set the ClassInterface set to AutoDispatch
    for the whole assembly but there's no difference.


    >
    > From the VBS end, you want to "consume
    > events" from your "component solution"?
    Exactly.
    ..NET creates the event and VBScript is
    supposed to process them.

    > You have the right setup for creating the object,
    > but you also need to have an event sub and
    > you also need to keep the script alive until
    > the event happens. So either you're missing
    > two critical things or you haven't posted
    > all of the code.
    This is all of the code there is.
    How do I define an event sub?
    I thought, defining a sub like X_Resize does it.
    Is there anything more to do?
    Should the sub accept a certain set of parameters?

    How do I keep a script alive?
    The error happens before the messagebox "There" appears.
    Adding a wscript.sleep(15) right after the CauseResizeEvent
    doesn't make a difference.

    It's probably some stupid beginners mistake, but
    somehow I'm not getting it right.

    Lots of Greetings!
    Volker



    >
    >

    >> I'm pretty new to .NET and I am trying to have a VBScript consume an event
    > created in a .NET component.

    >> I started out with http://msdn.microsoft.com/en-us/library/dd8bf0x3.aspx.
    >> I registered the assembly for COM interop and made it COM visible
    > (checkboxes in the Visual Studio 2--8 project properties dialog).

    >> This is the .NET Code:
    >> using System.Runtime.InteropServices;
    >> namespace PureEvents
    >> {
    >> public delegate void ClickDelegate(int x, int y);
    >> public delegate void ResizeDelegate();
    >>
    >> // Step 1: Defines an event sink interface (ButtonEvents) to be
    >> // implemented by the COM sink.
    >> [GuidAttribute("1A585C4D-3371-48dc-AF8A-AFFECC1B0967")]
    >> [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
    >> public interface ButtonEvents
    >> {
    >> void Click(int x, int y);
    >> void Resize();
    >> }
    >> // Step 2: Connects the event sink interface to a class
    >> // by passing the namespace and event sink interface
    >> // ("EventSource.ButtonEvents, EventSrc").
    >> [ComSourceInterfaces(typeof(ButtonEvents))]
    >> public class PureEvents
    >> {
    >> public event ClickDelegate Click;
    >> public event ResizeDelegate Resize;
    >> public string getValue()
    >> {
    >> return "Normal method call";
    >> }
    >> public PureEvents()
    >> {
    >> }
    >> public void CauseClickEvent(int x, int y)
    >> {
    >> Click(x, y);
    >> }
    >> public void CauseResizeEvent()
    >> {
    >> Resize();
    >> }
    >> }
    >> }
    >>
    >> The VBScript code looks like this:
    >> sub X_Resize
    >> msgBox "Here"
    >> end sub
    >> set BFI=wscript.createobject("PureEvents.PureEvents","X_")
    >> msgBox BFI.GetValue()
    >> BFI.CauseResizeEvent
    >> msgBox "There"
    >>
    >> The getValue()-Method gets called properly, so the component itself works.
    >> However, when I call CauseResizeEvent, I get an 80004001 error (method or
    > process not implemented".

    >> Am I missing anything obvious here?
    >> The script does not run in IIS or internet explorer, it just gets double
    > clicked and then runs in wscript.exe.

    >> I appreciate any help.
    >>
    >> Lots of Greetings!
    >> Volker
    >>
    >> --
    >> For email replies, please substitute the obvious.
    >
    >

    --
    For email replies, please substitute the obvious.

      My System SpecsSystem Spec

  4. #4


    Volker Hetzer Guest

    Re: Consuming a .NET event in VBScript

    Volker Hetzer schrieb:
    Found the problem.
    The ButtonEvent-Interface needed DispIds.
    They were not in the example given by microsoft either.

    Lots of Greetings!
    Volker


    > mayayana schrieb:

    >> You should ask in a .Net group about that
    >> part.
    > Added crosspost.
    >

    >> You'll need to end up with a standard
    >> COM dispatch interface for VBS to see it.
    > I thought that VStudio does it correctly when
    > applying the settings in the project properties.
    > I have now set the ClassInterface set to AutoDispatch
    > for the whole assembly but there's no difference.
    >
    >

    >>
    >> From the VBS end, you want to "consume
    >> events" from your "component solution"?
    > Exactly.
    > .NET creates the event and VBScript is
    > supposed to process them.
    >

    >> You have the right setup for creating the object,
    >> but you also need to have an event sub and
    >> you also need to keep the script alive until
    >> the event happens. So either you're missing
    >> two critical things or you haven't posted
    >> all of the code.
    > This is all of the code there is.
    > How do I define an event sub?
    > I thought, defining a sub like X_Resize does it.
    > Is there anything more to do?
    > Should the sub accept a certain set of parameters?
    >
    > How do I keep a script alive?
    > The error happens before the messagebox "There" appears.
    > Adding a wscript.sleep(15) right after the CauseResizeEvent
    > doesn't make a difference.
    >
    > It's probably some stupid beginners mistake, but
    > somehow I'm not getting it right.
    >
    > Lots of Greetings!
    > Volker
    >
    >
    >

    >>
    >>

    >>> I'm pretty new to .NET and I am trying to have a VBScript consume an
    >>> event
    >> created in a .NET component.

    >>> I started out with
    >>> http://msdn.microsoft.com/en-us/library/dd8bf0x3.aspx.
    >>> I registered the assembly for COM interop and made it COM visible
    >> (checkboxes in the Visual Studio 2--8 project properties dialog).

    >>> This is the .NET Code:
    >>> using System.Runtime.InteropServices;
    >>> namespace PureEvents
    >>> {
    >>> public delegate void ClickDelegate(int x, int y);
    >>> public delegate void ResizeDelegate();
    >>>
    >>> // Step 1: Defines an event sink interface (ButtonEvents) to be
    >>> // implemented by the COM sink.
    >>> [GuidAttribute("1A585C4D-3371-48dc-AF8A-AFFECC1B0967")]
    >>> [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
    >>> public interface ButtonEvents
    >>> {
    >>> void Click(int x, int y);
    >>> void Resize();
    >>> }
    >>> // Step 2: Connects the event sink interface to a class
    >>> // by passing the namespace and event sink interface
    >>> // ("EventSource.ButtonEvents, EventSrc").
    >>> [ComSourceInterfaces(typeof(ButtonEvents))]
    >>> public class PureEvents
    >>> {
    >>> public event ClickDelegate Click;
    >>> public event ResizeDelegate Resize;
    >>> public string getValue()
    >>> {
    >>> return "Normal method call";
    >>> }
    >>> public PureEvents()
    >>> {
    >>> }
    >>> public void CauseClickEvent(int x, int y)
    >>> {
    >>> Click(x, y);
    >>> }
    >>> public void CauseResizeEvent()
    >>> {
    >>> Resize();
    >>> }
    >>> }
    >>> }
    >>>
    >>> The VBScript code looks like this:
    >>> sub X_Resize
    >>> msgBox "Here"
    >>> end sub
    >>> set BFI=wscript.createobject("PureEvents.PureEvents","X_")
    >>> msgBox BFI.GetValue()
    >>> BFI.CauseResizeEvent
    >>> msgBox "There"
    >>>
    >>> The getValue()-Method gets called properly, so the component itself
    >>> works.
    >>> However, when I call CauseResizeEvent, I get an 80004001 error
    >>> (method or
    >> process not implemented".

    >>> Am I missing anything obvious here?
    >>> The script does not run in IIS or internet explorer, it just gets double
    >> clicked and then runs in wscript.exe.

    >>> I appreciate any help.
    >>>
    >>> Lots of Greetings!
    >>> Volker
    >>>
    >>> --
    >>> For email replies, please substitute the obvious.
    >>
    >>
    >
    >

    --
    For email replies, please substitute the obvious.

      My System SpecsSystem Spec

Consuming a .NET event in VBScript problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
are VBscript on Windows server 2003 and VBscript on WS2008 compatible? Francois Lafont VB Script 9 26 Apr 2010
Can a vbscript identify the program/process that called a vbscript MarceepooNu VB Script 15 16 Mar 2010
Audiodg.exe consuming up to 40% CPU usage Tiger Lian Vista General 2 26 Jun 2008
Re: SP 1 Time Consuming Bill Vista General 3 22 Mar 2008
Re: SP 1 Time Consuming philo Vista General 0 22 Mar 2008