15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

704 ❘ ChaPTer 26 interOp<br />

With custom attributes, it is possible to change the name of the class <strong>and</strong> interfaces that<br />

are generated by a .<strong>NET</strong> wrapper class. You just have to add the attribute custom with<br />

the identifi er 0F21F359 - AB84 – 41e8 – 9A78 – 36D110E6D2F9, <strong>and</strong> the name under which<br />

it should appear within .<strong>NET</strong>.<br />

Add the custom attribute with the same identifi er <strong>and</strong> the name Wrox.ProCSharp.Interop.Server<br />

.IWelcome to the header section of the IWelcome interface. Add the same attribute with a corresponding<br />

name to the coclass COMDemo :<br />

[<br />

object,<br />

uuid(EB1E5898-4DAB-4184-92E2-BBD8F9341AFD),<br />

dual,<br />

nonextensible,<br />

helpstring("IWelcome Interface"),<br />

pointer_default(unique),<br />

custom( 0F21F359-AB84-41e8-9A78-36D110E6D2F9 ,<br />

"Wrox.ProCSharp.Interop.Server.IWelcome")<br />

]<br />

interface IWelcome : IDispatch{<br />

[id(1)] HRESULT Greeting([in] BSTR name, [out,retval] BSTR* message);<br />

};<br />

[<br />

uuid(8C123EAE-F567-421F-ACBE-E11F89909160),<br />

version(1.0),<br />

]<br />

library COMServerLib<br />

{<br />

importlib("stdole2.tlb");<br />

[<br />

uuid(ACB04E72-EB08-4D4A-91D3-34A5DB55D4B4),<br />

helpstring("COMDemo Class"),<br />

custom( 0F21F359-AB84-41e8-9A78-36D110E6D2F9 ,<br />

"Wrox.ProCSharp.Interop.Server.COMDemo")<br />

]<br />

coclass COMDemo<br />

{<br />

[default] interface IWelcome;<br />

};<br />

};<br />

Now add a second interface to the fi le COMServer.idl . You can copy the header section of the IWelcome<br />

interface to the header section of the new IMath interface, but be sure to change the unique identifi er that is<br />

defi ned with the uuid keyword. You can generate such an ID with the guidgen utility. The interface IMath<br />

offers the methods Add() <strong>and</strong> Sub() :<br />

// IMath<br />

[<br />

object,<br />

uuid(2158751B-896E-461d-9012-EF1680BE0628),<br />

dual,<br />

nonextensible,<br />

helpstring("IMath Interface"),<br />

pointer_default(unique),<br />

custom(0F21F359-AB84-41e8-9A78-36D110E6D2F9,<br />

"Wrox.ProCSharp.Interop.Server.IMath")<br />

]<br />

interface IMath: IDispatch<br />

{<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!