Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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.
 
Share this answer
 
Comments
R. Erasmus 25-Mar-11 4:30am    
good answer!
LaxmikantYadav 25-Mar-11 4:34am    
Thanks :)
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.");

}
 
Share this answer
 
Comments
Mohanraj Sam 25-Mar-11 6:48am    
Hi Jones,
Thanks for your prompt reply.

Mohan
Mohanraj Sam 25-Mar-11 9:10am    
Hi Jones,
I have one doubt, in your program you have written the word "hello". What are the pins in the connector will goes to high or how can I make the particular data pin to high or low. Please clear my doubt.

Thanks & Regards
Mohan

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