I'm trying to get this very simple VB code to work which worked before but now it fails. Strangely though, the ASP templates work fine so the control is obviously registered. I double checked the reference in VB as well.. HBControl.exe works fine too.
Option Explicit
Dim Obj As HBControl
Dim szRsp As String
Dim szVal As String
Private Sub Form_Load()
Set Obj = CreateObject("HBControlMod.HBControl")
End Sub
Private Sub Command1_Click()
szRsp = Obj.Connect(1234, "127.0.0.1", "pwd")
szVal = Obj.GetDeviceList("|")
Text1.Text = "szRsp: " + szRsp + vbCrLf + "szVal: " + szVal
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Obj = Nothing
End Sub
Results from code above:
szRsp: Unable to connect to HouseBot computer. Port = 1234, IP = 127.0.0.1, Error = Either the application has not called WSAStartup, or WSAStartup failed.
The reason that your VB codes is not working is because I initialize the socket resources (with WSAStartup()) in a method (OnStartPage()) that is called by IIS when the web page is loaded. I also clean up the socket resources in a method that is called by the web server when the page is unloaded. Since your VB code is not calling these methods, it is failing.
It was an oversight by me in designing and coding with ASP samples only. I've updated the control to now be a bit more flexable and allow the socket resources to be initialized when it is needed. I haven't done much testing with this, but it was a fairly simple change and will hopefully work for you.
I've also added a doConnect(...) method that simply calls the old/existing Connect(...) method.
You can download the latest control here. Let me know how this works for you.
ScottBot wrote:The reason that your VB codes is not working is because I initialize the socket resources (with WSAStartup()) in a method (OnStartPage()) that is called by IIS when the web page is loaded. I also clean up the socket resources in a method that is called by the web server when the page is unloaded. Since your VB code is not calling these methods, it is failing.
It was an oversight by me in designing and coding with ASP samples only. I've updated the control to now be a bit more flexable and allow the socket resources to be initialized when it is needed. I haven't done much testing with this, but it was a fairly simple change and will hopefully work for you.
I've also added a doConnect(...) method that simply calls the old/existing Connect(...) method.
You can download the latest control here. Let me know how this works for you.
Scott
Bingo!
We have a winner.. It worked first time out. I had modified the Delphi TLB import by hand and changed the original connect method to doConnect instead of the override of connect1. I tested the new version using the modified doConnect TLB calling the original connect method and it worked the first time out.
Any Delphi users who try to import the new version will get two functions in the auto generation process. They'll get the original connect method renamed as connect1 and the new doConnect method as well.
Should work perfectly and require no hand tweaking or modification to the TLB units to make it work.