Wie verwende ich [DllImport (“”)] in C #?

Ich habe viele Fragen dazu gefunden, aber niemand erklärt, wie ich das nutzen kann.

Ich habe das:

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;
    }
}

Kann mir jemand helfen zu verstehen, warum es mir einen Fehler auf der gibtDllImport Linie und auf derpublic static Linie?

Hat jemand eine Idee, was kann ich tun? Vielen Dank.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage