Privileged instruction in C

丶灬走出姿态 提交于 2020-01-15 10:21:02

问题


I'm having some problems with C. I am trying to program a parallel port in Windows 7 Professional x64 in VS 2010 Ultimate. Since I do not have a parallel port, I'm using a converter from USB->Parallel and Windows installed the drivers correctly. I've soldered 8 LED-s on the end of the parallel connector and they are all working fine when I connect the USB into the computer. Now, I would like to control the parallel port via my program written in C which is:

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <Windows.h>
/********************************************/
/*This program set the parallel port outputs*/
/********************************************/

void main (void)
{
//clrscr();            /* clear screen */
_outp(0x378,0xff); /* output the data to parallel port */
getch();              /* wait for keypress before exiting */
}

The program gets compiled and runs but I get an error message:

Unhandled exception at 0x00f313a5 in portovi.exe: 0xC0000096: Privileged instruction.

I have read that port IO is disabled in windows NT machines and that you need a specific driver to do it. Is there any solution to it?


回答1:


There are ways around this. See here for instance.




回答2:


Your USB->parallel converter has drivers to create a virtual parallel port. It implements the Windows parallel port API. It does not implement the PC/AT parallel port register-level API, and even if you were permitted to write I/O port 0x0378, you wouldn't find anything there. Only real PC/AT parallel ports on the system bus (ISA or PCI) use that register.



来源:https://stackoverflow.com/questions/5807882/privileged-instruction-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!