Pages

Tuesday, October 6, 2009

Вызвать Win32 API из C#

Просто MessageBox из MSDN:
using System;
using System.Runtime.InteropServices;

class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

static void Main()
{
// Call the MessageBox function using platform invoke.
MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
}
}

А можно MessageBeep:
[DllImport("User32.dll")]
static extern Boolean MessageBeep(UInt32 beepType);

А вот автоматический генератор: http://www.swig.org/
И статья по этому поводу: Calling Win32 DLLs in C# with P/Invoke

No comments:

Post a Comment