VC ++ 2010使用LPT的输出 [英] OUTPUT USING LPT BY VC++2010

查看:99
本文介绍了VC ++ 2010使用LPT的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI 我正在使用vc ++ 2010,并且我需要exe以下代码(但exe错误!!!):

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;
}



我在consol exe中输入1时显示以下错误:
AA.exe中0x0041154f的未处理异常:0xC0000096:特权指令.

为什么!!!!



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

why!!!!

推荐答案

错误消息说明了一切-您正在尝试执行特权指令.在这种情况下,它是读取或写入I/O端口的说明.这些是只有内核模式代码才能保护系统的事情.

互连网上的一些好人编写了设备驱动程序,用于处理由用户模式程序引起的处理器异常,然后实际为您执行读写操作.这些驱动程序通常打包为DLL,并且将驱动程序嵌入为资源.加载DLL时,它将解压缩驱动程序并进行安装.因此,您要做的就是将代码链接到打包的DLL,以管理员身份运行代码,然后有可能开始工作.

在这里 [此处查看 [
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.


嗨 实验室..
hi the lab..are
#include <iostream>
#include <stdlib.h>
#include <conio.h>


为什么我要犯错误?


why the error i haved???


这篇关于VC ++ 2010使用LPT的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆