Revision: 16237
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 29, 2009 14:25 by jimfred
Initial Code
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); } }
Initial URL
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx
Initial Description
[1] Add 'using System.Runtime.InteropServices;' [2] Add DllImport and function declaration [3] call function. This example involves passing strings and passing IntPtr.
Initial Title
C# calling a DLL API, in this case, MessageBox in user32.dll
Initial Tags
Initial Language
C#