Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Please share info on how to functionally access ports in Windows 10 using C++ (compiled with g++).

Please include all #include files and code necessary to test I/O Parallel Port Pin Programming.

Thank you

What I have tried:

C++
/*** Following Code Compiles but DOES NOT modify ports ***/

#include <stdio.h>
#include <conio.h>
#include <windows.h>


/* Definitions in the build of inpout32.dll are:            */
/*   short _stdcall Inp32(short PortAddress);               */
/*   void _stdcall Out32(short PortAddress, short data);    */
/* prototype (function typedef) for DLL function Inp32: */

     typedef short _stdcall (*inpfuncPtr)(short portaddr);
     typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);

int main(void)
{
     HINSTANCE hLib;
     inpfuncPtr inp32;
     oupfuncPtr oup32;

     short x;
     int i;

     /* Load the library */
     hLib = LoadLibrary("inpout32.dll");

     if (hLib == NULL) {
          printf("LoadLibrary Failed.\n");
          return -1;
     }

     /* get the address of the function */

     inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");

     if (inp32 == NULL) {
          printf("GetProcAddress for Inp32 Failed.\n");
          return -1;
     }

     oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");

     if (oup32 == NULL) {
          printf("GetProcAddress for Oup32 Failed.\n");
          return -1;
     }

/***************************************************************/
/* now test the functions */

     /* Try to read 0x378..0x37F, LPT1:  */

     for (i=0x378; (i<0x380); i++) {

          x = (inp32)(i);

          printf("port read (%04X)= %04X\n",i,x);
     }

     /*****  Write the data register */

     i=0x378;
     x=0x77;

     (oup32)(i,x);

     printf("port write to 0x%X, datum=0x%2X\n" ,i ,x);

     /***** And read back to verify  */
     x = (inp32)(i);
     printf("port read (%04X)= %04X\n",i,x);

     /*****  One more time, different value */

     i=0x378;
     x=0xAA;

     (oup32)(i,x);

     printf("port write to 0x%X, datum=0x%2X\n" ,i ,x);

     /***** And read back to verify  */
     x = (inp32)(i);
     printf("port read (%04X)= %04X\n",i,x);

/*****  One more time, different value */

     i=0x378;
     x=15;

     (oup32)(i,x);

     printf("port write to 0x%X, datum=0x%2X\n" ,i ,x);

     /***** And read back to verify  */
     x = (inp32)(i);
     printf("port read (%04X)= %04X\n",i,x);

     FreeLibrary(hLib);
     return 0;
}

/*** Output ***

port read (0378)= 0078
port read (0379)= 0079
port read (037A)= 007A
port read (037B)= 007B
port read (037C)= 007C
port read (037D)= 007D
port read (037E)= 007E
port read (037F)= 007F
port write to 0x378, datum=0x77
port read (0378)= 0078
port write to 0x378, datum=0xAA
port read (0378)= 0078
port write to 0x378, datum=0x F
port read (0378)= 0078

Process returned 0 (0x0)   execution time : 0.029 s
Press any key to continue.

***/
Posted
Updated 17-Aug-17 21:50pm
v6
Comments
Rick York 17-Aug-17 14:24pm    
I would start by searching for articles on "parallel port" at this site. I did and found a good number of articles. Here's one : https://www.codeproject.com/Articles/15020/Reading-from-Parallel-Port-using-Inpout-dll

That one uses VB but it's a start. You could see if it will even run on your machine as a proof of principle.
Jochen Arndt 18-Aug-17 3:32am    
Might be a silly question:
Does your system has a parallel port and is it enabled in the BIOS?

Most modern systems (using Windows 10 indicates that yours is not an old one) does not have a parallel port anymore. Some might have it in the chipset but disabled it in the BIOS without an enable option when not routed to a connector.

Or do you use an USB-to-parallel-port converter?
seyran1 25-Apr-21 5:39am    
This is a fake post.. It never run under windows 10 nor win 7..

1 solution

I personally prefer other API like WriteFile which also works with COM ports. The link is good starting point to get an overview with some links to sample code.

Take also a look at this great article about Serial library for C++.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900