Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI I am using vc++2010, and i need exe the following code (but error in exe!!!):
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
void main ()
{
   int x;
one:      
   cout<<"if you want to turn on the light press 1 or 2"<<endl;
   cin>>x;
   
   if (x==1)
   {
       for(int i=0;i<100;i++)
       {
           _outp (0x0378,1);
           _sleep (1000);
           _outp (0x0378,2);
           _sleep (1000);
           _outp (0x0378,3);
           _sleep (1000);
           _outp (0x0378,4);
           _sleep (1000);
           _outp (0x0378,5);
           _sleep (1000);
           _outp (0x0378,6);
           _sleep (1000);
           _outp (0x0378,7);
           _sleep (1000);
           _outp (0x0378,8);
           _sleep (1000);
        }
   }
   else
      goto one;
}


i showed the following error when (i enter 1 in the consol exe) :
Unhandled exception at 0x0041154f in AA.exe: 0xC0000096: Privileged instruction.

why!!!!
Posted
Updated 2-Jun-12 0:45am
v3

The error message says it all - you're trying to execute a privileged instruction. In this case it's the instructions to read or write I/O ports. These are things that only kernel mode code can do to protect the system.

Some nice people on the interwebs have written device drivers which handle the processor exceptions caused by user mode programs and then actually do the reads and writes for you. These drivers are generally packaged as DLLs with the driver embedded as a resource. When the DLL loads it extracts the driver and installs it. So all you have to do is link your code with the packaging DLL, run your code as administrator and then there's a chance it might start working.

Here's[^] one driver/DLL package that might do what you want with some decent docs. I've never tested this one so I can't warrant it's use - the one I used several years ago has annoyingly disapeared from the interwebs.

Good luck!

PS: For anyone having trouble with the above link have a look here[^] instead.
 
Share this answer
 
v2
Comments
Member 9063138 3-Jun-12 7:08am    
SORRY LINK IS NOT OPEN?? WHY
Aescleal 3-Jun-12 14:58pm    
Sorry, can't comment on why it doesn't open for you, it does for me!

Have a look at the URL i've tacked on the end of the answer and see if that helps
hi the lab..are
XML
#include <iostream>
#include <stdlib.h>
#include <conio.h>

why the error i haved???
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900