Why does DllImport not work for me?

All methods marked with the DllImport attribute must be marked as public static extern.

  
Showing Answers 1 - 7 of 7 Answers

Timothy Marin

  • Sep 22nd, 2005
 

be sure to referance System.Runtime.InteropServices;

Following is the example to use it properly This is from msdn for more visit
http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx


using
System;
using System.Runtime.InteropServices;

class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll", CharSet = CharSet.Auto)]
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);
}
}

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions