PRB: VB4 16-Bit Clients Cannot Early-Bind to VB5 .EXE Servers
ID: Q175488
|
The information in this article applies to:
-
Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 4.0, 5.0, 6.0
SYMPTOMS
If you have a Visual Basic 4.0 16-bit client that early-binds to a Visual
Basic 4.0 32-bit server and you replace the Visual Basic 4.0 32-bit server
with a binary-compatible Visual Basic 5.0 or 6.0 32-bit server, you receive
the following message when you try to run the client:
"Run-time error '-2147319784 (80028018)' OLE Automation error"
CAUSE
A Visual Basic 4.0 16-bit client can make use of the services of a Visual
Basic 4.0 32-bit local server (EXE OLE Server) with both early- and late-
binding. However, a Visual Basic 4.0 16-bit client can only late-bind to a
Visual Basic 5.0 or 6.0 32-bit server (ActiveX EXE).
The type library of the Visual Basic 5.0 or 6.0 32-bit server does not
appear in the references list of the Visual Basic 4.0 16-bit design
environment.
This also applies if you are upgrading a Visual Basic 4.0 32-bit local
server to a Visual Basic 5.0 or 6.0 ActiveX EXE and your server is going to
be used by a Visual Basic 4.0 16-bit client. You will have to use late-
binding in the Visual Basic 4.0 16-bit application. This is true even if
you simply recompile the project in Visual Basic 5.0 or 6.0 and set the
component to be binary compatible to the existing Visual Basic 4.0 32-bit
component.
RESOLUTION
Use late binding with CreateObject as shown below.
MORE INFORMATIONStep-by-Step Example
- Start 32-bit Visual Basic 4.0.
- Remove Form1 and insert a module (Module1) and a class module (Class1).
- Add the procedure Sub Main() to Module1.
- Set Class1's Name property to CServer, Instancing property to 2-
Creatable MultiUse and Public property to True.
- On the Tools menu, click Options. In the Options dialog box,
select the Project tab. Change Project Name to Server32, set
StartMode to OLE Server, and enter an Application Description of
"32-Bit Visual Basic Server."
- Paste the following code into the General Declarations section of the
CServer (formerly Class1) class module:
Private mName As String
Private Sub Class_Initialize()
mName = "Default name"
End Sub
Public Property Get sName() As String
sName = mName
End Property
Public Property Let sName(vNewValue As String)
mName = vNewValue
End Property
- Save the BAS module as Server32M.bas, the class module as Server32C.cls,
and the project as Server32.vbp, and then compile the project as
Server32.exe.
- Exit Visual Basic 4.0 32-bit.
- Start 16-bit Visual Basic 4.0.
- On the Tools menu, click References and then check 32-Bit Visual Basic
Server. You may have to use the Browse button to add Server32.exe to the
references list.
- Add the controls listed in the table below to your form (Form1). Change
the name property of these controls to the value listed in the Updated
Name column and change the caption property of those controls to the
value listed in the Updated Caption column.
Control Type Default Name Updated Name Updated Caption
-----------------------------------------------------------------
TextBox Text1 txtEarly
TextBox Text2 txtLate
Label Label1 lblEarly
Label Label2 lblLate
CommandButton Command1 cmdEarly Change Early's Name
CommandButton Command2 cmdLate Change Late's Name
- Change Form1's Name property to frmTest.
- Paste the following code into the General Declarations section of
frmTest (formerly Form1):
Dim LateObj As Object
Dim EarlyObj As New Server32.CServer
Private Sub cmdLate_Click()
On Error GoTo LateErrHandler:
With LateObj
.sName = txtLate
lblLate = .sName
End With
Exit Sub
LateErrHandler:
MsgBox Err.Number & " " & Err.Description
End Sub
Private Sub cmdEarly_Click()
On Error GoTo EarlyErrHandler:
With EarlyObj
.sName = txtEarly
lblEarly = .sName
End With
Exit Sub
EarlyErrHandler:
MsgBox Err.Number & " " & Err.Description
End Sub
Private Sub Form_Load()
On Error GoTo LoadErrHandler:
Set LateObj = CreateObject("server32.CServer")
lblEarly.Caption = EarlyObj.sName
Exit Sub
LoadErrHandler:
MsgBox Err.Number & " " & Err.Description
End Sub
- Test and then save the form as Client16.frm and the project as
Client16.vbp.
- Compile the project as Client16.exe and then exit Visual Basic 4.0
16-bit. Run Client16.exe and verify that both the early and late buttons work correctly.
- Copy Server32.exe to Server32B.exe (the backup copy) and copy the
Server32 project files to a new (backup) directory.
- Open the original Server32 project in 32-bit Visual Basic 4.0.
- Select the Options menu item from the Tools menu, and on the resulting
Options dialog, select the Project tab. Under Compatible OLE Server, use
the ellipsis button ("...") to select Server32B.exe (the backup copy of
Server32.exe).
- Recompile the project, making sure it over-writes the original copy of
Server32.exe, and then exit Visual Basic 4.0 32-bit.
- Run Client16.exe. It should still work if you have followed these steps
correctly.
- Using Visual Basic 5.0 or 6.0, recompile the Server32 project into
Server32.exe and make sure it over-writes the original copy of
Server32.exe.
- Run Client16.exe.
RESULT: You should receive one of the following error messages:
Error 429, 429 OLE Automation server can't create object
-2147319784 OLE Automation Error
After clearing the error message box, click the "Change Early's Name"
button (early-bound to server) which should produce the same error.
Clicking on the "Change Late's Name" button (late-bound to server) should
work.
Keywords : kberrmsg kbnokeyword kbVBp400 kbVBp500 kbVBp600 kbGrpVB
Version :
Platform :
Issue type : kbprb
|