Parallel port and MFC

Posted on 1998-07-27
Last Modified: 2013-11-20
I would like to send data strings to a device connected to my parallel port using MFC 5.0.  I have seen a variety of responses as to how to do this... "Use CreateFile()"... "You cannot use CreateFile(), you have to go thru the VxD"... "You can use CreateFile() with Windows 95"... etc. etc.  I am only interested in getting this to work under Windows 95.  Do I need to go thru a driver, can I use CreateFile()?  Is there some way I could use a dedicated thread to read the status of the parallel port to read data from the parallel port when there is data available?  Do I need to set the parallel port data buffer to hold a specified number of characters before I get around to reading it?  

Basically, I just need a method to read and write data strings to a custom device that is not a printer.  Can anyone give me some advice AND OR sample code?

Thanks in advance
Garrett Headley
Question by:headley

Expert Comment

ID: 1319793

Expert Comment

ID: 1319794
Hi headly -

If it's just '95 you're after working with, use the following tips:  Use this to get the IO base ads of printer port n

// returns 0 for invalid port, or IO base ads

WORD GetPrinterPortBaseAddress(int nPort) // 0=LPT1, 1=LPT2 ..3
WORD * pwDosPrinterPortBaseAddresses= (WORD *) 0x0408;
if((nPort<4)&&(nPort>=0)) return pwDosPrinterPortBaseAddresses[nPort];

Then write to the (base ads+0) to set D0..D7 on the printer port, eg outp(wBaseAds, 0x55);.  inp(wBaseAds+1) reads back the input lines, and outp(wBaseAds+2) writes to the status lines.

Contact me at if you need more detail.


Expert Comment

ID: 1319795
ALready answered, but you don't need a VxD for sure! If you need source, contact me.

You can still use the standard _inp and _outp as well.


Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)


Author Comment

ID: 1319796
Phillip, I would LOVE some source code.  The help from sites:
I've been over a couple of times, and cannot seem to figure out how to make it useful... I really need something that will allow me to send a string of characters to the parallel port... even if it can be done only 1 character at a time.  I'm checking into Andy's advice, but haven't gotten it to work correctly yet.  I apologize for delays in grading these responses... one fire after another seems to be springing up at the moment.

So yeah, source code would be GREAT!!


Accepted Solution

warmcat earned 200 total points
ID: 1319797
Headly -

The sample I gave you works in a DOS app - now I see you are in the 32-bit world.  Use the following code instead...

WORD GetPrinterPortBaseAddress(int nPort) // 0=LPT1, 1=LPT2 ..3
   WORD wa[4];
   DWORD dwRead;

   if( (nPort<0)||(nPort>3) ) return(0);
   if(ReadProcessMemory(GetCurrentProcess() ,(void *)0x00000408, wa, sizeof(wa), &dwRead)) {
      return (wa[nPort]);
   } else {

. some sample code to go with it ....

int main()
   WORD wBase=GetPrinterPortBaseAddress(0);
   int n;

   if(wBase==0) { printf("Unable to get LPT1 base ads\n"); return(1); }

   for(n=0;n<1000;n++) {
     outp(wBase, 0x55);
     outp(wBase, 0xaa);

. mail me if you need more advice.


Author Comment

ID: 1319798
Thanks to Andy for sample code... if Phillip comes across this question again, I'd definitely appriciate the sample code you offered.  You can always email it to me


Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 185
method notes when mouse over in eclipse 5 87
modThree challenge 4 91
Problem to event 3 97
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 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