Article ID: 317217 - Last Review: January 5, 2006 - Revision: 2.0

How to use the #import directive to target a specific type library resource ID from a file in Visual C++ .NET or in Visual C++ 2005

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q317217

On This Page

Expand all | Collapse all

SUMMARY

This step-by-step article describes how you can use the #import directive to target a specific type library resource ID from a single .dll file or from a single .exe file. By default, the type library is extracted from the first resource of type TypeLib. You can use the tlbid(n) attribute with the #import directive, where n is the resource ID of the type library that you want to use.

Using #import

If multiple type libraries are built into a single .dll file or a single .exe file, you can use the #import directive to target a specific type library resource. For example, to target the type library resource 2, use the following tlbid switch:
#import "SERVER.DLL" tlbid(2)
				
This statement loads the type library resource 2 from the file Server.dll, and then constructs header files that incorporate information from that type library resource 2.

By default, the type library is extracted from the first resource of type TypeLib, if the tlbid directive is missing.

When you use this tlbid switch, you get the same results that you get when you use the LoadTypeLib("SERVER.DLL\\2") API call.

REFERENCES

For other top-hit Visual C++ .NET Microsoft Knowledge Base articles, visit the following Microsoft Web site:
Visual C++ .NET (2002) Support Center
http://support.microsoft.com/default.aspx?xmlid=fh%3BEN-US%3Bvcnet (http://support.microsoft.com/default.aspx?xmlid=fh%3ben-us%3bvcnet)

APPLIES TO
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
Keywords: 
kbhowtomaster kbidl KB317217