static class Class
{
public static void methodRequiringStuffFromKernel32()
{
// code here...
}
}
Where do I put [DllImport("Kernel32.dll")]
here?
static class Class
{
public static void methodRequiringStuffFromKernel32()
{
// code here...
}
}
Where do I put [DllImport("Kernel32.dll")]
here?
It goes on the method itself that's P/Invoking outside methods. Make sure to add a reference to
System.Runtime.InteropServices
This is an example of
DllImport
:I suggest you to study Platform Invoke Tutorial.
You put it on the method you're importing from Kernel32.dll.
For example,
From @dtb: Note that the class should be named
NativeMethods
,SafeNativeMethods
orUnsafeNativeMethods
. See Naming Convention for Unmanaged Code Methods for more details.CA1060: Move P/Invokes to NativeMethods class: