>1. Should it be simply just implement an interface on C# side with syntax
>like below?
[ComImport]
[Guid("xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
interface ITestInterface
{
[PreserveSig]
int GetTestLevel(out int level);
2. Do all methods in the original interface have to be implemented on C#
side?
You don't have to implement the interface if you're just consuming an
existing class that implements it.
>3. Should "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx" be the interface GUID or CoClass
ID of the COM object?
The IID if you're declaring an interface. The CLSID if you're
declaring a class.
>4. What do "[ComImport]" and "[PreserveSig]" mean?
ComImport means that the type is originally defined in the COM world.
As a result, the type is not exported and registered by Tlbexp/Regasm
for example.
PreserveSig means you're taking responsability to handle the HRESULT
return value from the method. If you remove the attribute (and change
the return type to void) the CLR will do that for you and convert
error HRESULTs to corresponding exceptions.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
Please reply only to the newsgroup.