|
Creating a Custom Interface
Writing an application using a custom interface is similar to writing an OLE
application using standard interfaces, with two important differences. First, in
addition to registering the class identifier (CLSID) for your object, you also
must register the unique interface identifier (IID) for your custom interface.
Second, you must provide OLE with proxy and stub components capable of
remoting the interface. In most cases, you will use the MIDL compiler to generate code
to create the proxy/stub DLL for your custom interface.
As an OLE developer, you should already be familiar with the concept of using
CLSIDs and interface identifiers (IIDs) to uniquely identify class objects and
interfaces. The MIDL compiler refers to universally unique identifiers (UUIDs)
and uses UUIDs to uniquely represent its interfaces. In this case, a UUID is
the same as an IID. Every custom interface must have a IID; the UUIDGEN.EXE tool
provided with the toolkit can create one for you.
MIDL is a rich, complex language that allows you to define interface
parameters carefully in terms of their direction and type. Although the MIDL compiler
offers much, you will need only a small subset of its attributes to define your
interface.
The IDL file consists of two parts: the interface header and the interface
body. The interface header, delimited by brackets, contains information about the
interface as a whole, such as its IID. A prerequisite to completing the
interface header is running the RPC utility UUIDGEN.EXE to create the IID. Because
IIDs must be unique, never reuse one of them by copying it from one IDL file to
another. The header also contains the keyword object, indicating that this interface is a COM-style interface (that is, derived
from IUnknown). Whereas standard RPC interfaces have the version attribute in their
interface headers, object interfaces do not.
The following excerpt is from an actual IDL file:
[
object,
uuid(7ACC12C3-C4BB-101A-BB6E-0000C09A6549),
pointer_default(unique)
]
The uuid attribute precedes the unique identifier for the interface. The pointer_default attribute specifies the default IDL type for all pointers except for those
included in parameter lists. Parameter list pointers must be explicitly declared
with the pointer attribute. The default pointer type may either be unique, ref, or ptr. For more information on using IDL with pointers, see the RPC Programmer's Guide and Reference.
The interface body contains declarations for data members, prototypes for all
methods, and other information such as directives to the preprocessor and
include statements for other IDL files. The following example is the interface body
for ICustomInterface:
interface ICustomInterface : IUnknown
{
import "unknwn.idl";
HRESULT CustomReport(void);
}
The import attribute allows an interface to reference constructs defined in other IDL
files. Because ICustomInterface derives from IUnknown, the UNKNWN.IDL file must be included. ICustomInterface has only one method that takes no parameters; few interfaces will be this
simple.
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|