OLE Automation
Jurgen Postelmans -- Jurgen.Postelmans@ping.be Thursday, November 16, 1995 I'm trying to learn how to program OLE Automation Clients/Servers in MFC = but I have some questions that I don't know how to solve: 1) Is there any way to pass a complete class as a parameter of a = Automation function ? I want to be able to pass an uninitialized class = to the automation server. The server must then initialize all the data = members and pass it back to the client. How is this done in OLE ? 2) Is it possible to use optional parameters in Automation function with = MFC ? I don't know how to set it when adding a function with the = classwizard. Do I have to edit the ODL file manually ? And what if you = generate a class from the ODL file ? Thanks for any help Jurgen Postelmans
paf Pete Ferreira Friday, November 17, 1995 > > 1) Is there any way to pass a complete class as a parameter of a = > Automation function ? I want to be able to pass an uninitialized class = > to the automation server. The server must then initialize all the data = > members and pass it back to the client. How is this done in OLE ? > There's several ways to do this. At one extreme, the "COM correct" way is to make your class a COM object and pass a pointer to its IUnknown. AT the other end of the spectrum, if you're writing both the client and the server, and the server is in-proc, you can cast a pointer to your object to a long, pass it through a standard IDispatch interface, and cast it back to a pointer on the other side. These and other methods are covered in the OLE column in the most recent MSJ. > 2) Is it possible to use optional parameters in Automation function with = > MFC ? I don't think you can have optional parameters a la C varargs, but you don't have to pass real 'data' as long as the function receiving the data can tell which parameters are 'real'. > Do I have to edit the ODL file manually ? And what if you = > generate a class from the ODL file ? > My advice is don't mess with ODL until you're comfortable with the issues involved in marshalling data. Hope this helps, Pete paf@netcom.com http://www.webcom.com/paf/pete.html
Jim Lavin -- ooptech@Onramp.NET Friday, November 17, 1995 At 06:03 PM 11/16/95 +-100, you wrote: >I'm trying to learn how to program OLE Automation Clients/Servers in MFC but I have some questions that I don't know how to solve: > >1) Is there any way to pass a complete class as a parameter of a Automation function ? I want to be able to pass an uninitialized class to the automation server. The server must then initialize all the data members and pass it back to the client. How is this done in OLE ? > Sorry, but you can not pass a class to an automation object. You are sending the class to a different process space, or code segment in WIN16, therefore you will lose your virtual function table, even if you include the class's code in the automation server it will not work. What you need to do, is create a structure that holds the attributes, or data members, of the class and pass it as a Safe Array to the automation server. Then in the automation server you will have to decoded the structure and create a class from it. I do this by having member functions that take a structure as in input and either reads the structure to initialize the class or fills it out for passing to the automation server. >2) Is it possible to use optional parameters in Automation function with MFC ? I don't know how to set it when adding a function with the classwizard. Do I have to edit the ODL file manually ? And what if you generate a class from the ODL file ? > I think Microsoft has something about passing optional parameters in OLE automation on thier Web Site www.microsfot.com in the Visual C++ knowledge base. I have not done much with optional parameters as far as OLE automation is concerned so I can't help much. >Thanks for any help > >Jurgen Postelmans > > Good Luck Jim Lavin OOP Technologies http://emporium.turnpike.net/~jlavin http://rampages.onramp.net/~ooptech
Stephen Keeler -- keelers@igs.net Saturday, November 18, 1995 > I'm trying to learn how to program OLE Automation Clients/Servers in > MFC but I have some questions that I don't know how to solve: > > 1) Is there any way to pass a complete class as a parameter of a > Automation function ? I want to be able to pass an uninitialized > class to the automation server. The server must then initialize all > the data members and pass it back to the client. How is this done in > OLE ? Sorry, don't know the answer to this one. > 2) Is it possible to use optional parameters in Automation function > with MFC ? I don't know how to set it when adding a function > with the classwizard. Do I have to edit the ODL file manually ? And > what if you generate a class from the ODL file ? Yes, you need to make sure the parameters are VARIANTS, and I believe you also need to manually add the 'optional' ODL keyword to the parameter(s) modifier which is enclosed in the square brackets. Regards, Stephen Keeler On-Line Systems Inc.
Sunil Kumar P -- sunilk@OPTIMASW.COM Thursday, November 23, 1995 Hi, I am adding OLE Automation functionality to a server application. Can anyone suggest a through testing procedure apart from the controllers developed in DispTest/VisualBasic. An entry is being made into the Registration Database and the server application is functioning normally when called from these controllers. I am using Visual C++ 1.52 and MFC 2.5. ~~~~~~~~~~~~~~~~~~~~~~~~U~T~O~P~I~A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sunil Kumar Pothakamoorie Voice : 91-40-290321,292771 Optima Software Services Ltd Fax : 91-40-294810 #503, HUDA COMPLEX Internet : sunilk@optimasw.com Maitrivanam, AMEERPET, HYDERABAD 500 038 Home Page: http://www.optimasw.com ANDHRA PRADESH INDIA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David Dworkin -- ddworkin@wpine.com Wednesday, November 13, 1996 Environment: VC++ 4.2-flat, Win 95 Hi, I have an existing MFC app (*not* doc/view based) which I'm trying to make into an OLE automation server. To get some basic automation code, I made a generic automation MFC appwizard app, and am grabbing the stuff from there into my application. However, it's not quite a direct parallel, as the MFC app is doc/view based, and my app is not. I yanked the automation stuff out of the Doc class, and have it in my CWinApp-derived class. [First question: was that the right thing to do?] At the moment, I just want to launch my application via OLE automation, then add the properties and methods. I create a simple VB app which does a CreateObject on my application object (everything is in the registry correctly I think, and the GUIDS are all set up properly). When I run the VB app, my application gets launched appropriately, I detect that it's run via automation (the m_bRunAutomated flag), everything seems OK. But, control doesn't come back to the VB app. Shortly (maybe 1 minute), my app goes away, and VB tells me it could not successfully create the object. I try the same thing creating an automation clent MFC app (importing the type library that I created), and same thing -- I call if (!(m_server.CreateDispatch("MyApp.Document"))) and same thing -- the app launches, but control doesn't come back, then after 1 minute or so, it goes away, and this call fails. there must be something that I'm just not doing in my application. Does anyone have any ideas? Thanks a lot, David Dworkin ddworkin@wpine.com ============================================================================ _________________________________________________________________________ White Pine Software - Nashua, NH has MOVED ! (Please make note of our new NH address) _________________________________________________________________________ David Dworkin ddworkin@wpine.com White Pine Software White Pine Software 15 Messenger St. 542 Amherst Street Plainville MA 02762 Nashua NH 03063 508-699-7051 / 508-695-2378 (Fax) 603-886-9050 ext 402 / 603-886-9051 (Fax) www.wpine.com (WWW) www.wpine.com (WWW) ============================================================================
Carl Gunther -- cgunther@ix.netcom.com Monday, November 18, 1996 David, Although it is true that CWinApp is derived from CCmdTarget, and therefore inherits the OLE support provided by MFC, I suspect that it is not an appropriate place to put an OLE server interface. Normally, you will want to create an instance of your OLE server interface object when a client requests such a connection, and remove it when the last reference is gone. This obviously will create problems if your interface object is also your application object. My own approach to automating an existing MFC application was to create a new CCmdTarget-derived class to serve as the OLE interface object. The constructor of this class should call EnableAutomation() and AfxOleLockApp(). The destructor should call AfxOleUnlockApp(). Its OnFinalRelease() override should "delete this" to delete itself when the final reference by a client is released. You also need an IMPLEMENT_OLECREATE macro call at the top of the implementation file (and a DECLARE_OLECREATE macro call in the declaration file), with a unique name and class ID for your interface. All of your external OLE interface functions can be declared using ClassWizard in the usual manner (from the OLE Automation tab). Since it is part of the same compilation unit, you ought to be able to call any aspect of your application that is required from an instance of this interface class. By the way, it has been my experience that if you want to build an OLE automation server interface into an application that is also intended to be directly invoked by a user, what MFC's standard AppWizard-created servers will do is create two separate instances of the application - one for the server, and one for the end-user application. Therefore, it is important that your application be able to run with multiple instances, so you want to be sure that it's not a large model 16-bit application. If the app is built on the large model, then you'll have to create a separate server app using some compiler switches (and a separate .DEF file to rename the module) if you want to run it as both a server and as an application (in other words, you're going to need two distinct applications, compiled for convenience from the same source). Hope this helps, Carl Gunther David Dworkin wrote: > > Environment: VC++ 4.2-flat, Win 95 > > Hi, > > I have an existing MFC app (*not* doc/view based) which I'm trying > to make into an OLE automation server. To get some basic automation > code, I made a generic automation MFC appwizard app, and am grabbing > the stuff from there into my application. > > However, it's not quite a direct parallel, as the MFC app is doc/view > based, and my app is not. I yanked the automation stuff out of the Doc > class, and have it in my CWinApp-derived class. [First question: was > that the right thing to do?] At the moment, I just want to launch my > application via OLE automation, then add the properties and methods. > I create a simple VB app which does a CreateObject on my application > object (everything is in the registry correctly I think, and the GUIDS > are all set up properly). When I run the VB app, my application > gets launched appropriately, I detect that it's run via automation > (the m_bRunAutomated flag), everything seems OK. But, control doesn't > come back to the VB app. Shortly (maybe 1 minute), my app goes away, > and VB tells me it could not successfully create the object. > > I try the same thing creating an automation clent MFC app (importing the > type library that I created), and same thing -- I call > if (!(m_server.CreateDispatch("MyApp.Document"))) > and same thing -- the app launches, but control doesn't come back, then > after 1 minute or so, it goes away, and this call fails. > > there must be something that I'm just not doing in my application. > Does anyone have any ideas? > > Thanks a lot, > > David Dworkin > ddworkin@wpine.com > ============================================================================ > _________________________________________________________________________ > > White Pine Software - Nashua, NH has MOVED ! > (Please make note of our new NH address) > _________________________________________________________________________ > David Dworkin ddworkin@wpine.com > > White Pine Software White Pine Software > 15 Messenger St. 542 Amherst Street > Plainville MA 02762 Nashua NH 03063 > 508-699-7051 / 508-695-2378 (Fax) 603-886-9050 ext 402 / 603-886-9051 > (Fax) > www.wpine.com (WWW) www.wpine.com (WWW) > ============================================================================ -- Check out the extensive Website of the Labor/Community Strategy Center at http://www.igc.apc.org/lctr/ Check out the Website of Songs for Social Change at http://globalvisions.org/cl/sfsc/ Copyright 1996 Carl E. Gunther. Permission to reproduce this message in text form for not-for-profit purposes freely granted provided that the preceeding copyright notice is retained.
| Вернуться в корень Архива |