【发布时间】:2013-10-27 08:43:21
【问题描述】:
我发现了很多关于它的问题,但没有人解释我如何使用它。
我有这个:
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;
}
}
谁能帮我理解为什么它在DllImport 行和public static 行上给我一个错误?
有没有人有想法,我该怎么办? 谢谢。
【问题讨论】:
-
除了@vcsjones 提到的内容之外,还有多个问题。你有使用这个的 User32.dll 吗?并且还要检查你写 [DllImport] 语句的地方。它是错误的地方。
-
@PM。 User32.dll 是一个非常标准的 Win32 DLL,它总是在 SysWow64 或 System32 中,所以找到它应该没有问题。如果有另一个同名的 DLL 在搜索序列中“更接近”,它可能会找到错误,但这会给大多数程序带来灾难。
-
@vcsjones 哦,好吧,我的错。我不知道。