What do lines like [COMImport] do?

S

SM

I found a COM interop code sample and came across these lines of code:

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]

What do those type of lines encapsuled in [] brackets do? I already tried
to find an answer using web search but no success. :(

Thanks for any help.
 
D

Dmitriy Lapshin [C# / .NET MVP]

These are so called attributes. They usually emit metadata about a class, a
class member or an assembly which is then used by the JIT compiler, CLR or
even in other parts of the program. In your particular example, the
attributes instruct the runtime to forward calls to the class they apply to
to a COM object with the specified GUID and interface type.

P.S. You should consult MSDN on topics such as ComImportAttribute,
GuidAttribute and InterfaceTypeAttribute to find out their *exact* meaning
as my response is rather generic.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

SM said:
I found a COM interop code sample and came across these lines of code:

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]

What do those type of lines encapsuled in [] brackets do? I already tried
to find an answer using web search but no success. :(

Thanks for any help.
adress.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top