P
Pretorian
Пытаюсь в приложении получить хендл консоли с помощью GetStdHandle, на XP все удачно, на Server 2003 приложение пишет ошибку. Кто сталкивался с этим и как это лечится, помоему где то стоит какой то запрет на выполнение GetStdHandle.
Код:
using System;
using System.Runtime.InteropServices;
class Screen
{
[DllImport(”kernel32.dll”)]
static extern bool SetConsoleTextAttribute(int hConsoleOutput, ushort wAttributes);
[DllImport(”kernel32.dll”)]
static extern int GetStdHandle(uint nStdHandle);
const uint STD_OUTPUT_HANDLE = 0x0FFFFFFF5;
static Screen()
{
output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
m_attributes = 7;
}
public static void PrintString(string str)
{
Console.Write(str);
}
public static ushort Attributes
{
get
{
return m_attributes;
}
set
{
m_attributes = value;
SetConsoleTextAttribute(output_handle, value);
}
}
private static ushort m_attributes;
private static int output_handle;
}
class Example_4
{
public static void Main()
{
for (ushort i = 1; i < 8; i++)
{
Screen.Attributes = i;
Screen.PrintString(”Property Demo\n”);
}
}
}