View Full Version : Why won't VC++ 6.0 compile this?:
GabrielBlumenthal
11-28-2002, 01:02 PM
Here's the .h file:
char getAdapter();
int getMode(int *ncols);
void gotoxy(int column,int row);
Here's the .c file:
#include "otherheaderfile.h"
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
void cls(char colors)
{
#include <dos.h>
union REGS reg;
char ch;
int columns,mode;
mode = getMode(&columns);
if (columns == 80)
{
if ((mode == 0x11) || (mode == 0x12))
reg.x.dx = 0x1D4F;
else
reg.x.dx = 0x184F;
reg.h.bh = colors;
}
else
{
reg.x.dx = 0x1828;
switch (colors)
{
case 1: reg.h.bh = 0x55;
break;
case 2: reg.h.bh = 0xAA;
break;
case 3: reg.h.bh = 0xFF;
break;
default:
reg.h.bh = 0;
break;
}
}
reg.x.ax = 0x0600;
reg.x.cx = 0;
int86(0x10,®,®);
gotoxy(0,0);
}
int getMode(int *ncols)
{
#include <dos.h>
union REGS reg;
reg.h.ah = 0x0F;
int86(0x10,®,®)
*ncols = reg.h.ah;
return reg.h.al;
}
void gotoxy(int column,int row)
{
#include <dos.h>
union REGS reg;
reg.h.ah = 2;
reg.h.bh = 0;
reg.h.dh = row;
reg.h.dl = column;
int86(0x10,®,®);
}
It keeps saying "error C2224: left of '.h' must have struct/union type".
It also gave me this error: "error C2079: 'reg' uses undefined union 'REGS'"
I thought that that REGS was defined in dos.h which I included.
Pommy
11-28-2002, 01:35 PM
Apparently not, since it seems right now reg is being initiated as an int instead of a union because of the invalid REGS, which in turn produces the left of '.h' must have struct/union type error.
GabrielBlumenthal
11-28-2002, 01:46 PM
So how can I fix that? http://forums.massassi.net/html/confused.gif
Gamma_Ray54
11-28-2002, 06:08 PM
My suspicion is that it's complaining because you're putting an #include inside a function declaration. Try just putting the #include <dos.h> line up at the top with the others.
------------------
"I realized the moment I fell into the fissure that the book would not be destroyed as I'd planned.
It continued falling into that starry expanse of which I had only a fleeting glimpse.
I've tried to speculate, where it might have landed, although I must admit such conjecture is futile. Still, the question about whose hands might one day hold my Myst book are unsettling to me.
I know my apprehensions might never be allayed, and so I close, realizing that perhaps, the ending has not yet been written."
Yeah, you can't put includes inside function declarations.
------------------
"A wizard is never late, Frodo Baggins. Nor is he early. He arrives pricisely when he means to!" --Gandalf
Gamma_Ray54
11-29-2002, 01:07 PM
Well, technically, you CAN....but most include files have things in them that can't be put inside function declarations, so basically you can't.
GabrielBlumenthal
11-29-2002, 03:16 PM
I took them out and put the include at the beginning and it made no difference.
Any ideas? http://forums.massassi.net/html/confused.gif
[This message has been edited by GabrielBlumenthal (edited November 29, 2002).]
Are you sure that when you declare your reg variable that you don't have to use the keyword union? From the looks of it, REGS seems to be some form of struct or union.
Looking over your error messages, it says that reg is using some undefined union. Try just "REGS reg;" instead of "union REGS reg;"
------------------
"A wizard is never late, Frodo Baggins. Nor is he early. He arrives pricisely when he means to!" --Gandalf
Pommy
11-29-2002, 07:54 PM
Hrm, yeah, Gandalf may be right.
[This message has been edited by Pommy (edited November 29, 2002).]
GabrielBlumenthal
11-30-2002, 03:52 PM
I changed it to this:
REGS reg;
But it didn't make a difference. I thought that in C if you had a structure (or union) and wanting to declare a variable of that type, that you had put a struct (or union) in front of it. I know for a fact though, that in C++, if you declare a class, you don't have to code it like this (I think it might create an error message, actually):
class some_class {//blah blah};
class some_class a_class;
You can do this;
class some_class {//blah blah};
some_class a_class;
I don't know if VC++ is treats .c files like a .cpp file though.
Any ideas? http://forums.massassi.net/html/confused.gif
[This message has been edited by GabrielBlumenthal (edited November 30, 2002).]
Ok, I tested your code in Visual Studio .NET and I got the same errors. I came to this conclusion. REGS is undefined because you're not including the right headers. I tried "struct REGS reg" and it still failed. It looks like you're trying to write some assembly code. You can use the __asm { } call to include straight assembly in your C program.
I think I can find an assembler clear screen routine in my CS 231 book somewhere. If that's what you desire.
------------------
"A wizard is never late, Frodo Baggins. Nor is he early. He arrives pricisely when he means to!" --Gandalf
GabrielBlumenthal
11-30-2002, 08:49 PM
Ok, if I use the __asm{} thingy, then how would I modify the code?
[This message has been edited by GabrielBlumenthal (edited November 30, 2002).]
Well you gotta know 8086 assembler first
Like.
mov ax,mode
cmp 0011h
jz mode_is_11
mov dx,0184Fh
mov bh,colors
I'm pretty sure that's 15% correct. All ready my CS 231 material is slipping from my mind :P
------------------
"A wizard is never late, Frodo Baggins. Nor is he early. He arrives pricisely when he means to!" --Gandalf
GabrielBlumenthal
12-01-2002, 08:45 AM
Ok, but how exactly would I modify the functions so they would work. Sorry, but I only know a little bit of assembly. The functions are part of a Console Graphics Library I'm making, with the assistance of a book.
Wel... Does anyone know how to modify the code (the whole entire thing) to compile and work with the __asm{} thingy?
http://forums.massassi.net/html/confused.gif
[This message has been edited by GabrielBlumenthal (edited December 01, 2002).]
[This message has been edited by GabrielBlumenthal (edited December 01, 2002).]
GabrielBlumenthal
12-02-2002, 04:34 PM
*bump*
Gamma_Ray54
12-03-2002, 02:49 AM
Ok, I'm pretty sure this is what's going on. Microsoft, in their infinite wisdom, is making yet another stab at killing DOS by crippling 90% of dos.h, including both the REGS union and the int() calls. So you're going to have to do this with _asm calls.
This is going to end up looking sort of ugly. What you need to do is, everywhere in your source file that there's a "regs.something.* = blah;" construction, you need to replace it with "_asm mov *,blah" where * and blah are the same as the above line. So "regs.h.bh=0x55;" turns to "_asm mov bh,0x55" There's no semicolon at the end of these lines. Then, everywhere you've got an "int86(blah,®,®);", change it to "_asm int blah". So "int86(0x10,®,®);" becomes "_asm int 0x10". Hopefully, that should make it work.
------------------
"I realized the moment I fell into the fissure that the book would not be destroyed as I'd planned.
It continued falling into that starry expanse of which I had only a fleeting glimpse.
I've tried to speculate, where it might have landed, although I must admit such conjecture is futile. Still, the question about whose hands might one day hold my Myst book are unsettling to me.
I know my apprehensions might never be allayed, and so I close, realizing that perhaps, the ending has not yet been written."
GabrielBlumenthal
12-03-2002, 02:03 PM
Gamma_Ray54: I just tried compiling this with another C Compiler, ( http://www.hitech.com.au/products/pacific.html ) but it wouldn't work, are you sure it just another one of MS's campaigns to eradicate DOS?
GabrielBlumenthal
12-03-2002, 02:37 PM
Ok well, I tried recompiling it, and I got the error count down from 29 (I think) to fifteen. How else should I modify the following code?:
#include "otherheaderfile.h"
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int getMode(int *ncols)
{
union REGS reg;
__asm {mov ah,0x0F}
__asm {int 0x10}
*ncols = reg.h.ah;
return reg.h.al};
}
void gotoxy(int column,int row)
{
{
union REGS reg;
__asm {mov ah,2}
__asm {mov bh,0}
__asm {mov dh,row}
__asm {mov dl,column}
__asm {int 0x10}
}
void cls(char colors)
{
union REGS reg;
char ch;
int columns,mode;
mode = getMode(&columns);
if (columns == 80)
{
if ((mode == 0x11) || (mode == 0x12))
__asm {mov dx,0x1D4F}
else
__asm {mov dx,0x184F}
__asm {mov bh,colors}
}
else
{
reg.x.dx = 0x1828;
switch (colors)
{
case 1: __asm {mov bh,0x55}
break;
case 2: __asm {mov bh,0xAA}
break;
case 3: __asm {mov bh,0xFF}
break;
default:
__asm {mov bh,0}
break;
}
}
__asm {mov ax,0x0600}
__asm {mov cx,0}
__asm {int 0x10}
gotoxy(0,0);
}
The .h file is unchanged, and here are the errors:
C:\Code\gLib\Gtools.c(12) : error C2079: 'reg' uses undefined union 'REGS'
C:\Code\gLib\Gtools.c(16) : error C2224: left of '.h' must have struct/union type
C:\Code\gLib\Gtools.c(17) : error C2224: left of '.h' must have struct/union type
C:\Code\gLib\Gtools.c(17) : warning C4033: 'getMode' must return a value
C:\Code\gLib\Gtools.c(23) : error C2079: 'reg' uses undefined union 'REGS'
C:\Code\gLib\Gtools.c(27) : error C2443: operand size conflict
C:\Code\gLib\Gtools.c(28) : error C2443: operand size conflict
C:\Code\gLib\Gtools.c(32) : error C2143: syntax error : missing ';' before 'type'
C:\Code\gLib\Gtools.c(36) : error C2143: syntax error : missing ';' before 'type'
C:\Code\gLib\Gtools.c(37) : error C2143: syntax error : missing ';' before 'type'
C:\Code\gLib\Gtools.c(39) : error C2065: 'mode' : undeclared identifier
C:\Code\gLib\Gtools.c(39) : error C2065: 'columns' : undeclared identifier
C:\Code\gLib\Gtools.c(46) : error C2443: operand size conflict
C:\Code\gLib\Gtools.c(50) : error C2065: 'reg' : undeclared identifier
C:\Code\gLib\Gtools.c(50) : error C2224: left of '.x' must have struct/union type
C:\Code\gLib\Gtools.c(51) : error C2065: 'colors' : undeclared identifier
Error executing cl.exe.
Gtools.obj - 15 error(s), 1 warning(s)
Gamma_Ray54
12-03-2002, 10:31 PM
Here's my next stab at it--see what it gives you.
#include "otherheaderfile.h"
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int getMode(int *ncols)
{
unsigned char ret;
__asm {mov ah,0x0F}
__asm {int 0x10}
__asm { mov ret,ah };
*ncols=ret;
__asm { mov ret,al}
return ret;
}
void gotoxy(unsigned char column,unsigned char row)
{
__asm {mov ah,2}
__asm {mov bh,0}
__asm {mov dh,row}
__asm {mov dl,column}
__asm {int 0x10}
}
void cls(char colors)
{
char ch;
int columns,mode;
mode = getMode(&columns);
if (columns == 80)
{
if ((mode == 0x11) || (mode == 0x12)) __asm {mov dx,0x1D4F}
else __asm {mov dx,0x184F}
__asm {mov bh,colors}
}
else
{
__asm {mov dx,0x1828}
switch (colors)
{
case 1: __asm {mov bh,0x55}
break;
case 2: __asm {mov bh,0xAA}
break;
case 3: __asm {mov bh,0xFF}
break;
default:__asm {mov bh,0}
break;
}
}
__asm {mov ax,0x0600}
__asm {mov cx,0}
__asm {int 0x10}
gotoxy(0,0);
}
Hopefully that will have at least a few less errors. Basically all I did was get rid of a couple extra curly braces, changed some variable types around to avoid operator type mismatches, converted a couple more lines to assembly, and got rid of the union REGS declarations (which you don't need anymore). See if this works in some way, shape or form. http://forums.massassi.net/html/smile.gif
------------------
"I realized the moment I fell into the fissure that the book would not be destroyed as I'd planned.
It continued falling into that starry expanse of which I had only a fleeting glimpse.
I've tried to speculate, where it might have landed, although I must admit such conjecture is futile. Still, the question about whose hands might one day hold my Myst book are unsettling to me.
I know my apprehensions might never be allayed, and so I close, realizing that perhaps, the ending has not yet been written."
[This message has been edited by Gamma_Ray54 (edited December 03, 2002).]
I managed to dig up my CS 231 book (8086 assembler) and jogged my mind a bit. I did some mods to your prog. Methinks you should write this entirely in assembler. Here's the code
#include "otherheaderfile.h"
#include <dos.h>
int getNumCols()
{
unsigned nCols;
__asm
{
mov ah,0Fh
int 10h
mov nCols,al
}
return nCols;
}
int getMode()
{
unsigned nMode;
__asm
{
mov ah,0Fh
int 10h
mov nCols,bh
}
return nMode;
}
void gotoxy(unsigned column,unsigned row)
{
__asm
{
mov ah,02h
mov bh,0
mov dh,row
mov dl,column
int 10h
}
}
void cls(char colors)
{
char ch;
int columns,mode;
mode = getMode();
columns = getNumCols();
if (columns == 80)
{
if ((mode == 0x11) || (mode == 0x12))
__asm {mov dx,0x1D4F};
else
__asm {mov dx,0x184F};
__asm {mov bh,colors};
}
else
{
__asm {mov dx,0x1828};
switch (colors)
{
case 1: __asm {mov bh,0x55}
break;
case 2: __asm {mov bh,0xAA}
break;
case 3: __asm {mov bh,0xFF}
break;
default:__asm {mov bh,0}
break;
}
}
__asm
{
mov ax,0x0600
mov cx,0
int 10h
}
gotoxy(0,0);
}
I haven't tested it yet.
------------------
"A wizard is never late, Frodo Baggins. Nor is he early. He arrives pricisely when he means to!" --Gandalf
Gamma_Ray54
12-04-2002, 12:17 PM
Gandalf--I may be wrong, but it looks like you've got different registers in the get*() functions than Gabriel had in his original code. Are you sure those are right? Also you're using nCols in the getMode() function instead of nMode. But other than that the implementation looks cleaner than mine, so Gabriel, I'd say go with his.
Those registers are correct. I had my assembler book with me when I coded that. As for the nMode/nCols thing.. Well, when you're doing assembler @ 1 am you overlook some stuff http://forums.massassi.net/html/tongue.gif
------------------
"A wizard is never late, Frodo Baggins. Nor is he early. He arrives pricisely when he means to!" --Gandalf
GabrielBlumenthal
12-05-2002, 05:10 PM
Why did you make a new function called getNumCols? Also, what were the errors Gamma_Ray54 pointed out and how should they be fixed?
Argath
12-07-2002, 06:51 PM
FYI, 32-bit Windows console programs are text only. You'll need a 16-bit compiler to create a DOS program if you want to use DOS graphics functions.
As far as I know, Visual C++ can't compile DOS programs, but I could be mistaken.
No, I don't think VC can compile 16-bit DOS programs. You'll have to get a simpler compiler. I think Borland does 16-bit. Is there a GCC/G++ for DOS?
------------------
"A wizard is never late, Frodo Baggins. Nor is he early. He arrives pricisely when he means to!" --Gandalf
Gamma_Ray54
12-08-2002, 12:14 AM
*slaps forehead in disgust* Argath, I guess I should have thought of that a while ago. Thanks for calling me on my idiocy.
Anyway, DJGPP is a freeware DOS-based compiler. I know it's primarily focused around 32-bit applications, but it might also be able to do the old 16-bit stuff. You could certainly check it out at www.delorie.com/djgpp. (http://www.delorie.com/djgpp.) It might be able to do what you're looking for.
------------------
"I realized the moment I fell into the fissure that the book would not be destroyed as I'd planned.
It continued falling into that starry expanse of which I had only a fleeting glimpse.
I've tried to speculate, where it might have landed, although I must admit such conjecture is futile. Still, the question about whose hands might one day hold my Myst book are unsettling to me.
I know my apprehensions might never be allayed, and so I close, realizing that perhaps, the ending has not yet been written."
Ashkashal
05-14-2004, 09:08 PM
I believe I may have an answer which will save you MUCH time. Go download Open Watcom 1.2 (completey free). 1)Start a new project, make the project and make the following selections from the dialog; Target environment="DOS - 16-bit", Image Type="Executable [.exe]". Right-click in your new project & "New Source" (pixel.c in my case), add your c file and close. Goto "Actions" and "Make all". If you get no errors, it worked.
I have been trying to do DOS graphics in MSVC++ for about a year to no AVAIL!, and I realized perhaps I should use an older compiler designed for DOS(watcom has a winows IDE and will compile buku executable types). I hope this works for you too, I was reading over this helpful posting when I gave watcom a try, its terrific.
If a pro here can try this out and verify my findings I am sure it would be a great help to many people. http://forums.massassi.net/html/biggrin.gif Tonight I sleep happy.
Last post made before thread necromancy was: 1 year 5 months 7 days. Wow.
------------------
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Pommy
05-15-2004, 06:03 PM
Holy CRAP, I actually posted on this thread .. a loooooong time ago ..
------------------
Sigs are for n00bs.
[1337 FRNDS_Pommy (http://forums.massassi.net/cgi-bin/ubbmisc.cgi?action=getbio&UserName=FRNDS_Pommy) | 3.14 of 14 | » And-GTx2 (http://andgtx2.el3ctro.co.uk)]
Half-Life 2 Central (http://www.hl2central.net) - your definitive source for everything HL2!
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.