Jak używać [DllImport („”)] w C #?

Znalazłem wiele pytań na ten temat, ale nikt nie wyjaśnia, jak mogę to wykorzystać.

Mam to:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.FSharp.Linq.RuntimeHelpers;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;

public class WindowHandling
{
    public void ActivateTargetApplication(string processName, List<string> barcodesList)
    {
        [DllImport("User32.dll")]
        public static extern int SetForegroundWindow(IntPtr point);
        Process p = Process.Start("notepad++.exe");
        p.WaitForInputIdle();
        IntPtr h = p.MainWindowHandle;
        SetForegroundWindow(h);
        SendKeys.SendWait("k");
        IntPtr processFoundWindow = p.MainWindowHandle;
    }
}

Czy ktoś może mi pomóc zrozumieć, dlaczego powoduje to błądDllImport linia i napublic static linia?

Czy ktoś ma pomysł, co mogę zrobić? Dziękuję Ci.

questionAnswers(1)

yourAnswerToTheQuestion