Win32 doesn't allow direct manipulation of hardware so you must use a device driver to "talk" to the parallel port.
I use Port95NT to control the parallel port from C++/C#. It's free and simple.
Port95NT is a commonly-used driver (by Scientific Software Tools) that allows this access via a simple user-mode DLL.
Sadly, Port95NT was discontinued in 1999, but it still works great on WinXP and Win7 (probably Vista too, if you're unlucky enough to be stuck with Vista).
- Port95NT installer - ZIPped copy from my server (the original driverlinx site appears to be dead?!?!)
- C++ Parallel Port Wrapper class - ZIPfile).
- C# Port95NT Wrapper assembly - ZIPfile). Includes a simple demo testapp!
Port95NT Installation notes
Port95NT.exe (in the above ZIP) creates a \Program Files\DLPortIO directory. This contains only the Windows uninstaller.
The meat of the thing comes in two parts:
- DLPortIO.dll - This is the user-mode dll. It's installed into \windows\system32 (and is thus in your searchpath).
- DLPortIO.sys - This is the kernel-mode driver. It's installed into \windows\system32\drivers. You access it via DLPortIO.dll.
Port95NT.exe installs everything correctly on WinXP, but requires a trick (that I learned here) to get it to install on Win7:
In Win7, before running Port95NT.exe:
- In Explorer, right-click Port95nt.exe
- Click Properties
- In the popup, click the Compatibility tab
- Check the Run this program in compatibility mode for: checkbox.
- In the droplist, select Windows XP Service Pack 2
- Click OK
Now run Port95NT.exe as an administrator.
If you don't follow the above steps on Win7, Port95NT.exe will appear to have installed everything correctly, but you'll get a DLPORTIO.SYS is not loaded error when you invoke any of the functions exported by DLPortIO.dll