Hi,
I need to write a c# dll which I can call from a VBScript.
It works, except that I also need to catch events from the dll.
Here is my C# code
[tt]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IFormCloseEvents
{
void OnFormClose();
}
//declaring the event handler delegate
public delegate void SimpleEventHandler();
[ProgId("DHI.WFScriptWindow"),
ComSourceInterfaces("IFormCloseEvents"),
ClassInterface(ClassInterfaceType.AutoDual),
ComVisible(true)]
public class WFScriptWin
{
//declaring the event
public event SimpleEventHandler OnFormClose;
frmMain mFrm;
public WFScriptWin()
{
//init
mFrm = new frmMain();
mFrm.FormClosing += new FormClosingEventHandler(frmMain_FormClosing);
}
//expose the main form's closing event through COM
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (null != OnFormClose) OnFormClose();
}
public void ShowForm(string winTitle)
{
if (winTitle == "") winTitle = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
mFrm.Show();
}
[/tt]
Here is my script code
[tt]
Set obj = WScript.CreateObject("DHI.WFScriptWindow","_hej")
obj.ShowForm "min titel"
for i=0 to 10
wscript.sleep 2000
next
sub hej_OnFormClose
msgBox "end"
end sub
[/tt]
The C# dll is, strongnamed, registered in the GAC and coverted to a type lib by regasm.
Any help will be greatly appreciated.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
I need to write a c# dll which I can call from a VBScript.
It works, except that I also need to catch events from the dll.
Here is my C# code
[tt]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IFormCloseEvents
{
void OnFormClose();
}
//declaring the event handler delegate
public delegate void SimpleEventHandler();
[ProgId("DHI.WFScriptWindow"),
ComSourceInterfaces("IFormCloseEvents"),
ClassInterface(ClassInterfaceType.AutoDual),
ComVisible(true)]
public class WFScriptWin
{
//declaring the event
public event SimpleEventHandler OnFormClose;
frmMain mFrm;
public WFScriptWin()
{
//init
mFrm = new frmMain();
mFrm.FormClosing += new FormClosingEventHandler(frmMain_FormClosing);
}
//expose the main form's closing event through COM
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (null != OnFormClose) OnFormClose();
}
public void ShowForm(string winTitle)
{
if (winTitle == "") winTitle = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
mFrm.Show();
}
[/tt]
Here is my script code
[tt]
Set obj = WScript.CreateObject("DHI.WFScriptWindow","_hej")
obj.ShowForm "min titel"
for i=0 to 10
wscript.sleep 2000
next
sub hej_OnFormClose
msgBox "end"
end sub
[/tt]
The C# dll is, strongnamed, registered in the GAC and coverted to a type lib by regasm.
Any help will be greatly appreciated.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'