Click here to Skip to main content
11,801,910 members (56,193 online)
Click here to Skip to main content

Port Access

, 17 Aug 2004 136.3K 3.7K 38
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.

You may also be interested in...

Comments and Discussions

GeneralRe: Port access project Pin
Wamuti16-Nov-07 6:07
memberWamuti16-Nov-07 6:07 
Generalplotting a graph in VC++ Pin
Member #343294419-Mar-07 22:07
memberMember #343294419-Mar-07 22:07 
GeneralVisual C++ 6 Or Visual C++.Net 2005 Pin
saman_programing29-May-06 1:13
membersaman_programing29-May-06 1:13 
GeneralRe: Visual C++ 6 Or Visual C++.Net 2005 Pin
asef29-May-06 2:40
memberasef29-May-06 2:40 
Questionejraye barname dar Turbo C++ 3.0 DOS Pin
saman_programing24-May-06 18:55
membersaman_programing24-May-06 18:55 
AnswerRe: ejraye barname dar Turbo C++ 3.0 DOS Pin
asef26-May-06 18:49
memberasef26-May-06 18:49 
Generalserial ( COM) port accessing Pin
bala nagesh15-May-06 18:29
memberbala nagesh15-May-06 18:29 
GeneralRe: serial ( COM) port accessing Pin
asef15-May-06 20:14
memberasef15-May-06 20:14 
QuestionInput Probs Pin
bhaskar_gupta8-Feb-06 8:31
memberbhaskar_gupta8-Feb-06 8:31 
AnswerRe: Input Probs Pin
asef11-Feb-06 17:45
memberasef11-Feb-06 17:45 
GeneralHow to control parallel port by programming Visual C++ Pin
BK200725-Dec-06 4:07
memberBK200725-Dec-06 4:07 
GeneralParallel port Pin
dzldan2-Nov-05 10:46
memberdzldan2-Nov-05 10:46 
GeneralRe: Parallel port Pin
asef4-Nov-05 17:36
memberasef4-Nov-05 17:36 
GeneralRe: Parallel port Pin
BK200725-Dec-06 4:05
memberBK200725-Dec-06 4:05 
Generalport Programming Problem In XP Pin
Masoud Aghapour7-Sep-05 17:49
memberMasoud Aghapour7-Sep-05 17:49 
GeneralRe: port Programming Problem In XP Pin
asef21-Oct-05 18:49
memberasef21-Oct-05 18:49 
Generalport interface for XP Pin
sarkiszakaryan23-Aug-05 11:26
membersarkiszakaryan23-Aug-05 11:26 
GeneralI/O Pin
Georgi Petrov19-Jul-05 10:37
memberGeorgi Petrov19-Jul-05 10:37 
GeneralPrivileged Instruction problem Pin
jrocnuck1-Dec-04 8:45
memberjrocnuck1-Dec-04 8:45 
GeneralRe: Privileged Instruction problem Pin
richy_b20-Dec-04 4:15
memberrichy_b20-Dec-04 4:15 
GeneralRe: Privileged Instruction problem Pin
jrocnuck20-Dec-04 10:41
memberjrocnuck20-Dec-04 10:41 
GeneralRe: Privileged Instruction problem Pin
asef28-Aug-05 21:38
memberasef28-Aug-05 21:38 
GeneralRe: Privileged Instruction problem Pin
jrocnuck29-Aug-05 2:42
memberjrocnuck29-Aug-05 2:42 
GeneralWhere the source code Pin
M.Atia20-Nov-04 7:14
sussM.Atia20-Nov-04 7:14 
GeneralRe: Where the source code Pin
MAHDI.M24-Nov-04 2:58
memberMAHDI.M24-Nov-04 2:58 
GeneralSource code Pin
asif ahsan18-Aug-04 8:04
memberasif ahsan18-Aug-04 8:04 
GeneralRe: Source code Pin
jrocnuck1-Dec-04 9:10
memberjrocnuck1-Dec-04 9:10 
GeneralAnother hardware related article! Pin
A. Riazi18-Aug-04 2:48
memberA. Riazi18-Aug-04 2:48 
GeneralRe: Another hardware related article! Pin
Anonymous21-Aug-04 19:41
sussAnonymous21-Aug-04 19: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.151002.1 | Last Updated 18 Aug 2004
Article Copyright 2004 by asef
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid