javascript
Brief description  about Online courses   join in Online courses
View Amritha  Saran 's Profile

Can I use the Win32 API from a .NET Framework program?

Can I use the Win32 API from a .NET Framework program?
Asked by Amritha Saran | Aug 30, 2010 |  Reply now
Replies (1)
View dotnet teacher 's Profile
Can I use the Win32 API from a .NET Framework program?

Yes. Using platform invoke, .NET Framework programs can access native code libraries by means of static DLL entry points.

Here is an example of C# calling the Win32 MessageBox function:
Copy

using System;
using System.Runtime.InteropServices;

class MainApp
{
[DllImport("user32.dll", EntryPoint="MessageBox")]
public static extern int MessageBox(int hWnd, String strMessage, String strCaption, uint uiType);

public static void Main()
{
MessageBox( 0, "Hello, this is PInvoke in operation!", ".NET", 0 );
}
}

Aug 30, 2010