Converting C++ Console Program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry chapman

    #1

    Converting C++ Console Program

    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
    "SetConsoleActi veScreenBuffer( hForegroundBuff er)" to switch the console
    display to the new buffer. I couldn't find a corresponding function in C#.

    2. I use the function "SetConsoleCurs orPosition(hFor egroundBuffer,p os)" 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 "SetConsoleText Attribute()" 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#?


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Converting C++ Console Program

    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.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nick(dot)paldin o=at=exisconsul ting<dot>com

    "Jerry chapman" <jerryc314@worl dnet.att.net> wrote in message
    news:6JCbb.1544 82$3o3.10997988 @bgtnsc05-news.ops.worldn et.att.net...[color=blue]
    > Several years ago I wrote a console program in Visual C++, which I am[/color]
    still[color=blue]
    > 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[/color]
    function[color=blue]
    > "SetConsoleActi veScreenBuffer( hForegroundBuff er)" to switch the console
    > display to the new buffer. I couldn't find a corresponding function in C#.
    >
    > 2. I use the function "SetConsoleCurs orPosition(hFor egroundBuffer,p os)"[/color]
    to[color=blue]
    > 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 "SetConsoleText Attribute()" 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#?
    >
    >[/color]


    Comment

    • Michael Kremser

      #3
      Re: Converting C++ Console Program

      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.
      [color=blue]
      > 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#?[/color]

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

      May be



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

      HTH,

      Michael

      --
      Michael Kremser


      Comment

      Working...