OLE object names
Koronthaly David -- dkoronth@blava-s.bratisla.ingr.com
Thursday, September 12, 1996
Environment: VC++ 4.2, Win NT 4.0, VB 4.0, MSDN
I am writing OLE Automation server in MFC and client in VB
I want server to appear as single creditable object (Foo.Application),
which in turn will have several other objects and collection accessible
as its properties. I am using dual interfaces. I have created several
objects connected together, each of them derived from CCmdTarget and
Automation enabled.
1. I don't know how to update IDL file correctly - I am having two
names for each object in VB (like CFoo and IFoo). (one is for interface
and other for coclass)
2. I don't know how to display all objects in type library (so user can
browse their structure), but to allow only application object to be
created directly
Thanks,
>David Koronthaly
Dean Wiles -- deanw@isc-br.isc-br.com
Friday, September 13, 1996
This seems to be a common scenario that would be great if the MFC team could
facilitate as part of the AppWizard and ClassWizard support :-)
We are in the process of doing some similar things - this is what we've
found thus far:
BTW, this is after we used TN065 for implementing the dual-interface.
1. If you add the keyword "hidden" to your interface description, it does
not show up in VB's interface list:
[ uuid(...), hidden ]
dispinterface IMyClass
2. To register the type library takes a few extra steps:
In your project.rc2 or project.rc file, include your type library into your
resources:
1 TYPELIB "project.tlb"
To register your server, use:
// register type library
AfxOleRegisterTypeLib(AfxGetInstanceHandle(), LIBID_MyLibrary);
// register all object factories
COleObjectFactory::UpdateRegistryAll(TRUE);
The "LIBID_MyLibrary" can be generated by going into your Project Settings,
selecting your .odl file in the Settings For: list, select the OLE Types
tab, and enter an new filename in the Output header file name: field. We
did this under VC++ 4.1, before odl and idl where supposedly merged, so if
you use idl, it may be a little different.
To actually register (and unregister correctly) you may need to add a
DECLARE_OLECREATE_EX(CMyClass) in the class declaration in your class.h, and
the following code in class.cpp: (If you generated your app from AppWizard
as an OLE In-Place server, you may have to do this differently because it
does part but not all of it for you.)
#include "afxclt.h"
IMPLEMENT_OLECREATE_EX(CMyClass, "MyLibrary.MyClass", CLSID...)
//If your class already had DECLARE_OLECREATE, then use the _EX version of
the macros.
/////////////////////////////////////////////////////////////////////////////
// CMyClass::CMyClassFactory::UpdateRegistry -
// Adds or removes system registry entries for CMyClass
BOOL CMyClass::CMyClassFactory::UpdateRegistry(BOOL bRegister)
{
if (bRegister)
return AfxOleRegisterServerClass(m_clsid, m_lpszProgID,
m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// Type library support
IMPLEMENT_OLETYPELIB(CMyClass, LIBID_MyLibrary, wVerMajor, wVerMinor)
// Pick you own wVerMajor & wVerMinor - we started with 1,0 for 1.0
BOOL CMyClass::GetDispatchIID(IID* pIID)
{
*pIID = DIID_IMyClass;
return TRUE;
}
And in your CMyClass constructor, should you should have the following:
EnableAutomation();
AfxOleLockApp();
EnableTypeLib();
There were also some other gotchas when using optional or named parameters
when calling from VB, but we haven't figured them all out yet ;-). Calling
C++ OLE servers from VB is feasible, just not easy. I hope Microsoft picks
up the ball on this since they are so strongly pushing developers to go
their way. Not all OLE development is in ActiveX controls!
Again, this is only what we have found thus far by sorting through OCX MFC
code, doc, and lots of trial and error. Hope it is helpful. Dean.
At 06:40 PM 9/12/96 +0200, you wrote:
>Environment: VC++ 4.2, Win NT 4.0, VB 4.0, MSDN
>
>I am writing OLE Automation server in MFC and client in VB
>
>I want server to appear as single creditable object (Foo.Application),
>which in turn will have several other objects and collection accessible
>as its properties. I am using dual interfaces. I have created several
>objects connected together, each of them derived from CCmdTarget and
>Automation enabled.
>
>1. I don't know how to update IDL file correctly - I am having two
>names for each object in VB (like CFoo and IFoo). (one is for interface
>and other for coclass)
>
>2. I don't know how to display all objects in type library (so user can
>browse their structure), but to allow only application object to be
>created directly
>
>
>Thanks,
>>David Koronthaly
>
>
--------------------------------------------------------------------------
Dean Wiles (deanw@mail.isc-br.com) Olivetti North America
Phone: (509)927-7037 22425 East Appleway Ave
Fax: (509)927-2499 Liberty Lake, WA 99019-9534
If the Son sets you free, you will be free indeed. (John 8:36)
Martin Schlaghecke -- Martin.Schlaghecke@studbox.uni-stuttgart.de
Monday, September 16, 1996
> 1. I don't know how to update IDL file correctly - I am having two
> names for each object in VB (like CFoo and IFoo). (one is for interface
> and other for coclass)
The ODL file should hide the Interface Classes this is done by adding
",hidden" to the ClassHeader:
[ GUID..., hidden ]
dispinterface ITestClass
| Вернуться в корень Архива
|