Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 17th, 2006, 7:42 AM   #1
rup
Newbie
 
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0 rup is on a distinguished road
Manipulating the console using Windows API

I was trying to code a 7-segment display clock at the console. It's a console app in VC++ which uses the Windows API to manipulate the console.

These are three functions,

Init_Graphics
Set_Color
Clear_Screen

which uses API calls to to manipulate the console.

I wrote another three functions to do simple output to stdout using cout, they are:
seg_ver
seg_hor
draw_display

When I build the prog (one cpp file with standard headers included) I get this error:

error LNK2019: unresolved external symbol "void __cdecl draw_display(char * const,int)" (?draw_display@@YAXQADH@Z) referenced in function _main
fatal error LNK1120: 1 unresolved externals

I can't figure out what is wrong with my draw_display function. Please help.

Here's the code, if someone wishes to take a look:

//A console clock.

#include<iostream>
#include<ctime>
#include<windows.h>
using namespace std;

int display_mask[10][7]= { {1,1,1,0,1,1,1},
				     {0,0,1,0,0,1,0},
				     {1,0,1,1,1,0,1},
				     {1,0,1,1,0,1,1},
				     {0,1,1,1,0,1,0},
				     {1,1,0,1,0,1,1},
				     {1,1,0,1,1,1,1},
				     {1,0,1,0,0,1,0},
				     {1,1,1,1,1,1,1},
				     {1,1,1,1,0,1,1}
				  };	
#define SCROLL_POS   24  // the point that scrolling occurs
CONSOLE_SCREEN_BUFFER_INFO con_info;   // holds screen info
HANDLE hconsole;			           // handle to console


void seg_hor(int size, int state);
void seg_ver(int state);
void draw_display(char number[7], int size);

void Init_Graphics(void);
inline void Set_Color(int fcolor, int bcolor);
inline void Clear_Screen(void);

int main()
{
	Init_Graphics();
	
	while(1)
	{
		Clear_Screen();

        char *time_str, time_digits[7];
		
		time_t t;
		time(&t);
		time_str = ctime(&t);
	
		time_digits[0]=time_str[11];
		time_digits[1]=time_str[12];
		time_digits[2]=time_str[14];
		time_digits[3]=time_str[15];
		time_digits[4]=time_str[17];
		time_digits[5]=time_str[18];
		time_digits[6]=0;

		draw_display(time_digits, 3);

		Sleep(40);
	}

	return 0;
}

void seg_hor(int size, int state)
{
	for(int i=0; i<size; i++)
	{
		if(state==0)
			cout<<" ";
		else
			cout<<"-";
	}
}

void seg_ver(int state)
{
	if(state==0)
		cout<<" ";
	else
		cout<<"|";
}

void draw_display(char number[7], unsigned int size)
{
		//7seg draw_display maps to 2*size + 3 rows in the console
		for(unsigned int i=0; i<(2*size+3); i++)
		{
			for(unsigned int j=0; j<=6; j++)
			{
				if(i==0)
				{
					//draw seg0
					cout<<" ";
					seg_hor(size,display_mask[number[j]-'0'][0]);
					cout<<" ";
				}
				if(i>0 && i<(size+1))
				{
					//draw seg1 and seg2
					seg_ver(display_mask[number[j]-'0'][1]);
					for(unsigned int k=0; k<(size);k++)
						cout<<" ";
					seg_ver(display_mask[number[j]-'0'][2]);
					
				}
				if(i==(size+1))
				{
					//draw seg3
					cout<<" ";
					seg_hor(size,display_mask[number[j]-'0'][3]);
					cout<<" ";
				}
				if(i>(size+1) && i<(2*size+2))
				{
					//draw seg4 and seg5
					seg_ver(display_mask[number[j]-'0'][4]);
					for(unsigned int k=0; k<(size);k++)
						cout<<" ";
					seg_ver(display_mask[number[j]-'0'][5]);
				}
				if(i==(2*size+2))
				{
					//draw seg6
					cout<<" ";
					seg_hor(size,display_mask[number[j]-'0'][6]);
					cout<<" ";
				}
				//space out the hr, min and sec displays
				if(j==1 || j==3)
					cout<<"     ";
			}
			cout<<endl;
		}
}

void Init_Graphics(void)
{
	COORD console_size = {80,25}; // size of console

	srand((unsigned)time(NULL));

	// open i/o channel to console screen
	hconsole=CreateFile("CONOUT$",GENERIC_WRITE | GENERIC_READ,
         FILE_SHARE_READ | FILE_SHARE_WRITE,
         0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);

	// make sure we are in 80x25
	SetConsoleScreenBufferSize(hconsole,console_size);

	// get details for console screen                       
	GetConsoleScreenBufferInfo(hconsole,&con_info);
}

inline void Set_Color(int fcolor, int bcolor=0) 
{
	// this function sets the color of the console output
	SetConsoleTextAttribute(hconsole,(WORD)((bcolor << 4) | 
		                    fcolor));
}

inline void Clear_Screen(void)
{
	// set color to white on black
	Set_Color(15,0);

	// clear the screen
	for (int index=0; index<=25; index++)
	{
		COORD cursor_pos;
		cursor_pos.X = 0;
		cursor_pos.Y = SCROLL_POS;
		SetConsoleCursorPosition(hconsole,cursor_pos);
		cout<<endl;
	}
}
rup is offline   Reply With Quote
Old Nov 17th, 2006, 8:44 AM   #2
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 266
Rep Power: 4 Cache is on a distinguished road
The signature of the prototype is different from the definition.

void draw_display(char number[7], int size);  // Prototype sig.
//...
void draw_display(char number[7], unsigned int size)  // Definition sig.
Cache is offline   Reply With Quote
Old Nov 17th, 2006, 2:04 PM   #3
rup
Newbie
 
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0 rup is on a distinguished road
Thanks. And I'm sorry for being so irresponsible.
rup is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Prompt SkyPioneer Coder's Corner Lounge 5 May 3rd, 2006 11:07 PM
The Black Art of Video Game Console Design lostcauz Book Reviews 0 Apr 26th, 2006 8:31 PM
Console windows jayme C++ 20 Apr 25th, 2006 8:34 AM
Net Group /ADD (on a windows box, non domain controller) Infinite Recursion Other Programming Languages 1 Apr 13th, 2005 3:27 PM
How Do I: Rewrite a Delphi 6 console app to run as a DLL for IIS5 daemonreaver Delphi 0 Mar 9th, 2005 3:05 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:31 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC