C# calling a DLL API, in this case, MessageBox in user32.dll


/ Published in: C#
Save to your folder(s)

[1] Add 'using System.Runtime.InteropServices;'
[2] Add DllImport and function declaration
[3] call function.

This example involves passing strings and passing IntPtr.


Copy this code and paste it in your HTML
  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. class Example
  5. {
  6. // Use DllImport to import the Win32 MessageBox function.
  7. [DllImport("user32.dll", CharSet = CharSet.Unicode)]
  8. public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
  9.  
  10. static void Main()
  11. {
  12. // Call the MessageBox function using platform invoke.
  13. MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
  14. }
  15. }

URL: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.