Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Parallel Comms under WinXP with VC++

Posted on 2005-03-07
Medium Priority
Last Modified: 2012-08-13
Hi Gurus,
I want to use the Parallel port under Windows XP. I have done it successfully with other Windows versions but XP doesn't work. I am using a VC++ DLL to do the actual communications to the Parallel port. I am calling the DLL from a VisualBasic6 App.


      void _stdcall OutM2G(short portVal, short number)
            _outp(portVal, number);            //( This crashes with values (0x378, 0) )

      short _stdcall InM2G(short portVal)
            return _inp(portVal);            //( This crashes with value (0x378) )

I have also tried using _outp and _inp from a Win32 Application but I get the same error: "Unhandled Eception in Blah.exe: 0xC0000096: Privileged Instruction."

Any idea what I'm doing wrong?
Question by:jasonbb
LVL 48

Expert Comment

ID: 13475391
This library can be used to make simple Windows program working with parallel port:

LVL 22

Accepted Solution

grg99 earned 2000 total points
ID: 13475641
You can't do direct port I/O with Windows NT/2000/XP as-is.

There are a few kludgy helper apps that turn off the I/O protection, google for "giveio", that's one I've used with some success.

LVL 86

Expert Comment

ID: 13477009
>>Any idea what I'm doing wrong?

Yes. You are using a "Privileged Instruction" :o) Direct hardware acces is not allowed under NT/2k/XP.

I'd strongly advise to only use direct port I/O as a last resort. Actually, all the APIs you need are described at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp ("Serial Communications in Win32"), which also applies to parallel port programming (just use 'LPT1' instead of e.g. 'COM1'). http://support.microsoft.com/default.aspx?scid=kb;en-us;138594 ("HOWTO: Send Raw Data to a Printer by Using the Win32 API")
LVL 22

Expert Comment

ID: 13477525
The problem with using the recommended methods of talking to LPT port is that many devices need more than simple data stream out with Centronics or ECP handshaking.

.  The LPT port is a bi-directional 14-bit port.  there are unfortunately lots of EE's that want to talk i2L protocol, which involves twiddling one of the bits as an output clock, while watching a different bit for input data.  

That was trivial under DOS, you just send out one bitmask to select what wires you wanted as inputs, which as outputs.  Then you could do an out 378h,al to send a byte, in 37Ah to input a byte.    

Now of course we have several layers (SIX I think if you use the stock Miniport driver skeletons) of protocols to navigate if we want to set up our own port driver.    Kind of a steep learning curve for somebody that just wants to input one bloody bit.

I still suggest kludges like "giveio".  They're not the "right" way to do it, just 10,000,000 times simpler.


Author Comment

ID: 13503379
The program I used is called "UserPort". It's very easy and it works.
I found "UserPort" from a link at "GiveIO" so grg99 gets the points.
Thankyou posters.

Links follow:




Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question