Click here to Skip to main content
15,445,641 members
Articles / Programming Languages / C++
Posted 29 Jun 2007


62 bookmarked

Parallel Port Pin Control Library (PaPiC)

Rate me:
Please Sign up or sign in to vote.
4.49/5 (16 votes)
16 Nov 2007CPOL3 min read
Controlling the twelve output pins and the five input pins of the LPT port.

Screenshot - papic1.gif


This is a wrapper for the inpout32.dll/inpout32.lib class which is available at For a little theory, please visit

This class is useful if you wish to control the 12 output pins of your computer's parallel port under Windows XP/NT (e.g., driving LEDs, motors and all). This means, the control pins are used as output. The LPT port has 8 data pins, 4 control pins, and 5 status pins (input), but unfortunately, the basic functions (Console and Port I/O Routines) do not support direct access to the control pins. For this reason, I have developed this project: to have more freedom and functionality using the LPT port.

Almost all functions have the same interface as PARAPIN functions, so this class is useful too if you are adapting your linux code included PARAPIN to Windows enviroment. Hopefully you will find CPaPiC useful.


This C++ class was inspired by PARAPIN, A Parallel Port Pin Programming Library for Linux, which was developed by Jeremy Elson and Al Hooton.

The realization of this work can never been done without the inpout32.dll/inpout32.lib from

Using the code


If you are using WinXP, do the following steps:

  1. Execute regedit.exe:
  2. Find the following registry key:
  3. [HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\CurrentControlSet\\\\Services\\\\Parport]
  4. Insert a new key named "Parameters" (if it does not exist).
  5. Insert a new double word named "DisableWarmPoll" into "Parameters" with value "1".
  6. Restart Windows.

After this. WinXP will not disturb the output if you are switching the status pins.

Before using CPaPiC:

  1. Copy the DLL file inpout32.dll and the lib file inpout32.lib to the project folder.
  2. From the Project menu, select Settings, go to the tab Link, in Object/ Library Modules, write inpout32.lib.

You may use CPaPiC in different ways. For example, you can:

  1. create a static or dynamic object, or
  2. derive your class from CPaPiC.

At first, I will show you how to create a static object and use its member functions and definitions. In this case, it is possible to use more then one object and control only the selected pins without the danger of disturbing the others. Let me declare a CPaPiC object like this:

CPaPiC papi;

The constructor sets the default port LPT1, and selects all the input and output port pins that are active:

Parallel port pins


Parallel port

Two additional definitions that refer to all I/O pins are LP_INPUT_PINS and LP_OUTPUT_PINS. The LPT port can be changed by the lpt_init_user() function. For example:

papi.lp_init_user(LPT2); // papi will control port LPT2

Furthermore, you may give different memory addresses. (But only LPT1 and LPT2 are defined.) If you want to select the pins to control, you can do it this way:

papi.pin_input_mode( LP_PIN10 | LP_PIN11 | LP_PIN12 );
// Set input pins 10, 11 and 12 active

papi.pin_output_mode( LP_PIN01 | LP_PIN02 );
// Set output pins 1 and 2 active

// Equivalent code:

papi.pin_mode( LP_PIN10 | LP_PIN11 | LP_PIN12, LP_INPUT );
papi.pin_mode( LP_PIN01 | LP_PIN02, LP_OUTPUT );

Now, only the 10, 11, 12 input pins and the 1, 2 output pins will be available for the papi object. The port address and active pins are revisable any time. Controlling the selected pins is very simple. Just have a look at these (PARAPIN-like) functions:

Pin control functions

For example:

// Set all pins low (if not all have
// been selected, set only selected)

papi.set_pin( LP_PIN01 ); // Set pin 1 high

papi.invert_pin( LP_PIN01 | LP_PIN02 ); // Invert pins 1 and 2

// Loading the values of input pin registers:

lp_pin pins; // Creat a new lp_pin varible

pins = papi.pin_is_set( LP_PIN10 | LP_PIN11 | LP_PIN12 );
// ask the state of the registers of pins 10, 11 and 12

for( int i = 10; i < 13; i++)
    if( pins & LP_PIN[i] == 0 )
        printf( "pin %d is low\n", i );
        // the pin number i is low

        printf( "pin %d is high\n", i ); // the pin number i is high

In the demo program, you can specify the pin parameters of a function using check boxes (parameter of pin_is_set(..) contains all input pins):

Giving parameters

I have derived the CPaPiCDlg class from CPaPiC, so my dialog has all the properties of CPaPiC. So, I can use all its functions instead of creating a separate CPaPiC object.

Points of interest

While writing the code, I learned how important the bit operations are.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Web Developer
Hungary Hungary
I graduated at University of Veszprem, Hungary and I'm working at Continental Teves as a software developer for brake systems. I like sports (swimming, hiking, jogging) and reading scientific books.

Comments and Discussions

NewsParallel Port Digital Oszilloscope and Logic Analyzer Pin
Elmue24-Apr-10 3:49
MemberElmue24-Apr-10 3:49 
Generalkérdés Pin
Lardino10-Aug-09 2:10
MemberLardino10-Aug-09 2:10 
GeneralInput Using Data Pin Pin
yuzizali29-Apr-09 17:16
Memberyuzizali29-Apr-09 17:16 
GeneralRe: Input Using Data Pin Pin
gordius2-May-09 10:09
Membergordius2-May-09 10:09 
GeneralRe: Input Using Data Pin Pin
Jacques Pelletier8-Jul-14 21:42
MemberJacques Pelletier8-Jul-14 21:42 
Questionim unable to find the proj menu Pin
aisshu25-Mar-09 19:21
Memberaisshu25-Mar-09 19:21 
AnswerRe: im unable to find the proj menu Pin
gordius27-Mar-09 9:02
Membergordius27-Mar-09 9:02 
GeneralPrecise timing using parallel port. Pin
Roccivic3-Oct-08 3:58
MemberRoccivic3-Oct-08 3:58 
Questionsending data through parallel port Pin
suncrest10-Sep-08 6:14
Membersuncrest10-Sep-08 6:14 
AnswerRe: sending data through parallel port Pin
gordius10-Sep-08 10:02
Membergordius10-Sep-08 10:02 
QuestionRe: sending data through parallel port Pin
suncrest10-Sep-08 18:44
Membersuncrest10-Sep-08 18:44 
AnswerRe: sending data through parallel port Pin
gordius11-Sep-08 8:32
Membergordius11-Sep-08 8:32 
GeneralFIle missing in source Pin
Member 45689997-Sep-08 14:40
MemberMember 45689997-Sep-08 14:40 
GeneralRe: FIle missing in source Pin
gordius9-Sep-08 10:53
Membergordius9-Sep-08 10:53 
QuestionI need to "catch" the output for a printer in another computer Pin
luixilva9-Oct-07 11:47
Memberluixilva9-Oct-07 11:47 
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'tFrown | :( 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.

AnswerRe: I need to "catch" the output for a printer in another computer Pin
gordius10-Oct-07 3:40
Membergordius10-Oct-07 3:40 
GeneralRe: I need to "catch" the output for a printer in another computer Pin
luixilva10-Oct-07 11:15
Memberluixilva10-Oct-07 11:15 
GeneralRe: I need to "catch" the output for a printer in another computer Pin
gordius11-Oct-07 2:25
Membergordius11-Oct-07 2:25 
GeneralSome trouble Pin
gordius24-Sep-07 3:08
Membergordius24-Sep-07 3:08 
AnswerProblem solved Pin
gordius30-Sep-07 3:30
Membergordius30-Sep-07 3:30 
Generalhi i am unable to write any value on control pins where is the problem Pin
rajbhansingh11-Jul-07 3:10
Memberrajbhansingh11-Jul-07 3:10 
GeneralRe: hi i am unable to write any value on control pins where is the problem Pin
gordius12-Jul-07 0:07
Membergordius12-Jul-07 0:07 
GeneralRe: hi i am unable to write any value on control pins where is the problem Pin
gordius12-Jul-07 8:52
Membergordius12-Jul-07 8:52 
GeneralA little misleading .. Pin
Garth J Lancaster29-Jun-07 14:42
professionalGarth J Lancaster29-Jun-07 14:42 
GeneralRe: A little misleading .. Pin
gordius1-Jul-07 10:08
Membergordius1-Jul-07 10:08 

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

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