Privileged instruction in C

2019-08-12 08:09发布

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?

2条回答
贼婆χ
2楼-- · 2019-08-12 08:46

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.

查看更多
叛逆
3楼-- · 2019-08-12 08:55

There are ways around this. See here for instance.

查看更多
登录 后发表回答