다음을 통해 공유


Imported Library Conversion

When the import process converts a type library, it automatically places the types defined within the library in a namespace of the same name as the type library. For example, if you run Tlbimp.exe on the following type library, the utility imports all types defined within the AcmeLib type library into the AcmeLib namespace.

Type library representation

library AcmeLib {
    interface Widget {};
    coclass Slingshot {};
};

After the conversion, you can use AcmeLib.Slingshot to call the Slingshot class from your managed application.

Namespace AcmeLib
    Interface Widget
    End Interface
   
    Class Slingshot
    End Class
End Namespace
[C#]
namespace AcmeLib {
    interface Widget {};
    class Slingshot {};
};

You can use a type library attribute to explicitly control the namespace for the type library import process. Because type library names cannot contain periods, this is the only technique that you can use to import types into a period-delimited namespace. This attribute identifier is 0F21F359-AB84-41e8-9A78-36D110E6D2F9. The following type library representation shows the addition of the user-defined attribute.

Type library representation

[
    uuid(...),
    version(1.0),
    custom(0F21F359-AB84-41e8-9A78-36D110E6D2F9, "Acme.WidgetLib")
]
library AcmeLib {
    interface Widget {};
    coclass Slingshot {};
};

By using the user-defined attribute, you can force Tlbimp.exe to import the AcmeLib type library into the Acme.WidgetLib namespace. The Slingshot class becomes Acme.WidgetLib.Slingshot in managed code.

See Also

Type Library to Assembly Conversion Summary | Imported Module Conversion | Imported Type Conversion | Imported Member Conversion | Imported Parameter Conversion