implementing interfaces from a type library 
Author Message
 implementing interfaces from a type library

Hi,

I want to implement a couple of interfaces defined in a type library.
The type library is called QXTypes.tlb which has been created in Visual Basic.NET.
It consists of the following definitions.

// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: <could not determine filename>
[
uuid(2FABA131-9DC3-4E35-88D6-3EC1A5841C9A),
version(1.0)
]

library QXTypes
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface ITServoSystem;
interface ITServoChannel;
interface ITTransducer;
[
odl,
uuid(1849613A-6EB3-3A13-B76A-DEB730329C13),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITServoSystem")
]

interface ITServoSystem : IUnknown {
HRESULT _stdcall GetServoChannel([in] long Index, [in, out] ITServoChannel** pServoChannel);
HRESULT _stdcall GetServoChannelCount([in, out] long* Count);
HRESULT _stdcall DownloadToHW();
HRESULT _stdcall SerialiseToDisk([in, out] VARIANT* XMLobj);

Quote:
};

[
odl,
uuid(8CA46DF9-832A-32AF-8997-CF87DFB35DE3),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITServoChannel")
]

interface ITServoChannel : IUnknown {
HRESULT _stdcall GetTransducer([in] long Index, [in, out] ITTransducer** pTransducer);
HRESULT _stdcall GetTransducerCount([in, out] long* Count);

Quote:
};

[
odl,
uuid(207BE976-1918-30EA-8F19-8557AEA48928),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITTransducer")
]

interface ITTransducer : IUnknown {
HRESULT _stdcall GetPID([in, out] ITPID** PID);

Quote:
};
};

To implement these interfaces I have added the following lines in the ATL idl file

importlib("..\tlb\QXTypes.tlb");
:
:
 [
  uuid(7D8B8E67-A9A6-488D-81FD-38E98D4D3FED),
  helpstring("TNICard Class")
 ]
 coclass TNICard
 {
  [default] interface ITMachine;
  interface ITServoSystem;
 };
 [
  uuid(D40F95AB-0C52-4F6F-8B87-C20E08A05D73),
  helpstring("TNIServoChannel Class")
 ]
 coclass TNIServoChannel
 {
  [default] interface ITDriveElem;
  interface ITServoChannel;
 };
 [
   uuid(9C9CEF65-F6F3-4D57-9D61-99847347085B),
   helpstring("TNITransducer Class")
]
coclass TNITransducer
{
   [default] interface ITTransducerElem;
   interface ITTransducer;

Quote:
};

In each ATL class header file I have added the interface as follows for example

class ATL_NO_VTABLE CTNICard :
 public CComObjectRootEx<CComMultiThreadModel>,
 public CComCoClass<CTNICard, &CLSID_TNICard>,
 public ITMachine,
   public ITServoSystem

And added the interface methods as follows for example

  // --------------------------------------------------------------------------
  // Implementation of methods from interface: ITServoSystem
 STDMETHOD(GetServoChannel)(long Index, ITServoChannel * * pServoChannel);
 STDMETHOD(GetServoChannelCount)(long * Count);
 STDMETHOD(DownloadToHW)();

 STDMETHOD(SerialiseToDisk)(VARIANT * XMLobj);

I have then implemented these functions with simple MessageBoxes in the cpp files.

I want to be able to access these ATL objects by their default interfaces and well as the
interfaces I've just added.
For example in VB.net

HardwareMngr.GetMachine(iMachine, Machine) ' This returns a CTNICard object

' Check the object implements the ITMachine interface
If TypeOf Machine Is MACHINELib.ITMachine Then
    Windows.Forms.MessageBox.Show("MACHINELib.ITMachine found " & Serial)
End If
' Check the object implements the ITServoSystem interface
If TypeOf Machine Is QXTypes.ITServoSystem Then
    Windows.Forms.MessageBox.Show("ITServoSystem found " & Serial)
End If

' I want access to the methods through the ITServoSystem interface
Dim IServoSys As QXTypes.ITServoSystem = CType(Machine, QXTypes.ITServoSystem)
Dim l As Integer
IServoSys.GetServoChannelCount(l)

What happens is that ITMachine interface is found but ITServoSystem not.
Can anyone tell me what I'm doing wrong!!
Many, many, many thanks in advance!!!!!!!!!!!!!!!!!



Mon, 30 May 2005 01:31:56 GMT  
 implementing interfaces from a type library
Check if you've listed both interfaces in the interface map.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Hi,

I want to implement a couple of interfaces defined in a type library.
The type library is called QXTypes.tlb which has been created in Visual basic.NET.
It consists of the following definitions.

// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: <could not determine filename>
[
uuid(2FABA131-9DC3-4E35-88D6-3EC1A5841C9A),
version(1.0)
]

library QXTypes
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface ITServoSystem;
interface ITServoChannel;
interface ITTransducer;
[
odl,
uuid(1849613A-6EB3-3A13-B76A-DEB730329C13),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITServoSystem")
]

interface ITServoSystem : IUnknown {
HRESULT _stdcall GetServoChannel([in] long Index, [in, out] ITServoChannel** pServoChannel);
HRESULT _stdcall GetServoChannelCount([in, out] long* Count);
HRESULT _stdcall DownloadToHW();
HRESULT _stdcall SerialiseToDisk([in, out] VARIANT* XMLobj);

Quote:
};

[
odl,
uuid(8CA46DF9-832A-32AF-8997-CF87DFB35DE3),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITServoChannel")
]

interface ITServoChannel : IUnknown {
HRESULT _stdcall GetTransducer([in] long Index, [in, out] ITTransducer** pTransducer);
HRESULT _stdcall GetTransducerCount([in, out] long* Count);

Quote:
};

[
odl,
uuid(207BE976-1918-30EA-8F19-8557AEA48928),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITTransducer")
]

interface ITTransducer : IUnknown {
HRESULT _stdcall GetPID([in, out] ITPID** PID);

Quote:
};
};

To implement these interfaces I have added the following lines in the ATL idl file

importlib("..\tlb\QXTypes.tlb");
:
:
 [
  uuid(7D8B8E67-A9A6-488D-81FD-38E98D4D3FED),
  helpstring("TNICard Class")
 ]
 coclass TNICard
 {
  [default] interface ITMachine;
  interface ITServoSystem;
 };
 [
  uuid(D40F95AB-0C52-4F6F-8B87-C20E08A05D73),
  helpstring("TNIServoChannel Class")
 ]
 coclass TNIServoChannel
 {
  [default] interface ITDriveElem;
  interface ITServoChannel;
 };
 [
   uuid(9C9CEF65-F6F3-4D57-9D61-99847347085B),
   helpstring("TNITransducer Class")
]
coclass TNITransducer
{
   [default] interface ITTransducerElem;
   interface ITTransducer;

Quote:
};

In each ATL class header file I have added the interface as follows for example

class ATL_NO_VTABLE CTNICard :
 public CComObjectRootEx<CComMultiThreadModel>,
 public CComCoClass<CTNICard, &CLSID_TNICard>,
 public ITMachine,
   public ITServoSystem

And added the interface methods as follows for example

  // --------------------------------------------------------------------------
  // Implementation of methods from interface: ITServoSystem
 STDMETHOD(GetServoChannel)(long Index, ITServoChannel * * pServoChannel);
 STDMETHOD(GetServoChannelCount)(long * Count);
 STDMETHOD(DownloadToHW)();

 STDMETHOD(SerialiseToDisk)(VARIANT * XMLobj);

I have then implemented these functions with simple MessageBoxes in the cpp files.

I want to be able to access these ATL objects by their default interfaces and well as the
interfaces I've just added.
For example in VB.net

HardwareMngr.GetMachine(iMachine, Machine) ' This returns a CTNICard object

' Check the object implements the ITMachine interface
If TypeOf Machine Is MACHINELib.ITMachine Then
    Windows.Forms.MessageBox.Show("MACHINELib.ITMachine found " & Serial)
End If
' Check the object implements the ITServoSystem interface
If TypeOf Machine Is QXTypes.ITServoSystem Then
    Windows.Forms.MessageBox.Show("ITServoSystem found " & Serial)
End If

' I want access to the methods through the ITServoSystem interface
Dim IServoSys As QXTypes.ITServoSystem = CType(Machine, QXTypes.ITServoSystem)
Dim l As Integer
IServoSys.GetServoChannelCount(l)

What happens is that ITMachine interface is found but ITServoSystem not.
Can anyone tell me what I'm doing wrong!!
Many, many, many thanks in advance!!!!!!!!!!!!!!!!!



Mon, 30 May 2005 03:57:22 GMT  
 implementing interfaces from a type library
I forgot to mention that I have to also add

#import "..\tlb\QXTypes.tlb" raw_interfaces_only, raw_native_types,
no_namespace, named_guids

in the header file of the ATL class.
If I dont have this then I get this error

ctnicard.h(34) : error C2504: 'ITServoSystem' : base class undefined

The COM interface map section contains the following

  DECLARE_REGISTRY_RESOURCEID(IDR_TNICARD)

  DECLARE_PROTECT_FINAL_CONSTRUCT()

  BEGIN_COM_MAP(CTNICard)
   COM_INTERFACE_ENTRY(ITMachine)
   COM_INTERFACE_ENTRY(ITServoSystem)
  END_COM_MAP()

Everything compiles but when I run the VB.net app and try

If TypeOf Machine Is QXTypes.ITServoSystem Then
   MessageBox.Show("ITServoSystem found")
End If

It doesn't find the QXTypes.ITServoSystem interface.

All I want is to be able to implement this interface which is in a tlb file
and then call it from a VB.net app.

PLEASE HELP !!!


Check if you've listed both interfaces in the interface map.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Hi,

I want to implement a couple of interfaces defined in a type library.
The type library is called QXTypes.tlb which has been created in Visual
basic.NET.
It consists of the following definitions.

// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: <could not determine filename>
[
uuid(2FABA131-9DC3-4E35-88D6-3EC1A5841C9A),
version(1.0)
]

library QXTypes
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface ITServoSystem;
interface ITServoChannel;
interface ITTransducer;
[
odl,
uuid(1849613A-6EB3-3A13-B76A-DEB730329C13),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITServoSystem")
]

interface ITServoSystem : IUnknown {
HRESULT _stdcall GetServoChannel([in] long Index, [in, out] ITServoChannel**
pServoChannel);
HRESULT _stdcall GetServoChannelCount([in, out] long* Count);
HRESULT _stdcall DownloadToHW();
HRESULT _stdcall SerialiseToDisk([in, out] VARIANT* XMLobj);

Quote:
};

[
odl,
uuid(8CA46DF9-832A-32AF-8997-CF87DFB35DE3),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITServoChannel")
]

interface ITServoChannel : IUnknown {
HRESULT _stdcall GetTransducer([in] long Index, [in, out] ITTransducer**
pTransducer);
HRESULT _stdcall GetTransducerCount([in, out] long* Count);

Quote:
};

[
odl,
uuid(207BE976-1918-30EA-8F19-8557AEA48928),
version(1.0),
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITTransducer")
]

interface ITTransducer : IUnknown {
HRESULT _stdcall GetPID([in, out] ITPID** PID);

Quote:
};
};

To implement these interfaces I have added the following lines in the ATL
idl file

importlib("..\tlb\QXTypes.tlb");
:
:
 [
  uuid(7D8B8E67-A9A6-488D-81FD-38E98D4D3FED),
  helpstring("TNICard Class")
 ]
 coclass TNICard
 {
  [default] interface ITMachine;
  interface ITServoSystem;
 };
 [
  uuid(D40F95AB-0C52-4F6F-8B87-C20E08A05D73),
  helpstring("TNIServoChannel Class")
 ]
 coclass TNIServoChannel
 {
  [default] interface ITDriveElem;
  interface ITServoChannel;
 };
 [
   uuid(9C9CEF65-F6F3-4D57-9D61-99847347085B),
   helpstring("TNITransducer Class")
]
coclass TNITransducer
{
   [default] interface ITTransducerElem;
   interface ITTransducer;

Quote:
};

In each ATL class header file I have added the interface as follows for
example

class ATL_NO_VTABLE CTNICard :
 public CComObjectRootEx<CComMultiThreadModel>,
 public CComCoClass<CTNICard, &CLSID_TNICard>,
 public ITMachine,
   public ITServoSystem

And added the interface methods as follows for example

// -------------------------------------------------------------------------
-
  // Implementation of methods from interface: ITServoSystem
 STDMETHOD(GetServoChannel)(long Index, ITServoChannel * * pServoChannel);
 STDMETHOD(GetServoChannelCount)(long * Count);
 STDMETHOD(DownloadToHW)();

 STDMETHOD(SerialiseToDisk)(VARIANT * XMLobj);

I have then implemented these functions with simple MessageBoxes in the cpp
files.

I want to be able to access these ATL objects by their default interfaces
and well as the
interfaces I've just added.
For example in VB.net

HardwareMngr.GetMachine(iMachine, Machine) ' This returns a CTNICard object

' Check the object implements the ITMachine interface
If TypeOf Machine Is MACHINELib.ITMachine Then
    Windows.Forms.MessageBox.Show("MACHINELib.ITMachine found " & Serial)
End If
' Check the object implements the ITServoSystem interface
If TypeOf Machine Is QXTypes.ITServoSystem Then
    Windows.Forms.MessageBox.Show("ITServoSystem found " & Serial)
End If

' I want access to the methods through the ITServoSystem interface
Dim IServoSys As QXTypes.ITServoSystem = CType(Machine,
QXTypes.ITServoSystem)
Dim l As Integer
IServoSys.GetServoChannelCount(l)

What happens is that ITMachine interface is found but ITServoSystem not.
Can anyone tell me what I'm doing wrong!!
Many, many, many thanks in advance!!!!!!!!!!!!!!!!!



Tue, 31 May 2005 06:50:21 GMT  
 implementing interfaces from a type library
Ah, it's simpler than I thought :)... Your VB code is wrong.
You need to QI first for the other interface by assigning your
interface pointer to a variable of the other interface type.
My limited understanding of VB leads me to believe your
check does nothing - it checks if a variable is of a specific
type.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> I forgot to mention that I have to also add

> #import "..\tlb\QXTypes.tlb" raw_interfaces_only, raw_native_types,
> no_namespace, named_guids

> in the header file of the ATL class.
> If I dont have this then I get this error

> ctnicard.h(34) : error C2504: 'ITServoSystem' : base class undefined

> The COM interface map section contains the following

>   DECLARE_REGISTRY_RESOURCEID(IDR_TNICARD)

>   DECLARE_PROTECT_FINAL_CONSTRUCT()

>   BEGIN_COM_MAP(CTNICard)
>    COM_INTERFACE_ENTRY(ITMachine)
>    COM_INTERFACE_ENTRY(ITServoSystem)
>   END_COM_MAP()

> Everything compiles but when I run the VB.net app and try

> If TypeOf Machine Is QXTypes.ITServoSystem Then
>    MessageBox.Show("ITServoSystem found")
> End If

> It doesn't find the QXTypes.ITServoSystem interface.

> All I want is to be able to implement this interface which is in a tlb file
> and then call it from a VB.net app.

> PLEASE HELP !!!



> Check if you've listed both interfaces in the interface map.

> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD

> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================



> Hi,

> I want to implement a couple of interfaces defined in a type library.
> The type library is called QXTypes.tlb which has been created in Visual
> basic.NET.
> It consists of the following definitions.

> // Generated .IDL file (by the OLE/COM Object Viewer)
> //
> // typelib filename: <could not determine filename>
> [
> uuid(2FABA131-9DC3-4E35-88D6-3EC1A5841C9A),
> version(1.0)
> ]

> library QXTypes
> {
> // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
> importlib("stdole2.tlb");
> // Forward declare all types defined in this typelib
> interface ITServoSystem;
> interface ITServoChannel;
> interface ITTransducer;
> [
> odl,
> uuid(1849613A-6EB3-3A13-B76A-DEB730329C13),
> version(1.0),
> oleautomation,
> custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITServoSystem")
> ]

> interface ITServoSystem : IUnknown {
> HRESULT _stdcall GetServoChannel([in] long Index, [in, out] ITServoChannel**
> pServoChannel);
> HRESULT _stdcall GetServoChannelCount([in, out] long* Count);
> HRESULT _stdcall DownloadToHW();
> HRESULT _stdcall SerialiseToDisk([in, out] VARIANT* XMLobj);
> };
> [
> odl,
> uuid(8CA46DF9-832A-32AF-8997-CF87DFB35DE3),
> version(1.0),
> oleautomation,
> custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITServoChannel")
> ]

> interface ITServoChannel : IUnknown {
> HRESULT _stdcall GetTransducer([in] long Index, [in, out] ITTransducer**
> pTransducer);
> HRESULT _stdcall GetTransducerCount([in, out] long* Count);
> };

> [
> odl,
> uuid(207BE976-1918-30EA-8F19-8557AEA48928),
> version(1.0),
> oleautomation,
> custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "QXTypes.ITTransducer")
> ]

> interface ITTransducer : IUnknown {
> HRESULT _stdcall GetPID([in, out] ITPID** PID);
> };
> };

> To implement these interfaces I have added the following lines in the ATL
> idl file

> importlib("..\tlb\QXTypes.tlb");
> :
> :
>  [
>   uuid(7D8B8E67-A9A6-488D-81FD-38E98D4D3FED),
>   helpstring("TNICard Class")
>  ]
>  coclass TNICard
>  {
>   [default] interface ITMachine;
>   interface ITServoSystem;
>  };
>  [
>   uuid(D40F95AB-0C52-4F6F-8B87-C20E08A05D73),
>   helpstring("TNIServoChannel Class")
>  ]
>  coclass TNIServoChannel
>  {
>   [default] interface ITDriveElem;
>   interface ITServoChannel;
>  };
>  [
>    uuid(9C9CEF65-F6F3-4D57-9D61-99847347085B),
>    helpstring("TNITransducer Class")
> ]
> coclass TNITransducer
> {
>    [default] interface ITTransducerElem;
>    interface ITTransducer;
> };

> In each ATL class header file I have added the interface as follows for
> example

> class ATL_NO_VTABLE CTNICard :
>  public CComObjectRootEx<CComMultiThreadModel>,
>  public CComCoClass<CTNICard, &CLSID_TNICard>,
>  public ITMachine,
>    public ITServoSystem

> And added the interface methods as follows for example

> // -------------------------------------------------------------------------
> -
>   // Implementation of methods from interface: ITServoSystem
>  STDMETHOD(GetServoChannel)(long Index, ITServoChannel * * pServoChannel);
>  STDMETHOD(GetServoChannelCount)(long * Count);
>  STDMETHOD(DownloadToHW)();

>  STDMETHOD(SerialiseToDisk)(VARIANT * XMLobj);

> I have then implemented these functions with simple MessageBoxes in the cpp
> files.

> I want to be able to access these ATL objects by their default interfaces
> and well as the
> interfaces I've just added.
> For example in VB.net

> HardwareMngr.GetMachine(iMachine, Machine) ' This returns a CTNICard object

> ' Check the object implements the ITMachine interface
> If TypeOf Machine Is MACHINELib.ITMachine Then
>     Windows.Forms.MessageBox.Show("MACHINELib.ITMachine found " & Serial)
> End If
> ' Check the object implements the ITServoSystem interface
> If TypeOf Machine Is QXTypes.ITServoSystem Then
>     Windows.Forms.MessageBox.Show("ITServoSystem found " & Serial)
> End If

> ' I want access to the methods through the ITServoSystem interface
> Dim IServoSys As QXTypes.ITServoSystem = CType(Machine,
> QXTypes.ITServoSystem)
> Dim l As Integer
> IServoSys.GetServoChannelCount(l)

> What happens is that ITMachine interface is found but ITServoSystem not.
> Can anyone tell me what I'm doing wrong!!
> Many, many, many thanks in advance!!!!!!!!!!!!!!!!!



Wed, 01 Jun 2005 02:47:50 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Interface with Interface pointer from imported type library as argument

2. Implementing the Shell interfaces - wrong parameter types in stubs

3. Implementing IShellPropSheetExt without a type library

4. How to implement type library SERVER using VC++?

5. Injection of other interfaces into a type library.

6. Reusing type libraries for reimplementing Interfaces

7. Seeing an interface in a type library

8. Exposing DirectDraw interfaces in a type library

9. Exposing interfaces in a type library that are infact defined in another type library.

10. MessengerAPI type library - IDispatch enum type problem

11. HRESULT return type turns into void when adding class from type library

12. Bug? Implementing an Interface

 

 
Powered by phpBB® Forum Software