Posted by
| Nick Gammon
Australia (22,982 posts) bio
Forum Administrator |
Message
| OK, this works pretty well. :)
The fundamental problem as I see it is if you try to start your external app first, and then call MUSHclient, you don't have a "world" object to use, and thus you can't do world.anything.
However, if you start MUSHclient, then call the external app, it all works fine.
This is pretty similar to an earlier post (subject 405) however this one actually shows a form that you can click to do nice things ...
- Copy the stuff between the lines below and save into the file names in bold (excluding the file name itself, of course).
- Start Visual Basic
- Open project mc_example_project.vbp (as saved to disk in step 1).
- Go to the File menu and choose "Make mc_example_project.exe"
The above steps have created a ActiveX file that can be called from MUSHclient.
mc_example_project.vbp
Type=OleExe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#E:\WINNT\System32\StdOle2.Tlb#OLE Automation
Reference=*\G{11DFC5E7-AD6F-11D0-8EAE-00A0247B3BFD}#1.0#0#c:\mushclient\MUSHclient.tlb#MUSHclient
Class=mc_example_class; mc_example_class.cls
Form=Form1.frm
Module=Module1; Module1.bas
Startup="(None)"
ExeName32="mc_example_project.exe"
Command32=""
Name="mc_example_project"
HelpContextID="0"
CompatibleMode="1"
CompatibleEXE32="mc_example_project.exe"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Gammon Software Solutions"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=1
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
DebugStartupOption=0
Form1.frm
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5145
ClientLeft = 60
ClientTop = 345
ClientWidth = 6270
LinkTopic = "Form1"
ScaleHeight = 5145
ScaleWidth = 6270
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "Send It"
Height = 495
Left = 4200
TabIndex = 5
Top = 4440
Width = 1215
End
Begin VB.TextBox DataToSend
Height = 375
Left = 1440
TabIndex = 4
Text = "Command"
Top = 4440
Width = 2295
End
Begin VB.CommandButton Command2
Caption = "Get World List"
Height = 495
Left = 240
TabIndex = 2
Top = 3480
Width = 2055
End
Begin VB.ListBox List1
Height = 2010
Left = 240
TabIndex = 1
Top = 1200
Width = 4095
End
Begin VB.CommandButton Command1
Caption = "test button"
Height = 615
Left = 360
TabIndex = 0
Top = 240
Width = 1455
End
Begin VB.Label Label1
Caption = "Send:"
Height = 255
Left = 360
TabIndex = 3
Top = 4440
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
If gWorld Is Nothing Then Exit Sub
gWorld.Note "test button clicked"
End Sub
Private Sub Command2_Click()
Dim worldlist, item
worldlist = gWorld.GetWorldList
For Each item In worldlist
List1.AddItem item
Next
End Sub
Private Sub Command3_Click()
Dim thedata
thedata = DataToSend.Text
gWorld.Send thedata
End Sub
mc_example_project.vbw
mc_example_class = 39, 31, 557, 468, C
Form1 = 154, 154, 672, 591, C, 86, 40, 604, 477, C
Module1 = 176, 176, 694, 613, C
mc_example_class.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 = "mc_example_class"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Sub Initialise_me(theworld As World)
'
' save pointer to the calling world
'
Set gWorld = theworld
'
' debug - message to world
'
gWorld.Note "MC Example initialised"
Form1.Show ' show our first form
End Sub
Module1.bas
Attribute VB_Name = "Module1"
'
' Global pointer to the world that initialised us
'
Public gWorld As World
Finally, to test it out in MUSHclient, open a Immediate window, enter the following and hit Run ...
dim x
set x = createobject ("mc_example_project.mc_example_class")
if x is nothing then msgbox "oh no"
x.Initialise_me (World)
set test = nothing
This should show the Form from the Visual Basic project, you can then click on the buttons to send a command to the world, get a list of open worlds, and so on.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|