The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Problem Running Example..
Discuss Problem Running Example.. in the C Programming forum on Dev Shed. Problem Running Example.. C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 11th, 2002, 11:11 PM
|
|
Contributing User
|
|
Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
Problem Running Example..
Hi,
I was over at pscode.com and ran across an example for Mouse Programming. I tried running the example but I was getting a bunch of errors such as..
c:\Documents and Settings\default\My Documents\Visual Studio Projects\mouse\mouse.cpp(33): error C2065: '_AX' : undeclared identifier
c:\Documents and Settings\default\My Documents\Visual Studio Projects\mouse\mouse.cpp(34): error C2065: 'geninterrupt' : undeclared identifier
c:\Documents and Settings\default\My Documents\Visual Studio Projects\mouse\mouse.cpp(58): error C2065: '_CX' : undeclared identifier
Here is the code for the example:
Code:
//The Compiler used is Turbo C, I dont know if it will compile in others also.
//Didn't Compile in Microsoft C Compiler. Make the respective change then.
//The function geninterrupt() generates interrupts, it is defined in dos.h
//_AX,_BX,_CX,_DX are defined in dos.h & correspond to ax,bx,cx,dx registers respectively.
//Make a header file out of this one and use it in your programs.
#include<dos.h>//this header file is necessary
#include<stdio.h>//only for displaying messages
#include<conio.h>//for other stuff like getch() etc.
unsigned initmouse()
{
_AX=0;
geninterrupt(0x33); //Generate Inpterrupt
return _AX;
}
void showmouse()
{
_AX=1;
geninterrupt(0x33);
}
void hidemouse()
{
_AX=2;
geninterrupt(0x33);
}
void restrictmouse(int x1,int y1,int x2,int y2)
{
_AX=7;
_CX=x1;
_DX=x2;
geninterrupt(0x33);
_AX=8;
_CX=y1;
_DX=y2;
geninterrupt(0x33);
}
void getmouse(int *button,int *x,int *y)
{
_AX=3;
geninterrupt(0x33);
*button=_BX;
*x=_CX;
*y=_DX;
}
void setmouse(int x,int y)
{
_AX=4;
_CX=x;
_DX=y;
geninterrupt(0x33);
}
void main()
{
int x,y,button;
clrscr();
gotoxy(29,18);
textbackground(GREEN);
cprintf("EXIT");
gotoxy(1,1);
if(initmouse()==0)
{
printf("Mouse support unavailable");
return;
}
printf("\n\nPress any key to Show Mouse");
getch();
showmouse();
printf("\nPress any key to Hide Mouse");
getch();
hidemouse();
printf("\nPress any key to Show Mouse again");
getch();
restrictmouse(208,80,416,160);
showmouse();
printf("\nMouse has been restricted");
printf("\nPress on Exit button to quit the Program");
while(1)
{
getmouse(&button,&x,&y);
gotoxy(35,1);
printf("Coordinates:-(%d,%d) ",x,y);
gotoxy(35,2);
if(button&1)//<- Here '&' means ANDing, remember bitwise operators of C/C++
printf("Left button pressed ");
else if(button&2)
printf("Right button pressed ");
else if(button&4)
printf("Center button pressed");
else
printf("No button Pressed ");
if(x>=224&&x<=248&&y==136&&button==1)//checks if exit button is pressed or not
break;
}
}
As you can see in the comments, it says "_AX,_BX,_CX,_DX are defined in dos.h & correspond to ax,bx,cx,dx registers respectively." dos.h is included in this example, so does anyone know why I am getting these errors?
Thanks.
-0pt!x
|

November 12th, 2002, 03:09 AM
|
|
Offensive Member
|
|
Join Date: Oct 2002
Location: in the perfect world
|
|
|
You could always OPEN dos.h and SEE if they are defined. (highlight the text 'dos.h' RIGHT click and select 'open document "dos.h" ' from the pop-up menu in MS Visual Studio (i know it is in from ver 5)
And then find they are not in dos.h.
"//The Compiler used is Turbo C, I dont know if it will compile in others also.
//Didn't Compile in Microsoft C Compiler."
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.
Frank Zappa
|

November 12th, 2002, 08:59 AM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
Even though dos.h was included with the code, I don't think you are calling that file that.
by using: #include<dos.h>
you are including the dos.h file from your compiler's include path. If you want to use a different dos.h file then the one that is in the include path, then give the complete path to it. i.e.
#include "drive:/path/to/dos.h"
|

November 12th, 2002, 07:47 PM
|
|
Contributing User
|
|
Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
Well I want to use the dos.h that came with my compiler. I looked in the header and it didnt define the _AX and stuff.. But ..  I am confused because it says that it is sposed to be defined in my dos.h. Is my dos.h screwed up or something?
|

November 12th, 2002, 07:52 PM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
quite possible.
|

November 12th, 2002, 09:03 PM
|
|
Offensive Member
|
|
Join Date: Oct 2002
Location: in the perfect world
|
|
|
>>Is my dos.h screwed up or something?
No. It is a just a difference between compliers.
as the code stated and I pointed out
"//The Compiler used is Turbo C, I dont know if it will compile in others also.
//Didn't Compile in Microsoft C Compiler."
Is that not clear enough for you?
You are obviously using a Microsoft Compiler, a version of MSVC
"c:\Documents and Settings\default\My Documents\Visual Studio Projects\"
What did you want to do with the mouse?
|

November 12th, 2002, 10:10 PM
|
|
Contributing User
|
|
Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
I know i was using a diff compiler but shouldnt the header files be the same?
>>What did you want to do with the mouse?
I wanted to make a prog that would click the mouse every 1 second untill i closed my prog. Like..
int main()
{
while(1)
{
click;
sleep(1000);
}
}
somethin like that.
|

November 13th, 2002, 02:20 AM
|
|
Offensive Member
|
|
Join Date: Oct 2002
Location: in the perfect world
|
|
|
>>I know i was using a diff compiler but shouldnt the header files be the same?
No.
A good coder comments his work and its limitations. This coder did, bad coders ignore instructions and commented code.
In the comments the coder TOLD you it would not compile in MSVC, he could not have been plainer. You have MSVC.
Did you not READ that line or did you not UNDERSTAND that line? (the bold one above)
If in doubt RTFM!
Ahhh
Some app that pretends you are still there surfing away.
If they had any sense when they wrote it they will have locked out external use of SendMessage() like functions.
If you can't read simple code comments then a WIN32 API app that sends mouse click messages to another application is most definately beyond the scope of your abilites.
You most probably need to send mouse messages thru windows to the other app as you will not know the client co-ordinates that the ckick happens at. That is WHERE the mouse is clicked ( in the other apps client coodinates).
Try a search for mouse_event(), which has been superceded by SendInput () ect. See what it turns up.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|