Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

IDL For VB Tutorial

The Interface Definition Language, or IDL, is a language for describing collections of data types, constants, methods (functions, procedures, etc.), and groups of methods known as interfaces. VB creates type information for you automatically when you create ActiveX components, but you can also create independent type information using IDL and the Microsoft IDL compiler. Using IDL in this way can enhance your programming skills and allow you to solve some pretty complex problems. The best way to get an understanding of how to write IDL, compile it to a type library, and use the type library in VB is see some real examples in a tutorial format, as this article demonstrates.


advertisement


The Interface Definition Language, or IDL, is a language for describing collections of data types, constants, methods (functions, procedures, etc.), and groups of methods known as interfaces. This is not all IDL can describe, but its what were primarily concerned with. When you use VBs object browser to look at classes, functions, and types native to VB, or those provided by some other component, you are looking at what is commonly called type information. VB creates type information for you automatically when you create ActiveX components, but you can also create independent type information using IDL and the Microsoft IDL compiler. Using IDL in this way can enhance your programming skills and allow you to solve some pretty complex problems. The best way to get an understanding of how to write IDL, compile it to a type library, and use the type library in VB is see some real examples in a tutorial format. I believe this will give you a better understanding of this technique. To that end, I have written this article with a strong emphasis on good, meaningful, examples.

The first three examples are designed to give you needed background information. The fourth example walks you through a solution to a real problem that can be solved very effectively using this technique. Throughout the examples, I include references to articles and books that will provide you with important background information.



Requirements

To get the most out of this article, not to mention your software development efforts, you need Microsoft Visual Studio Professional. This article is based on version 6.0, but 5.0 will work fine. Here are the programs you will use if try the examples in this article:

  • VB6.EXE Visual Basic
  • MSDEV.EXE Visual C++
  • OLEVIEW.EXE OLE View Tool
  • GUIDGEN.EXE GUID Generation Tool
  • MIDL.EXE Microsoft IDL Compiler

Dont worry, you will not be using MSDEV.EXE to write C++. I think of it as a great tool that also does C++. In addition to these programs, you will probably use the MSDN Library CD to look up references included in this article. If you want to go through the first three examples a little more quickly, I have packed up the sample code into the following zip file: Misc.Zip .

Example 1: Looking Under the Hood of VB Components

Type information is the single most important element in component development, and VB hides almost every technical detail about it from the programmer. This example is designed to get you under the hood with respect to VB generated type libraries.

Example 2: Compiling and Registering a Type Library

In subsequent examples you will need to be able to compile type libraries and reference them from VB projects. In this example you will compile an IDL file using the Microsoft IDL compiler and register the resulting type library file with Windows, thereby allowing you to reference the type library in VB just like an ActiveX component.

Example 3: IDL to VB

This example will begin to show you how to write IDL by showing the effects of an IDL generated type library in VB. You will see which IDL data types translate to VB data types and which IDL method declarations translate to VB method declarations.

Example 4: IDL for a Reason

The previous examples may help you understand how to write IDL and create, register, and reference the resulting compiled type libraries, but they dont give you a reason to care. This example is designed to provide a problem and an IDL/type library solution that will show you the power of this technique.

IDL vs. ODL

Microsofts first incarnation of a type description language was ODL (Object Description Language) which you could compile using MKTYPLIB.EXE. According to MSDN articles, the differences between IDL and ODL are minor. The primary areas of difference are:

  • The syntax of typedef statements
  • Boolean data types
  • The scope of symbols used in enums
  • Support for certain base types

If you want to know more about ODL vs. IDL, the following MSDN topic should provide you more than enough information:

  • MSDN Library(+)Platform SDK(+)COM and ActiveX Object Services(+)MIDL(+)Using The MIDL Compiler(+)Generating a Type Library With MIDL


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap