473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

CreateConsolScreenBuffer

Really have problems when converting "CreateConsolScreenBuffer" to C#. Can
anyone give me an example for the function ?

typedef struct _SECURITY_ATTRIBUTES
{ DWORD nLength;
LPVOID lpSecurityDescriptor; // not sure abt this part
BOOL bInheritHandle;
}
transfer to the following -----> is that correct ?
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public bool bInheritHandle;

--------------------------------------------------------------------------------------------
//The CreateConsoleScreenBuffer function creates a console screen buffer.
HANDLE CreateConsoleScreenBuffer
(
DWORD dwDesiredAccess,
DWORD dwShareMode,
const SECURITY_ATTRIBUTES* lpSecurityAttributes,
DWORD dwFlags,
LPVOID lpScreenBufferData
);
transfer to the following -----> is that correct ?
[DllImport("Kernel32.dll")]
private static extern int CreateConsoleScreenBuffer(int dwDesiredAccess, int
dwShareMode, SECURITY_ATTRIBUTES obj, int dwFlags, object lpScreenBufferData)
-------------------------------------------------------------------------------------
//the statement execution.
int hNewScreenBuffer = CreateConsoleScreenBuffer(
GENERIC_READ | // read/write access
GENERIC_WRITE,
0, // not shared
NULL, // no security attributes
CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE
NULL); // reserved; must be NULL
Nov 16 '05 #1
2 2572
> [StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public bool bInheritHandle;
}
explicit size with SizeConst=? would be more safe. try
sizeof(SECURITY_ATTRIBUTES) to find out exact size.
[DllImport("Kernel32.dll")]
private static extern int CreateConsoleScreenBuffer(int dwDesiredAccess, int dwShareMode, SECURITY_ATTRIBUTES obj, int dwFlags, object

lpScreenBufferData);

You must pass SECURITY_ATTRIBUTES as ref or out to make it work. The
lpScreenBufferData should be of type byte[] I think.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Nov 16 '05 #2
See my reply to your previous post.

Willy.

"Maverick" <Ma******@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
Really have problems when converting "CreateConsolScreenBuffer" to C#. Can
anyone give me an example for the function ?

typedef struct _SECURITY_ATTRIBUTES
{ DWORD nLength;
LPVOID lpSecurityDescriptor; // not sure abt this part
BOOL bInheritHandle;
}
transfer to the following -----> is that correct ?
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public IntPtr lpSecurityDescriptor;
public bool bInheritHandle;
}
--------------------------------------------------------------------------------------------
//The CreateConsoleScreenBuffer function creates a console screen buffer.
HANDLE CreateConsoleScreenBuffer
(
DWORD dwDesiredAccess,
DWORD dwShareMode,
const SECURITY_ATTRIBUTES* lpSecurityAttributes,
DWORD dwFlags,
LPVOID lpScreenBufferData
);
transfer to the following -----> is that correct ?
[DllImport("Kernel32.dll")]
private static extern int CreateConsoleScreenBuffer(int dwDesiredAccess,
int
dwShareMode, SECURITY_ATTRIBUTES obj, int dwFlags, object
lpScreenBufferData);
-------------------------------------------------------------------------------------
//the statement execution.
int hNewScreenBuffer = CreateConsoleScreenBuffer(
GENERIC_READ | // read/write access
GENERIC_WRITE,
0, // not shared
NULL, // no security attributes
CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE
NULL); // reserved; must be NULL

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.