We help IT Professionals succeed at work.

win32 paralle port I/O

byang asked
Medium Priority
Last Modified: 2013-12-03
From a win32 app, I need to control an external device connected to the PC thru the paralle port. I already have a DOS program which does this. It accesses the paralle port using IN and OUT instructions. How do I do this under win32 ?

Just a pointer to the info is enough.
Watch Question

You cannot, unless you want to write a device driver.  IN and OUT instructions can only run in kernel mode under NT.

You could open the port using CreateFile("LPT1", ...) and read/write data using ReadFile() and WriteFile() functions.

>>You cannot, unless you want to write a device driver.
You're right - the best way to do that is to write a device driver. But under Win95 and Win98 the Win32 applications do have I/O access.

>>IN and OUT instructions can only run in kernel mode under NT.
The ntiosupp.dll will help you to access the I/O space from the user mode application under Windows NT: http://warmcat.com/ntiosupp.zip 


I need this to work on win95, nt, and win98. Ideally on WinCE too.

So I cannot use IN and OUT instructions. What I am asking for is something like accessing the port thru some of standard paralle port driver, or win32 API.

I know I can open the port as a regular file, but then I need info on how data read by ReadFile() and data written by WriteFile() maps to pins on the port, or bits on the port registers.

For example, on a standard unidirecitonal port, external devices can change the voltages on 5 control pins (error, acknowledge etc). The CPU can then read them using IN instruction. If I use ReadFile(), how are these 5 bits returned ?

If you are going to do parallel port communication with Win95 and WinNT, you've gotta write yourself a VxD.  I've had little to no success at all with ReadFile and WriteFile using the parallel port.  You have no low level support using these features.

Check out the products available like VToolsD for your parallel port access.  You'll get a program up and running in days vs. months or not at all.  The price is relatively high but it's nothing compared to the troubles you'll see.


>>So I cannot use IN and OUT instructions.
You CAN !!! See my comment above.


I would like to avoid requiring a Vxd or device driver for my app, as it complicates shipping and installation.

To Andy Green:
I downloaded your ZIP file and it looks very interesting. I haven't tested it on NT yet but if it works, there's obviously some way to disable i/o trapping. I'd like to know:

1. Is it part of regular win32 API, or part of the device driver API ?
2. Do you need administrator previlege to use it ?
3. If possible, I'd like to see the code for you DLL, and the code for the DLL you're embedding in your DLL.

1) The NTIOSUPP.DLL uses the CreateService and StartService Win32 API functions to install the GIVEIO.SYS device driver that uses two undocumented functions to give I/O access to the calling process.

2) Yes you need the administrator privs. to use the ntiosupp.dll.
3) The ntiosupp.dll was written by Andy Green (aka warmcat) ask him (andy@warmcat.com). The source code of the GIVEIO.SYS driver you can find in the DDJ's May 1996 sources. (www.ddj.com).

Btw see the INSTDRV NT DDK's sample that shows how to install the driver without forcing the user to reboot. I think that warmcat uses the same way to load the GIVEIO.SYS

Is ut just me or anybody else sees some similarity between "Andy Green" and "agreen"?

alexo: :))
By a weird coincidence the warmcat's real name is Andy Green
and my name is Alex :)

It is so easy to do that just follow my instructions:

First method :
      If you are familier with Assembly language you can add your code in assembly language to Delphi , Vbasic, VC++ ......
as following :
....    //write your code here
the instructions you must use are
IN           addressOf port in hexadecimel
OUT       addressOf port in hexadecimel

the syntax depens on the kind of your processor
you can take the assistance of any book talking about Microprocessors or you can e-mail me.

second method:

Win32 programming langauges gives two instructions
for getting/giving information from/to port
they are
InPort ,
OutPort ,
they accepts the address of the port you are using
( Parallel port address =  3f8 Hexadecimal or 888 decimal )  
the syntax changes with programming language you are using.

These are the two ways, I used them when I was in my Fourth Year applying on an interfacing project.

Under Windows NT all the I/O ports are trapped.  
Under Windows 95 some ports are also trapped, for example the serial ports.
So in both cases you need a piece of kernel mode code.

As Alex and I live in different countries, we have never been seen together at the same time and same place :)  But I really am quite sure we're different people.

I fear your hope of unifying 95, NT and CE are doomed when it comes to IO.  If you use NTIOSUPP.DLL, you will be able to write a single piece of Application code that ''just works'' on 95, 98 and NT.  CE does not even use 80x86 processors, so you really will have to look into the CE SDK to find out what you're meant to do.  Unless it's a high-volume consumer device well suited to portable/battery operation I would skip CE support.



BTW, issamwd's comment:

>( Parallel port address =  3f8 Hexadecimal or 888 decimal )  

is busted: 0x378 is the normal address for LPT1.  See http://warmcat.com/parallel for a deeper discussion on how to get LPT base addresses, and some of the diseases that can attack the unwary LPT bit-twiddler.


Confusing names: I know warmcat is Andy Green from his web site, but agreen is not Andy Green ?

Agreen was the first one to point to the solution (on warmcat's web site, or are they the same person), so I'll give the points to agreen.
Unlock this solution and get a sample of our free trial.
(No credit card required)

>>...or are they the same person
Once again - we are different people :))

May be it will be better for me to write my own implementation of the giveio.sys loader instead of directing people to your web site or it will be better to change my nick ?? (joke) :)))
You can accsses easily with the LPT und Win95 / 98 with
the Borland CBuilder:

For Example:
The Parallelport base address 378h

unsigned char x;
// input
 mov dx,0x379
 in a,dx
 mov x,a
... now you can use x and its value in normal C code
// ouput
x=10; //just an example
 mov dx,0x379
 mov a,x
 out dx,a
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.