Why event doesnt fire in .NET object from VBS?

S

senglory

Code
-------------------

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

namespace DEMONS
{

[ComVisible(false)]
public delegate void TestEventHandler();

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ControlEvents
{
//[DispIdAttribute(0x60020000)]
void OnBeforeStartTest();
}

[
ClassInterface(ClassInterfaceType.AutoDispatch),
ComSourceInterfaces(typeof(ControlEvents))
]
public class Demo
{
public event TestEventHandler OnBeforeStartTest;
public void TEST()
{
Console.WriteLine("TEST()");

if (OnBeforeStartTest != null)
OnBeforeStartTest();
}
}
}

-------------------



VBS:



sub OnTest2()
msgbox "VBSCRIPT OnTest"
end sub

sub obj_OnBeforeStartMigration()
msgbox "VBSCRIPT OnTest"
end sub

set obj = createobject("DEMONS.Demo")
set obj.OnBeforeStartTest = GetRef("OnTest2")
obj.TEST

--------------------------------

obj.TEST works fine (if to comment upper string). But when I leave i
uncommented i receive
Microsoft VBScript runtime error: Object doesn't support this propert
or method: 'obj.OnBeforeStartTest'

Whats wrong to my code - VBS and .NET

+----------------------------------------------------------------
| Attachment filename: eventsforcom.zip
|Download attachment: http://www.codecomments.com/attachment.php?postid=1081328
+----------------------------------------------------------------

-
senglor
 
J

Jeffrey Palermo [MCP]

Senglory,
VBScript doesn't support the range of constructs that .Net code does.
You are trying to use VBScript code to respond to an event in your .Net
object. Your problems are not stemmed from bugs in your code. You are
trying to use VBScript for something it was not intended.

Best regards,
Jeffrey Palermo

senglory said:
Code:
--------------------

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

namespace DEMONS
{

[ComVisible(false)]
public delegate void TestEventHandler();

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ControlEvents
{
//[DispIdAttribute(0x60020000)]
void OnBeforeStartTest();
}

[
ClassInterface(ClassInterfaceType.AutoDispatch),
ComSourceInterfaces(typeof(ControlEvents))
]
public class Demo
{
public event TestEventHandler OnBeforeStartTest;
public void TEST()
{
Console.WriteLine("TEST()");

if (OnBeforeStartTest != null)
OnBeforeStartTest();
}
}
}

--------------------



VBS:



sub OnTest2()
msgbox "VBSCRIPT OnTest"
end sub

sub obj_OnBeforeStartMigration()
msgbox "VBSCRIPT OnTest"
end sub

set obj = createobject("DEMONS.Demo")
set obj.OnBeforeStartTest = GetRef("OnTest2")
obj.TEST

--------------------------------

obj.TEST works fine (if to comment upper string). But when I leave it
uncommented i receive
Microsoft VBScript runtime error: Object doesn't support this property
or method: 'obj.OnBeforeStartTest'

Whats wrong to my code - VBS and .NET?


+----------------------------------------------------------------+
| Attachment filename: eventsforcom.zip |
|Download attachment:
http://www.codecomments.com/attachment.php?postid=1081328 |
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top