
-----------------------------------
Kameboy
Sat Mar 05, 2011 1:14 pm

Does anyone know who to access the parallel port Using C++?
-----------------------------------
For school i am trying to help access the parallel port using C++. But i am not sure how to .

-----------------------------------
Insectoid
Sat Mar 05, 2011 1:34 pm

RE:Does anyone know who to access the parallel port Using C++?
-----------------------------------
the conio library has a function to write to a port, however this is not cross-platform and you need to know the port ID.

-----------------------------------
bbi5291
Sat Mar 05, 2011 5:02 pm

Re: Does anyone know who to access the parallel port Using C++?
-----------------------------------
I believe that Windows reserves the lowest 1024 ports (numbered from 0x0000 to 0x03ff), and the first parallel port is almost universally located at 0x0378. By "reserves", I mean that it locks them so that they cannot be accessed from userland. (If this were not the case, malicious applications could easily halt the system by messing with the microcontroller, corrupt the filesystem by talking directly to the hard disk, circumvent system security by changing the CMOS password, and so on.)

If you want to access them, you will have to install a driver (remember, drivers run with elevated privileges) that will accept requests to write to these ports from application programs. (For security reasons, I wouldn't be surprised if ports numbered lower than 0x0100 were still blocked --- these are the important ones.) Otherwise, the functions from conio.h will trigger an exception, which will either be handled silently by the OS, or terminate your program with an error.

There are many such drivers available for free; just Google up "windows port access" or something similar.

-----------------------------------
Kameboy
Sat Mar 05, 2011 8:03 pm

Re: Does anyone know who to access the parallel port Using C++?
-----------------------------------
Well is is for a Windows 2000 computer manufacturer is Dell. I can check the port number. I did find something online but when i tried it out it didn't work. When i tired linking the lib and the include.

-----------------------------------
OneOffDriveByPoster
Sun Mar 06, 2011 4:44 pm

Re: Does anyone know who to access the parallel port Using C++?
-----------------------------------
Depending on what you want to do, you can try using fopen() on "LPT1", "PRN", etc.
There also seems to be a DeviceIoControl function in the Win32 API.

-----------------------------------
Kameboy
Mon Mar 07, 2011 10:00 am

Re: Does anyone know who to access the parallel port Using C++?
-----------------------------------
Could you show me a open source code that would utlizes the COM1 port on a dell computer using intel pentium 3.
I read the conio libaray and read about i think that might work.

-----------------------------------
Homer_simpson
Mon Mar 07, 2011 11:05 pm

Re: Does anyone know who to access the parallel port Using C++?
-----------------------------------
hey, I'm not sure if this is useful to you.. but I used this to use my laptop serial port to communicate to an AVR chip.. 
#include 
#include 
#include 
#include 
#include 
HANDLE hPort;

BOOL WriteByte(BYTE bybyte)
{
    DWORD iBytesWritten=0;
    DWORD iBytesToRead = 1;
    if(WriteFile(hPort,(LPCVOID) 
        &bybyte,iBytesToRead,&iBytesWritten,NULL)==0)
        return FALSE;
    else return TRUE;
}

BOOL WriteString(const void *instring, int length)
{
    int index;
    BYTE *inbyte = (BYTE *) instring;
    for(index = 0; index< length; ++index)
    {
        if (WriteByte(inbyte
