Dimi Dimi - 2 months ago 22
C# Question

Move P/Invokes to NativeMethods class Because it is a P/Invoke method message

Can someone suggest what do I have to do with this message?


CA1060 Move P/Invokes to NativeMethods class Because it is a P/Invoke
method, 'UControl.InternetGetConnectedState(out int, int)' should be
defined in a class named NativeMethods, SafeNativeMethods, or
UnsafeNativeMethods. Mega. UControl.xaml.cs 33


Code:

namespace Mega
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UControl
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int description, int reservedValue);


THANK YOU!

Answer

Oh!

I found an answer

https://msdn.microsoft.com/library/ms182161.aspx

using System;
using System.Runtime.InteropServices;

    namespace DesignLibrary
    {
    // Violates rule: MovePInvokesToNativeMethodsClass.
        internal class UnmanagedApi
        {
            [DllImport("kernel32.dll")]
            internal static extern bool RemoveDirectory(string name);
        }
    }