Description



Description

The values of this enumeration are used to specify the calling conventions required to call unmanaged methods implemented in shared libraries.

[Note: Implementers should map the semantics of specified calling conventions onto the calling conventions of the host OS.]

[Note: For additional information on shared libraries and an example of the use of the CallingConvention enumeration, see the DllImportAttribute class overview.]

Example

using System;

using System.Runtime.InteropServices;



/// <summary>

/// Sample demonstrating the use of the CallingConvention enumeration.

/// Use this enumeration to specify the calling convention for methods 

/// decorated with DllImportAttribute.

/// </summary>

internal class CallingConventionSample

{



    private static void Main()

    {

        WritePunctuationResultForChar(',');

        WritePunctuationResultForChar('.');

        WritePunctuationResultForChar('!');

        WritePunctuationResultForChar('?');

        WritePunctuationResultForChar('a');

        WritePunctuationResultForChar('2');

        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("Press Enter to continue");

        Console.ReadLine();

    }



    private static void WritePunctuationResultForChar(char c)

    {



        // iswpunct returns non-zero if c is a recognized punctuation character.

        if (iswpunct(c) != 0)

        {

            Console.WriteLine("'{0}' is a punctuation character.", c);

        }

        else

        {

            Console.WriteLine("'{0}' is not a punctuation character.", c);

        }



    }



    // C runtime method to determine if a given character represents a 

    // punctuation character. This is used purely to demonstrate calling a 

    // cdecl method; .NET code should use char.IsPunctuation(char).

    [DllImport(

        "msvcrt.dll", 

         CallingConvention=CallingConvention.Cdecl, 

         CharSet=CharSet.Unicode)]

    private static extern int iswpunct(char c);



}




The output is


',' is a punctuation character.

'.' is a punctuation character.

'!' is a punctuation character.

'?' is a punctuation character.

'a' is not a punctuation character.

'2' is not a punctuation character.





Press Enter to continue