Click here to Skip to main content
Click here to Skip to main content

Port Access

, 17 Aug 2004
Rate this:
Please Sign up or sign in to vote.
A way to access parallel port in Windows XP


At first I want to thank Mr. Tomas Franzon as I used his help a lot in this project. This code opens and closes 0x378 port ( printer port ) manually. In XP we have no permission to access external port like Printer. Here we copy a sys file to system32 and use it in the code so we can send and receive data through this port.

Using the code

For using the code you have to copy PortAccess.sys ( exists in source ) to system32\drivers. Then you can run the program.

For sending and receiving data we do this :

#include <conio.h>
#include <math.h>

         // for sending data


Return Value:

This function returns data output . There is no error return.


Unsigned short Port Number ( defined 0x378 )

Int Output value

         // for receiving data

Return Value:

This function returns the byte, word or int from port. There is no error report


Unsigned short Port Number ( defined 0x378 )

When you check a check box the iBitOut value is Set or Reset.

// to set or reset a bit

When you click output button the Bits are changed to int value to send to port.

         // to send value to port


         for (i=0;i<=7;i++)







When you click input button the input value is read and iBitIn[i] becomes set or reset.


         // to get data from port 


         for (i=7;i>=0;i--)



                 if (iByte>=nIndex)

                 {        iByte=iByte-nIndex;



                 else iBitIn[i]=0;


For checking a check box we use code below :

         // to check a check box

         if (iBitIn[0]==1)

Points of Interest

I always work with peripheral devices. In these cases, communicating in parallel mode is more flexible and easier than the other modes like serial communication. So I am forced to go to this field. You can send and receive int, long, Byte, unsigned short, unsigned char etc as easy as possible.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I live in Iran . I started hardware programming when I was young. I designed and built some ISA cards for attaching to ocsiloscope and signal generator. Now I am working for a engineering company and Manager of some project.

Comments and Discussions

GeneralMy vote of 4 PinmemberMember 870111428-Apr-12 23:19 
GeneralRun file PinmemberROVIO5-Oct-09 4:47 
Questionemergency help Pinmembermechatron19-Apr-08 1:39 
QuestionI have a problem with a parallel port, could you please help me? Pinmemberluixilva9-Oct-07 12:53 
I have a problem: a program X send an output to the printer, but.... i need this output in a file in another computer. Then I need to "catch" this output trough the parallel port in another computer. I am using a cable DB25M - DB25M connected to the parallel port of both computers (this cable was used with a switch between two printers and worked properly), but.... i just can't do it, i don't know what happen, because i can read properly the ports: data, status and control.

I am using a visual C++ program to catch the output from the other computer trough the parallel port. The code i am using is something like this...

fin = 0;
count = 0;
data = _inp( dataport );
stat = _inp( statport );
ctrl = _inp( ctrlport );
ctrl = ctrl & 0x000000ff;
if( ctrl & 0x01 )
stat = stat | 0x80; // set the busy port on
retu = _outp( stat );
wait( (clock_t) 5 ); // wait for 5 micro-seconds
data = _inp( dataport );
printf( "Data read: 0x%2x\n", data );
stat = stat | 0x40; // set acknowledge on
retu = _outp( stat );
wait( (clock_t) 5 ); // wait for 5 micro-seconds
stat = stat & 0x7f; // set busy off
retu = _outp( stat );
stat = stat & 0xbf; // set ackn off
retu = _outp( stat );
if( _kbhit() != 0 )
c = getch();
if( c == 'c' || c == 'C' )
fin = 1;
printf("End of process\n");
} while( fin != 0 );

Could you please help me?

Thank you in advance for your attentions.

QuestionInput Problem Pinmembermirispearl5-Sep-07 20:37 
Questiona question from lovers_ali PinadminSean Ewington6-Jun-07 9:41 
AnswerRe: a question from lovers_ali Pinmemberasef9-Jun-07 20:26 
GeneralPort access project PinmemberRupanagudi4-May-07 16:25 
GeneralRe: Port access project Pinmemberf227-May-07 17:49 
GeneralRe: Port access project Pinmemberasef9-Jun-07 20:42 
GeneralRe: Port access project PinmemberWamuti16-Nov-07 7:07 
Generalplotting a graph in VC++ PinmemberMember #343294419-Mar-07 23:07 
GeneralVisual C++ 6 Or Visual C++.Net 2005 Pinmembersaman_programing29-May-06 2:13 
GeneralRe: Visual C++ 6 Or Visual C++.Net 2005 Pinmemberasef29-May-06 3:40 
Questionejraye barname dar Turbo C++ 3.0 DOS Pinmembersaman_programing24-May-06 19:55 
AnswerRe: ejraye barname dar Turbo C++ 3.0 DOS Pinmemberasef26-May-06 19:49 
Generalserial ( COM) port accessing Pinmemberbala nagesh15-May-06 19:29 
GeneralRe: serial ( COM) port accessing Pinmemberasef15-May-06 21:14 
QuestionInput Probs Pinmemberbhaskar_gupta8-Feb-06 9:31 
AnswerRe: Input Probs Pinmemberasef11-Feb-06 18:45 
GeneralHow to control parallel port by programming Visual C++ PinmemberBK200725-Dec-06 5:07 
GeneralParallel port Pinmemberdzldan2-Nov-05 11:46 
GeneralRe: Parallel port Pinmemberasef4-Nov-05 18:36 
GeneralRe: Parallel port PinmemberBK200725-Dec-06 5:05 
Generalport Programming Problem In XP PinmemberMasoud Aghapour7-Sep-05 18:49 
GeneralRe: port Programming Problem In XP Pinmemberasef21-Oct-05 19:49 
Generalport interface for XP Pinmembersarkiszakaryan23-Aug-05 12:26 
GeneralI/O PinmemberGeorgi Petrov19-Jul-05 11:37 
GeneralPrivileged Instruction problem Pinmemberjrocnuck1-Dec-04 9:45 
GeneralRe: Privileged Instruction problem Pinmemberrichy_b20-Dec-04 5:15 
GeneralRe: Privileged Instruction problem Pinmemberjrocnuck20-Dec-04 11:41 
GeneralRe: Privileged Instruction problem Pinmemberasef28-Aug-05 22:38 
GeneralRe: Privileged Instruction problem Pinmemberjrocnuck29-Aug-05 3:42 
GeneralWhere the source code PinsussM.Atia20-Nov-04 8:14 
GeneralRe: Where the source code PinmemberMAHDI.M24-Nov-04 3:58 
GeneralSource code Pinmemberasif ahsan18-Aug-04 9:04 
GeneralRe: Source code Pinmemberjrocnuck1-Dec-04 10:10 
GeneralAnother hardware related article! PinmemberA. Riazi18-Aug-04 3:48 
GeneralRe: Another hardware related article! PinsussAnonymous21-Aug-04 20:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150331.1 | Last Updated 18 Aug 2004
Article Copyright 2004 by asef
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid