ActiveX control in WSH without HTML? 
Author Message
 ActiveX control in WSH without HTML?

I need to display and receive responses from an ActiveX control, such
as a treeview, on a local machine (with or without IE) from a WSH
script, but I would really like to avoid using HTML with an HTA file.
Can this be done?  How?

TIA for any help,

Martin Wulfe



Sun, 29 May 2005 22:22:31 GMT  
 ActiveX control in WSH without HTML?
You can do it by making an ActiveX DLL in VB.
VB DLLs can include forms. As long as all properties
and methods take and return variants VBS can use it.

--
--

Quote:
> I need to display and receive responses from an ActiveX control, such
> as a treeview, on a local machine (with or without IE) from a WSH
> script, but I would really like to avoid using HTML with an HTA file.
> Can this be done?  How?

> TIA for any help,

> Martin Wulfe



Sun, 29 May 2005 23:10:44 GMT  
 ActiveX control in WSH without HTML?
mayayana -

Thanks for the tip, it works!!

The only problem I still have is exposing the events of the DLL.  I used
a "public event" in the general section of the form, and used a
"raiseevents" in the dblclick event for the treeview control.  I know it
sees the dblclick event because I inserted a msgbox in there, but the
wsf file does not seem to see the function with that name (I use
VBScript).

Any hints?

Thanks again,

Martin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 30 May 2005 08:52:20 GMT  
 ActiveX control in WSH without HTML?

Quote:

> mayayana -

> Thanks for the tip, it works!!

> The only problem I still have is exposing the events of the DLL.  I
> used a "public event" in the general section of the form, and used a
> "raiseevents" in the dblclick event for the treeview control.  I know
> it sees the dblclick event because I inserted a msgbox in there, but
> the wsf file does not seem to see the function with that name (I use
> VBScript).

> Any hints?

set myObj = WScript.CreateObject("myobject.progid","myObj_")

Note: In a WSF, you can also use an <object id="objectid" ...> element has a
events="yes" attribute that presumes the event handlers will be named using
the objectid_eventname convention.

...
...an appropriate loop around wscript.sleep nMilliseconds
...to allow for events to fire and be handled.  Some event
...*must* trigger an exit from the loop or your script will
...never end.
...

sub myObj_eventname(eventArgsIfPassed)
    ...
end sub

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Mon, 30 May 2005 09:40:15 GMT  
 ActiveX control in WSH without HTML?
Thanks, but I think I tried tha, will try againt.  Could the problem
be that the DLL MUST use a modal form?  If so, is there another way
around this?

On Wed, 11 Dec 2002 17:40:15 -0800, "Michael Harris \(MVP\)"

Quote:

>set myObj = WScript.CreateObject("myobject.progid","myObj_")



Mon, 30 May 2005 19:42:19 GMT  
 ActiveX control in WSH without HTML?
Every time I try to add a second parameter to the createobject funtion
I get this message: "The remote server machine does not exist or is
unavailable: 'createobject'"

On Wed, 11 Dec 2002 17:40:15 -0800, "Michael Harris \(MVP\)"

Quote:


>> mayayana -

>> Thanks for the tip, it works!!

>> The only problem I still have is exposing the events of the DLL.  I
>> used a "public event" in the general section of the form, and used a
>> "raiseevents" in the dblclick event for the treeview control.  I know
>> it sees the dblclick event because I inserted a msgbox in there, but
>> the wsf file does not seem to see the function with that name (I use
>> VBScript).

>> Any hints?

>set myObj = WScript.CreateObject("myobject.progid","myObj_")

>Note: In a WSF, you can also use an <object id="objectid" ...> element has a
>events="yes" attribute that presumes the event handlers will be named using
>the objectid_eventname convention.

>...
>...an appropriate loop around wscript.sleep nMilliseconds
>...to allow for events to fire and be handled.  Some event
>...*must* trigger an exit from the loop or your script will
>...never end.
>...

>sub myObj_eventname(eventArgsIfPassed)
>    ...
>end sub



Mon, 30 May 2005 22:01:35 GMT  
 ActiveX control in WSH without HTML?
Sorry to be so confusing about this.  I can run this with a second
parameter as suggested, but get a message "cannot connect object".
Does this mean the error is in the DLL?

On Wed, 11 Dec 2002 17:40:15 -0800, "Michael Harris \(MVP\)"

Quote:


>> mayayana -

>> Thanks for the tip, it works!!

>> The only problem I still have is exposing the events of the DLL.  I
>> used a "public event" in the general section of the form, and used a
>> "raiseevents" in the dblclick event for the treeview control.  I know
>> it sees the dblclick event because I inserted a msgbox in there, but
>> the wsf file does not seem to see the function with that name (I use
>> VBScript).

>> Any hints?

>set myObj = WScript.CreateObject("myobject.progid","myObj_")

>Note: In a WSF, you can also use an <object id="objectid" ...> element has a
>events="yes" attribute that presumes the event handlers will be named using
>the objectid_eventname convention.

>...
>...an appropriate loop around wscript.sleep nMilliseconds
>...to allow for events to fire and be handled.  Some event
>...*must* trigger an exit from the loop or your script will
>...never end.
>...

>sub myObj_eventname(eventArgsIfPassed)
>    ...
>end sub



Mon, 30 May 2005 22:06:04 GMT  
 ActiveX control in WSH without HTML?
  I'm not sure if this is answering the right question, but the script
doesn't know about the form. It only gets what you make available
through public declares in the main class.
You need to process the form events through the class.

--
--

Quote:
> mayayana -

> Thanks for the tip, it works!!

> The only problem I still have is exposing the events of the DLL.  I used
> a "public event" in the general section of the form, and used a
> "raiseevents" in the dblclick event for the treeview control.  I know it
> sees the dblclick event because I inserted a msgbox in there, but the
> wsf file does not seem to see the function with that name (I use
> VBScript).

> Any hints?

> Thanks again,

> Martin

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Mon, 30 May 2005 22:55:17 GMT  
 ActiveX control in WSH without HTML?
Could you show how you have the progid declared and the code where you error
out?

--
Please respond in the newsgroup so everyone may benefit.
 http://dev.remotenetworktechnology.com
 ----------
 Subscribe to Microsoft's Security Bulletins:
 http://www.microsoft.com/technet/security/bulletin/notify.asp


Quote:
> Sorry to be so confusing about this.  I can run this with a second
> parameter as suggested, but get a message "cannot connect object".
> Does this mean the error is in the DLL?

> On Wed, 11 Dec 2002 17:40:15 -0800, "Michael Harris \(MVP\)"


> >> mayayana -

> >> Thanks for the tip, it works!!

> >> The only problem I still have is exposing the events of the DLL.  I
> >> used a "public event" in the general section of the form, and used a
> >> "raiseevents" in the dblclick event for the treeview control.  I know
> >> it sees the dblclick event because I inserted a msgbox in there, but
> >> the wsf file does not seem to see the function with that name (I use
> >> VBScript).

> >> Any hints?

> >set myObj = WScript.CreateObject("myobject.progid","myObj_")

> >Note: In a WSF, you can also use an <object id="objectid" ...> element has a
> >events="yes" attribute that presumes the event handlers will be named using
> >the objectid_eventname convention.

> >...
> >...an appropriate loop around wscript.sleep nMilliseconds
> >...to allow for events to fire and be handled.  Some event
> >...*must* trigger an exit from the loop or your script will
> >...never end.
> >...

> >sub myObj_eventname(eventArgsIfPassed)
> >    ...
> >end sub



Tue, 31 May 2005 04:12:06 GMT  
 ActiveX control in WSH without HTML?

Quote:

> Sorry to be so confusing about this.  I can run this with a second
> parameter as suggested, but get a message "cannot connect object".
> Does this mean the error is in the DLL?

It means the component doesn't expose any public events...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Tue, 31 May 2005 04:23:10 GMT  
 ActiveX control in WSH without HTML?
I have been able to get this to run, but I still cannot get the event to
fire in the WSF file.  In the code below, the msgbox "Button Clicked"
never displays.  

My form file code looks like this:

Option Explicit

Private Sub Command1_Click()

    Dim xClass As New TestClass
    xClass.TestEvent

End Sub

In the class TestClass.cls:

Option Explicit

Public Event NewEvent()

Sub TestEvent()
    MsgBox "TestEvent"
    RaiseEvent NewEvent
End Sub

Sub ShowForm()
    Form1.Show vbModal
End Sub

and the WSF file:

<job>
<script language="VBScript">
option explicit

dim NewDLL

set newdll = wscript.createobject("Project1.TestClass", "Test_")

newdll.showform

Sub Test_NewEvent(x)
    msgbox "Button Clicked"
End Sub
</script>
</job>

I'm probably doing something really stupid here.  Your help is
appreciated!

Martin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 31 May 2005 05:12:42 GMT  
 ActiveX control in WSH without HTML?
See Michael's response - I forgot about that cause...
--
Please respond in the newsgroup so everyone may benefit.
 http://dev.remotenetworktechnology.com
 ----------
 Subscribe to Microsoft's Security Bulletins:
 http://www.microsoft.com/technet/security/bulletin/notify.asp


Quote:
> I have been able to get this to run, but I still cannot get the event to
> fire in the WSF file.  In the code below, the msgbox "Button Clicked"
> never displays.

> My form file code looks like this:

> Option Explicit

> Private Sub Command1_Click()

>     Dim xClass As New TestClass
>     xClass.TestEvent

> End Sub

> In the class TestClass.cls:

> Option Explicit

> Public Event NewEvent()

> Sub TestEvent()
>     MsgBox "TestEvent"
>     RaiseEvent NewEvent
> End Sub

> Sub ShowForm()
>     Form1.Show vbModal
> End Sub

> and the WSF file:

> <job>
> <script language="VBScript">
> option explicit

> dim NewDLL

> set newdll = wscript.createobject("Project1.TestClass", "Test_")

> newdll.showform

> Sub Test_NewEvent(x)
>     msgbox "Button Clicked"
> End Sub
> </script>
> </job>

> I'm probably doing something really stupid here.  Your help is
> appreciated!

> Martin

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Tue, 31 May 2005 05:21:02 GMT  
 ActiveX control in WSH without HTML?

Quote:

> Sorry to be so confusing about this.  I can run this with a second
> parameter as suggested, but get a message "cannot connect object".
> Does this mean the error is in the DLL?

It means the component doesn't expose any public events...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Tue, 31 May 2005 05:52:08 GMT  
 ActiveX control in WSH without HTML?

Quote:
> See Michael's response - I forgot about that cause...

or mayayana's...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Tue, 31 May 2005 05:52:49 GMT  
 ActiveX control in WSH without HTML?


Quote:

> > See Michael's response - I forgot about that cause...

> or mayayana's...

Yes, and it looks like mayayana cut to the heart of the issue... To show a modal
form, the next technique is to try using an ActiveX EXE, and run everything
through a class file. You can use implements in VB.NET as well to make a
COM-exposed DLL, but it isn't any simpler.

Here's an example of a VB executable I wrote specifically to be launched by
script, display a form, and send events back to the script which runs it.  The
first part is the CLS file, the second is the FRM.

Application.cls

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Application"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private WithEvents mfrmGui As frmGui
Attribute mfrmGui.VB_VarHelpID = -1
Private Script As New ScriptControl
Public Event onQuit()
Public Event onExecute(ByVal sCode As String)
'local variable(s) to hold property value(s)
Private mvarCodeBase As String 'local copy
Public Property Let CodeBase(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.CodeBase = 5
    mvarCodeBase = vData
End Property

Public Property Get CodeBase() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.CodeBase
    CodeBase = Script.CodeObject
End Property

Private Sub Class_Initialize()
  Set mfrmGui = New frmGui
  mfrmGui.Show
  Script.Language = "VBScript"
End Sub

Private Sub mfrmGui_onbtnExecuteClicked(sCode As String)
  Debug.Print "Code Execution fired!"
  Script.AddCode (sCode)
  RaiseEvent onExecute(sCode)
End Sub

Private Sub mfrmGui_onfrmUnloading()
  Debug.Print "onQuit Event raised!"
  RaiseEvent onQuit
End Sub

' 0.0.5 First Release
' 0.0.6 - added Codesense

====================================================
====================================================
====================================================
====================================================
====================================================
frmGui.frm

VERSION 5.00
Object = "{665BF2B8-F41F-4EF4-A8D0-303FBFFC475E}#2.0#0"; "cmcs21.ocx"
Begin VB.Form frmGui
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "WshConsole"
   ClientHeight    =   6285
   ClientLeft      =   -180
   ClientTop       =   315
   ClientWidth     =   10875
   Icon            =   "frmGUI.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6285
   ScaleWidth      =   10875
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin CodeSenseCtl.CodeSense txtConsole
      Height          =   6255
      Left            =   1320
      OleObjectBlob   =   "frmGUI.frx":57E2
      TabIndex        =   1
      Top             =   120
      Width           =   9495
   End
   Begin VB.CommandButton Command1
      Caption         =   "Execute"
      Height          =   495
      Left            =   240
      TabIndex        =   0
      ToolTipText     =   "Also Use Ctl+Enter to Execute"
      Top             =   240
      Width           =   975
   End
End
Attribute VB_Name = "frmGui"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public Event onbtnExecuteClicked(sCode As String)

Public Event onfrmUnloading()

Private Sub Command1_Click()
  Dim sCode As String
  sCode = CStr(txtConsole.Text)
  txtConsole.Text = ""
  RaiseEvent onbtnExecuteClicked(sCode)
End Sub

Private Sub Form_Load()
  Setup_CodeWindow
End Sub

Private Sub Form_Unload(Cancel As Integer)
  RaiseEvent onfrmUnloading
End Sub

Sub Setup_CodeWindow()
  txtConsole.GlobalProps = True
  txtConsole.SelBounds = True
  'txtConsole.StealKeys = True
  txtConsole.LineNumbering = True
  txtConsole.LineNumberStart = 1
  txtConsole.AutoIndentMode = 2
  txtConsole.EnableDragDrop = True
  txtConsole.DisplayLeftMargin = True
  txtConsole.BorderStyle = 10
  txtConsole.object.Language = "Basic"
  txtConsole.ColorSyntax = True
  txtConsole.HScrollVisible = False
End Sub



Tue, 31 May 2005 06:43:13 GMT  
 
 [ 20 post ]  Go to page: [1] [2]

 Relevant Pages 

1. ActiveX Control Container for VBCCE5 ActiveX Controls!?

2. Calendar or ActiveX Control on html page

3. Changing HTML Help ActiveX Control Parameters from Script

4. ActiveX control not available in HTML

5. Focus on ActiveX Control Combobox in HTML Form

6. ActiveX Tree Controls in HTML Forms

7. Using ActiveX Tab Strip Control in HTML

8. Changing HTML Help ActiveX Control Parameters from Script

9. ActiveX control not available in HTML

10. Referencing ActiveX Control within html form tag

11. ActiveX takes control from HTML

12. Changing HTML Help ActiveX Control Parameters from Script

 

 
Powered by phpBB® Forum Software