Microsoft KB Archive/317217

= 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 =

Article ID: 317217

Article Last Modified on 1/5/2006

-

APPLIES TO


 * Microsoft Visual C++ 2005 Express Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q317217



IN THIS TASK
SUMMARY
 * Use #import

REFERENCES



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.

back to the top

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: 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.
 * 1) import &quot;SERVER.DLL&quot; tlbid(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(&quot;SERVER.DLL\\2&quot;) API call.

back to the top

