Description



Description

[Note: In C#, an entry point is defined through the Main() method. For additional information about entry points, see Partition II of the CLI Specification.]

Example

using System;

using System.Runtime.InteropServices;



/// <summary>

/// Shows why a EntryPointNotFoundException is thrown

/// and how to handle it

/// </summary>



public class EntryPointNotFoundExceptionSample

{

    // This wrapper causes an exception to be thrown. EntryPoint, CharSet, and 

    // ExactSpelling fields are mismatched.

    [DllImport( "User32.dll", EntryPoint="MessageBox", 

         CharSet=CharSet.Ansi, ExactSpelling=true )]

    public static extern int MsgBox3( int hWnd, String text, 

        String caption, uint type );



    public static void Main()

    {

        try

        {

            MsgBox3( 0, "No such function", "MsgBox Sample", 0 );

        }

        catch (EntryPointNotFoundException e)

        {

            Console.WriteLine("Caught exception: {0} - '{1}'", e.GetType().Name,

                e.Message);

        }

        Console.WriteLine();

        Console.WriteLine();

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

        Console.ReadLine();

    }

}


The output is


Caught exception: EntryPointNotFoundException - 'Unable to find an entry point n

amed MessageBox in DLL User32.dll.'





Press Enter to continue