[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 711
  • Last Modified:

Console Manipulation without Windows.h

Is there any way, without including windows.h, to perform console furctions like SetCursorPosition, WriteCharString, WriteAttributes (color, blinking, etc) and Save what's on the screen to a memory buffer?

I'm taking some OS/2 C code and want to compile it on windows.  In OS/2 we used these Vio* calls (VioWrtCharStr) that don't exist on windows.  I'd like to not include the whole windows.h/platform SDK - I'd prefer to use something closer to ANSI C or maybe some other library.

Any ideas?
0
helpatudallshumwaycom
Asked:
helpatudallshumwaycom
  • 3
  • 2
4 Solutions
 
jkrCommented:
If you need a library for that, 'curses' usually is the one of choice and available for a variety of platforms. See http://pdcurses.sourceforge.net/ ("Public Domain Curses") which works on DOS, OS/2, Win32, X11 and SDL. If you are targetting only Windows, I'd rather go for native Win32 API calls, though.
0
 
helpatudallshumwaycomAuthor Commented:
Is there any way to limit the amount of the Win32 API calls to just the few console functions I need?  I originally turned away from importing Windows.h because of the magnutude of everything it brought with it.  There are some significant naming conflicts that I'd rather avoid.  I agree, it would be nice to just use the Win32 calls, I just don't know how to get *only* the handful of console functions that I want.

Specifically, I'm looking for replacements for the following:
VioWrtCharStr(char*,length,row,col,0) - writes a string
VioWrtNAttr(attribute,count,row,col,0) - writes a given attribute N times
VioSetCurPos(row,col,0) - sets the cursor position
VioWrtNChar(char, length,row,col,0) - Writes a single character N times
VioReadCellStr(start,length, row, col, 0) - Reads the current contents of the screen into a buffer
VioWrtCellStr(char*, length, row, col, 0) - Writes the contents of a buffer onto the screen
VioGetCurPos(row,col,0) - Gets the cursor position

How do I just get the Win32 functions necessary to replace those functions?
0
 
jkrCommented:
>>Is there any way to limit the amount of the Win32 API calls

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

removes most of the unnecessary stuff. If you really only need console APIS,

#include <wincon.h>

and linking with kernel32.lib should be enough.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
itsmeandnobodyelseCommented:
>>>> How do I just get the Win32 functions necessary to replace those functions?
Make your own header file where you 'declare' only the functions you need. You should avoid using windows types like UINT, DWORD, LPSTR, BOOL if doing so, but use the original C types (unsigned int, char*, int, ...) instead.

Regards, Alex
0
 
helpatudallshumwaycomAuthor Commented:
So, assuming I am able to just pull in parts of the platform SDK - what functions / libraries / ??? do I use?  Please forgive me, I'm totally and completely unfamiliar with using the Windows SDK - I've got no idea what the libraries are.  I've done some research on MSDN and it looks like SetConsoleCursorPosition() is one that will work for me, but I haven't been able to figure out how to get it to work. :(

I certainly appreciate the comments and suggestions that have been offered so far - I'll keep trying to figure out what it takes to appropriately implement them.
0
 
jkrCommented:
>>what functions / libraries / ??? do I use?

As above, 'wincon.h' and kernel32.lib (and the necessary C library headers that you might need. 'wincon.h' will reference other include files that you will need too, but that will be done transparently.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now