To create the interface with COM attributes

In this section, you create an interface and configure it with COM attributes.

  1. Delete the default class (Class1).

  2. In Solution Explorer, right-click the project name that is in bold type, point to Add, and then click Class.

  3. In the Name field, enter "IExchangeUfl", and then click Add.

  4. Change the class signature from class to interface, and set the scope to public.

> [!NOTE]
> <P>In Visual Basic, remember to change both the opening and closing signature. In C#, delete the constructor.</P>


``` vb
Public Interface IExchangeUfl
End Interface
```

``` csharp
public interface IExchangeUfl
{
}
```
  1. Above the class declaration, add the following using/Imports statement:

    Imports System.Runtime.InteropServices
    
    using System.Runtime.InteropServices;
    
  2. From the Tools menu, click Create GUID.

  3. In the Create GUID dialog box, in the GUID format panel, select Registry Format.

  4. Click New GUID.

  5. Click Copy, and then close the dialog box.

  6. Above the interface declaration, create an attribute with three values: ComVisible, InterfaceType, and Guid (in C#) or GuidAttribute (in Visual Basic) with parameter string quotes.

> [!NOTE]
> <P>In Visual Basic, for readability add an underscore after the close tag to place the class on the next line.</P>


``` vb
<ComVisible(), InterfaceType(), GuidAttribute("")> _
Public Interface IExchangeUfl
End Interface
```

``` csharp
[ComVisible(), InterfaceType(), Guid("")]
public interface IExchangeUfl
{
}
```
  1. Enter a parameter value of "True" [Visual Basic] or "true" [C#] into the ComVisible attribute.

  2. Enter a parameter value of ComInterfaceType.InterfaceIsDual from the ComInterfaceType enum into the InterfaceType attribute.

  3. Paste the GUID value from the clipboard into the parameter value of the Guid attribute. Be careful to remove the curly braces and any carriage returns.

> [!NOTE]
> <P>Do not use the GUID provided in the code snippet below. Create a unique GUID for your interface.</P>


``` vb
<ComVisible(True),
InterfaceType(ComInterfaceType.InterfaceIsDual),
GuidAttribute("E7A4EC98-BF2B-4006-B266-74C74421C394")> _
Public Interface IExchangeUfl
End Interface
```

``` csharp
[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual),
Guid("E7A4EC98-BF2B-4006-B266-74C74421C394")]
public interface IExchangeUfl
{
}
```
  1. Within the IExchangeUfl interface, create a method signature.
> [!NOTE]
> <P>This method signature will become the name of the function that is exposed in the embedded Crystal Reports Designer.</P>


``` vb
Function ConvertUSDollarsToCDN(ByVal usd As Double) As Double
```

``` csharp
double ConvertUSDollarsToCDN(double usd);
```
  1. Close the interface window.

Next you create the implementation class.