The error occurs because the target computer is missing the license information for the control objects that are used in the application. You might attempt to set the project reference to point to MSWINSCK.ocx, and then generate a deployment package through the use of the Package and Deployment Wizard. This would generate a setup package that contains the correct version of the Winsock control. However, the license key for the control will not be compiled into the application unless an instance of the control is placed on a form. When you try to instantiate the objects at run time, the application has no way to provide the license key, and the code will fail. For example, the following code will run properly at design time, but will fail at run time on computers that do not have Visual Basic installed:
程序原来是这样定义的。
Dim myWinSock As MSWinsockLib.Winsock
Sub Main()
' Early binding does not work
Set myWinSock = New MSWinsockLib.Winsock
myWinSock.LocalPort = 5432
myWinSock.Listen
MsgBox ("Listening!")
myWinSock.Close
End Sub
Therefore, you must provide an instance of the Winsock control on a form so that Visual Basic can compile the license information into the application. You can make the form hidden if necessary. To do this, set the form's Visible property to "False." You can then prepare for deployment. The following code snippet demonstrates the method:
使用这种方法,就解决了问题。
Dim myWinsock As MSWinsockLib.Winsock
Sub Main()
' Form1 is hidden
Set myWinsock = Form1.myWinsock