How to use [DllImport(“”)] in C#?

后端 未结 1 850
囚心锁ツ
囚心锁ツ 2020-12-01 01:41

I found a lot of questions about it, but no one explains how I can use this.

I have this:

using System;
using System.Collections.Generic;
using Syste         


        
1条回答
  •  生来不讨喜
    2020-12-01 02:26

    You can't declare an extern local method inside of a method, or any other method with an attribute. Move your DLL import into the class:

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

    0 讨论(0)
提交回复
热议问题