Unable to call trivial OCX from VB
George V. Reilly -- georger@microcrafts.com Tuesday, October 15, 1996 Environment: NT 4.0, VC 4.1, VB 4.0 I'm trying to create an ActiveX control that I can call from VBscript. I couldn't get it working there, so I'm trying to do it in VB 4.0. I created an OCX with the OLE ControlWizard and added a couple of trivial methods. When I try to call any of them from VB---even the Wizard-provided one of AboutBox---I get a runtime error of 8000FFFF (E_UNEXPECTED), a "catastrophic failure" of OLE automation. I'm using the following procedure which is attached to an input box. When Enter is pressed, the object gets created and then one of its methods is called. Private Sub Input_KeyPress(KeyAscii As Integer) If (KeyAscii = 13) Then Dim Hello As Object Set Hello = CreateObject("HELLOWORLD.HelloWorldCtrl.1") ' Hello.TestEcho("Foo") Hello.AboutBox Set Hello = Nothing End If End Sub I've saved the VB program as an EXE and tried running it in VC 4.1. The object gets constructed successfully, but it fails in COleDispatchImpl::Invoke. It calls IsInvokeAllowed, which returns FALSE (m_bInitialized has not been set). A friend of mine thought that it might be something to do with the ODL file generated by the Wizard, but when put on the spot, was unable to pinpoint the problem or produce a reference. All of this confirms my longstanding prejudice that OLE and VB are evil, but that's not getting me anywhere. TIA. -- /George V. ReillyMicroCrafts, Inc., 17371 NE 67th Ct #205, Redmond, WA 98052, USA. Tel: +1 206/250-0014 Fax: 206/250-0100 Web: www.microcrafts.com Vim 4 (vi clone) for NT & Windows 95: http://www.halcyon.com/gvr/ pgp fingerprint: e2 b4 83 64 11 52 21 ea bf d8 51 c2 11 00 78 fc
Neil Hodgson -- ip104@astsun.fujitsu.com.au Thursday, October 17, 1996 [Mini-digest: 2 responses] George V. Reilly wrote on October 16, saying "Unable to call trivial OCX from VB" This is a limitation in MFC's OCX implementation. To access the OLE Automation interface of an MFC OCX, that OCX must be fully intantiated and loaded. Often, it makes no sense to call the OA interface before the OCX's properties have been loaded. The CreateObject in your example is simply doing a CoCreateInstance which will not perform all the needed operations. You could modify your OCX to make it accept incoming automation calls without full instantiation but I think the solution to your problem is much simpler. To do what you want, you should place the OCX on a Visual Basic form. Then you may call its automation interface. This way it is fully loaded and happy to accept calls before you call it. Similarly in VBScript, place the OCX on the page. Neil Hodgson -----From: "George V. Reilly"To answer my own question: > I created an OCX with the OLE ControlWizard > and added a couple of trivial methods. When I try > to call any of them from VB---even the Wizard-provided > one of AboutBox---I get a runtime error of 8000FFFF > (E_UNEXPECTED), a "catastrophic failure" of OLE > automation. It is necessary to override COleControl::IsInvokeAllowed to return TRUE. KnowledgeBase article Q146120: "How to Use an OLE Control as an Automation Server" sort of explains why. -- /George V. Reilly MicroCrafts, Inc., 17371 NE 67th Ct #205, Redmond, WA 98052, USA. Tel: +1 206/250-0014 Fax: 206/250-0100 Web: www.microcrafts.com Vim 4 (vi clone) for NT & Windows 95: http://www.halcyon.com/gvr/ pgp fingerprint: e2 b4 83 64 11 52 21 ea bf d8 51 c2 11 00 78 fc
Dublin-ISG2@stercomm.com Friday, October 18, 1996 [Mini-digest: 2 responses] George V. Reilly wrote on October 16, saying "Unable to call trivial OCX from VB" This is a limitation in MFC's OCX implementation. To access the OLE Automation interface of an MFC OCX, that OCX must be fully intantiated and loaded. Often, it makes no sense to call the OA interface before the OCX's properties have been loaded. The CreateObject in your example is simply doing a CoCreateInstance which will not perform all the needed operations. You could modify your OCX to make it accept incoming automation calls without full instantiation but I think the solution to your problem is much simpler. To do what you want, you should place the OCX on a Visual Basic form. Then you may call its automation interface. This way it is fully loaded and happy to accept calls before you call it. Similarly in VBScript, place the OCX on the page. Neil Hodgson -----From: "George V. Reilly"To answer my own question: > I created an OCX with the OLE ControlWizard > and added a couple of trivial methods. When I try > to call any of them from VB---even the Wizard-provided > one of AboutBox---I get a runtime error of 8000FFFF > (E_UNEXPECTED), a "catastrophic failure" of OLE > automation. It is necessary to override COleControl::IsInvokeAllowed to return TRUE. KnowledgeBase article Q146120: "How to Use an OLE Control as an Automation Server" sort of explains why. -- /George V. Reilly MicroCrafts, Inc., 17371 NE 67th Ct #205, Redmond, WA 98052, USA. Tel: +1 206/250-0014 Fax: 206/250-0100 Web: www.microcrafts.com Vim 4 (vi clone) for NT & Windows 95: http://www.halcyon.com/gvr/ pgp fingerprint: e2 b4 83 64 11 52 21 ea bf d8 51 c2 11 00 78 fc
| Вернуться в корень Архива |