Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在64位中禁用QuickEditMode_C#_.net_Windows_64 Bit_32bit 64bit - Fatal编程技术网

C# 在64位中禁用QuickEditMode

C# 在64位中禁用QuickEditMode,c#,.net,windows,64-bit,32bit-64bit,C#,.net,Windows,64 Bit,32bit 64bit,我目前在旧的32位体系结构窗口中使用以下代码: [DllImport("kernel32.dll", EntryPoint = "SetConsoleMode", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode)] public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode); [DllImpor

我目前在旧的32位体系结构窗口中使用以下代码:

    [DllImport("kernel32.dll", EntryPoint = "SetConsoleMode", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode)]
    public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
    [DllImport("kernel32.dll", EntryPoint = "GetConsoleMode", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode)]
    public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
    [DllImport("user32.dll")]
    public static extern bool EnableMenuItem(IntPtr hConsoleHandle, uint uIDEnableItem, uint uEnable);
    [DllImport("user32.dll")]
    public static extern IntPtr GetSystemMenu(IntPtr hSystemMenu, bool bRevert);
    [DllImport("user32.dll")]
    public static extern IntPtr RemoveMenu(IntPtr hSystemMenu, uint nPosition, uint wFlags);
这是使用GetConsoleMode和SetConsoleMode的代码:

if (!GetConsoleMode(consoleHandle, out consoleMode))
                throw new IOException("Console setup error - failed to retrieve current ConsoleMode");
consoleMode &= ~Constants.ENABLE_QUICK_EDIT_MODE;
Constants.SetConsoleMode(consoleHandle, consoleMode)
我知道,尝试让应用程序在64位计算机中运行,但我遇到以下错误:

Type: System.IO.IOException
Message: Console setup error - failed to retrieve current ConsoleMode

我在谷歌上搜索并检查了64位windows上的dll是否也被命名为kernel32.dll。。这里我缺少什么?

我不确定假设控制台句柄始终具有0x3值是否是一个好主意,特别是因为有一个Windows API方法来检索标准句柄

在以32位和64位可执行文件(在64位Windows上)运行时,以下内容对我来说似乎很有用,.NET在内部是这样做的:

[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetStdHandle(int nStdHandle);

var consoleHandle = GetStdHandle(-10); // STD_INPUT_HANDLE
GetConsoleMode(consoleHandle, out var mode);

你能在调用
GetConsoleMode
的地方显示代码吗?@Iridium当然,我在原始帖子中添加了代码,请看一看,你在哪里可以得到
consoleHandle
?@Iridium IntPtr consoleHandle=new IntPtr(3);谢谢你,这对我有用。。还有一个问题:我还有一个IntPtr invalidHandle=newintptr(-1);。。我还应该使用GetStdHandle函数。仍然存在int值-1吗?合理地确定Windows将-1定义为无效句柄,因此可以保持原样
GetStdHandle
仅用于检索输入/输出/错误句柄。