Visual C++ OLE Automation and VB's GetObject
Vince Pajerski -- vp360@ansyspo.ansys.com Tuesday, February 20, 1996 MSVC 4.0 (with service pack 1) MFC 4.0 Windows NT 3.51 (not using the new shell with service pack 3) VB 4.0 Hi all, I'm trying to access an existing automation object using VB and the GetObject function call. The automation server is written with VC++ . The call looks like this: dim obj as Object set obj = GetObject(, "Myapp.document") // doesn't work However, this code will execute: dim obj as Object set obj = GetObject("", "Myapp.document") // works but trashes my document Every time the 1st two lines execute, VB complains that it can't create the object. According to the documentation, it should return a reference to the active object and not create a new one. The app I built from VC++ is a standard app generated from App Wizard and only exposes one method to the world. I tried the same code with an Excel object and it worked fine. The code to do this looks like: dim obj as Object set obj = GetObject(,"Excel.Application") This works provided that Excel is up and running already, so I am lead to believe that something is wrong with either my code and/or the type library. Can anyone help? if(Penguins != Stanley_Cup) something_went_terribly_wrong( ); Vince Pajerski ANSYS Inc. e-mail vpajerski@ansys.com
Ludek Slegr -- ludek.slegr@munich.ixos.de Wednesday, February 21, 1996 [Mini-digest: 2 responses] Hi Vince, > I'm trying to access an existing automation object using VB and the > GetObject function call. The automation server is written with VC++ . The > call looks like this: > > dim obj as Object > set obj = GetObject(, "Myapp.document") // doesn't work I will tell you, what you probably know already. It looks like the Server is not running or the class does not match the entry in the registry. Regards, Ludek -----From: Victor Garcia ApreaHi, 1) Why are you using GetObject instead of CreateObject. Are you creating a new object, right? 2) If you wrote the code for the OLE Automation server, are you calling AddRef() before returning a reference to the object? Because if you forget to call AddRef() on your new object and then return a reference to it, when it goes out of scope then VB can crash itself and actually it sure will do that (happen to me). I wrote my own OLE Auto server and I tested it from VB 4. At the first time I got some problems but know I have a bit of experience. If you continue having problems maybe I can help you if you explain the problem in more detail. Victor Garcia Aprea.
| Вернуться в корень Архива |