Converting C++ Console Program

  • Thread starter Thread starter Jerry chapman
  • Start date Start date
J

Jerry chapman

Several years ago I wrote a console program in Visual C++, which I am still
using. In converting this program to C#, I have encountered the following
problems:

1. I build my console display in a back ground buffer and use the function
"SetConsoleActiveScreenBuffer(hForegroundBuffer)" to switch the console
display to the new buffer. I couldn't find a corresponding function in C#.

2. I use the function "SetConsoleCursorPosition(hForegroundBuffer,pos)" to
set the position of the cursor. Again, I couldn't find a corresponding
function in C#.

3. I display some lines of data in red and some in black, and use the
function "SetConsoleTextAttribute()" to accomplish that. Again, I couldn't
find a corresponding function in C#.

Perhaps the book I am using (Programming C#, by Jesse Liberty) is just
incomplete. If that is true, where can I find a more complete list of
functions available in C#?
 
Jerry,

There is not a one to one mapping between the windows API and .NET.
..NET is lacking on the console support. However, all of the functions from
the windows API that you mentioned can be accessed through the P/Invoke
layer. If you need help in declaring these functions in C#, just post which
ones you need help with, and I or someone else would be more than happy to
help.

Hope this helps.
 
Jerry chapman wrote:

[Missing functions in System.Console]

The System.Console class isn't "finished", one could say. It has only
the most important functions like Read, ReadLine, Write, WriteLine and
so on. All other console functions have to done via PInvoke.
Perhaps the book I am using (Programming C#, by Jesse Liberty) is just
incomplete. If that is true, where can I find a more complete list of
functions available in C#?

First: No, your book doesn't seem to be incomplete. Second: These are
_not_ functions of C# but the .net Framework.

May be

http://www.csharphelp.com/archives2/archive354.html

is a good point to start for you, as you're experienced in API programming.

HTH,

Michael
 
Back
Top