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 (317217)



The information in this article applies to:

  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)

This article was previously published under Q317217

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:
#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.

back to the top

REFERENCES

For other top-hit Visual C++ .NET Microsoft Knowledge Base articles, visit the following Microsoft Web site: back to the top

Modification Type:MajorLast Reviewed:1/5/2006
Keywords:kbHOWTOmaster kbIDL KB317217 kbAudDeveloper