Page #48 (Organizing Multiple IDL Files)

< BACK  NEXT >
[oR]

Putting It All Together

It is time for us to convert our C++ interfaces defined in the previous chapter into IDL interfaces. We will define two interfaces, IVideo and ISVideo, create a library section, and define a COM class for our VCR.

Step 1: Create a file, video.idl, using notepad or your favorite editor.

Step 2: Access information from SDK-defined IDL files, as follows:

 import "oaidl.idl";  import "ocidl.idl"; 

Step 3: Define interface block for Ivideo, as follows:

 [ ]  interface IVideo : IUnknown  { }; 

Step 4: Add interface attributes. The required ones are object and uuid. However, it is good practice to add helpstring and pointer_default as well.

 [   object,    uuid(318B4AD0-06A7-11d3-9B58-0080C8E11F14),    helpstring("IVideo Interface"),    pointer_default(unique)  ] 

You will have to run guidgen.exe to obtain the GUID for the interface.

graphics/01icon02.gif

If you use guidgen.exe to obtain a GUID, leave it running until you obtain all the GUIDs. This way, all the GUIDs used in a project will have contiguous values, and it makes it easy to identify them.

However, you will need to run guidgen.exe on NT4. On Windows 2000, the algorithm used to generate GUIDs is different; it no longer generates contiguous GUIDs.


Step 5: Add the interface methods.

The following class shows our final C++ interface that appeared at the end of the previous chapter:

 class IVideo : public IGeneral  { public:    virtual VRESULT _stdcall GetSignalValue(long* pRetVal) = 0;  }; 

The following is the equivalent IDL interface representation:

 interface IVideo : IUnknown  {   HRESULT GetSignalValue([out] long* val);  }; 

Step 6: Add method attributes.

I am adding just one attribute helpstring as follows:

 interface IVideo : IUnknown  {   [helpstring("Obtain the signal value")]    HRESULT GetSignalValue([out] long* val);  }; 

Step 7: Repeat steps 3 through 6 for interface ISVideo. Following is the final definition of interface ISVideo.

 [   object,    uuid(318B4AD1-06A7-11d3-9B58-0080C8E11F14),    helpstring("ISVideo Interface"),    pointer_default(unique)  ]  interface ISVideo : IUnknown  {   [helpstring("Obtain the S-Video signal value")]    HRESULT GetSVideoSignalValue([out, retval] long* val);  }; 

Step 8: Define the library block, as follows:

 [ ]  library VcrLib  { }; 

Step 9: Add library attributes. The required attribute is uuid. However, it is a good idea to also add the version number and helpstring.

 [   uuid(318B4AD2-06A7-11d3-9B58-0080C8E11F14),    version(1.0),    helpstring("VCR Type Library")  ] 

Step 10: Add importlib statements for SDK type libraries, as follows:

 library VcrLib  {   importlib("stdole32.tlb");    importlib("stdole2.tlb");  }; 

Step 11: Add coclass block within the library scope, as follows:

 [ ]  coclass VCR  { }; 

Step 12: Define coclass attributes. The required attribute is uuid. However, adding helpstring as well is a good idea.

 uuid(318B4AD3-06A7-11d3-9B58-0080C8E11F14),  helpstring("VCR Class") 

Step 13: List the interfaces we plan to expose in the coclass scope, as follows:

 interface IVideo;  interface ISVideo; 

We are done. Following is the IDL file we just created in its entirety.

 // File Video.idl  import "oaidl.idl";  import "ocidl.idl";  [   object,    uuid(318B4AD0-06A7-11d3-9B58-0080C8E11F14),    helpstring("IVideo Interface"),    pointer_default(unique)  ]  interface IVideo : IUnknown  {   [helpstring("Obtain the signal value")]    HRESULT GetSignalValue([out, retval] long* val);  };  [   object,    uuid(318B4AD1-06A7-11d3-9B58-0080C8E11F14),    helpstring("ISVideo Interface"),    pointer_default(unique)  ]  interface ISVideo : IUnknown  {   [helpstring("Obtain the S-Video signal value")]    HRESULT GetSVideoSignalValue([out, retval] long* val);  };  [   uuid(318B4AD2-06A7-11d3-9B58-0080C8E11F14),    version(1.0),    helpstring("VCR Type Library")  ]  library VcrLib  {   importlib("stdole32.tlb");    importlib("stdole2.tlb");    [     uuid(318B4AD3-06A7-11d3-9B58-0080C8E11F14),      helpstring("VCR Class")    ]    coclass VCR    {     interface IVideo;      interface ISVideo;    };  }; 

< BACK  NEXT >


COM+ Programming. A Practical Guide Using Visual C++ and ATL
COM+ Programming. A Practical Guide Using Visual C++ and ATL
ISBN: 130886742
EAN: N/A
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net