Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Parallel port and MFC

Posted on 1998-07-27
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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 andy@warmcat.com 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.


What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


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 800 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 headley@cs.ucsb.edu


Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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