使用_outp()时出现未处理的异常 [英] Unhandled exception when using _outp()
本文介绍了使用_outp()时出现未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用_outp(0x378,0xAA)在Windows 7中以C语言在计算机的并行端口中写入数据,它已编译,但在运行时给出了以下错误,
"Parallel_Port.exe中0x00d413c5处未处理的异常:0xC0000096:特权指令"
谁能建议我该怎么做.
谢谢&问候
Mohan
Hi,
I''m using _outp(0x378,0xAA) for writing data in the parallel port of the computer in C language in Windows 7, it gets compiled but it gives the below error at run time,
"Unhandled exception at 0x00d413c5 in Parallel_Port.exe: 0xC0000096: Privileged instruction"
Can anyone suggest me what I have to do.
Thanks & Regards
Mohan
推荐答案
Windows XP和2000不允许您直接写入硬件.您必须通过驱动程序执行此操作.
您可以做的是访问 http://www.beyondlogic.org [ 使用此程序,您可以直接写入硬件或使用Windows API来实现.
Windows XP and 2000 do not allow you to write directly to the hardware. You have to do this through drivers.
What you can do is visit http://www.beyondlogic.org[^] and download a program called "Port Talk".
Using this program, you can write directly to the hardware or use windows API for same.
Laxmikant_Yadav是正确的,现代Windows版本不允许您直接写入硬件.如果要在Windows 9x或MS-DOS计算机上运行程序,则不会出现冲突错误.
要使用Windows API写入并行端口,使其也适用于现代Windows版本,您可以编写如下内容:
Laxmikant_Yadav is right, modern Windows versions do not allow you to write directly to hardware. If you were to run your program on a Windows 9x or MS-DOS machine it wouldn''t give you a violation error.
To write to the parallel port using the Windows API, so it works with modern Windows versions as well, you could write something like this:
#include <windows.h>
#include <stdio.h>
void main(void)
{
HANDLE hPort = CreateFile("LPT1",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(hPort != INVALID_HANDLE_VALUE){
char buffer[5] = {''h'',''e'',''l'',''l'',''o''};
unsigned long count;
if(WriteFile(hPort, buffer, 5, &count, 0))
printf("Write succesful.\n");
else
printf("Write failed\n");
CloseHandle(hPort);
}
else
printf("Unable to access LPT1.");
}
这篇关于使用_outp()时出现未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文