• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 879
  • Last Modified:

Parallel Port Address

From a Win32 app, how can I find the parallel port addresses? (ie, LPT1 is at 0x378, LPT2 is at 0x278, etc).
 
This information is in the BIOS data area at address 04:08, but I don't know how to access that from a 32 bit MFC app.

0
ivanm
Asked:
ivanm
1 Solution
 
glittleCommented:
Are you running under Win 3.1, 95, or NT?  

If your using NT, then the best solution is to query the services registery for the parallel port information.  Of course, to use it you will have to be in kernel mode, which means your writing your own device driver.

Outside of NT, the big question here is protected mode and if your application has access to that area of memory that contains your LPT1 and 2 address.  If your app does not have access to that memory in protected mode, you will cause a Trap 13, or GPF.  If you are in Real mode, then you have access to that page, or at least a copy of that page if you are virtual 86 in a Protected mode OS.

The first thing I would try is to build a 32 bit pointer using segment 0 with offset 408 (0000:0408).

typedef struct {
  union {
    int      offset;
    int segment;
    char *pointer;
  }
}POINTER;    

POINTER      aPointer;
int      port;

aPointer.offset = 408;
aPointer.segment = 0;
port = *aPointer.pointer;

You C compiler should have macros that deal with this.  Check for SEGMENT, OFFSET, MAKEP, MAKEPOINTER, MAKEFAR, MAKENEAR, etc.

OR -- you could force assembly and do:
      int      port;

      _asm {
            push es
            push ax
            push dx
            push 0
            pop  ds
            mov  si, 0x0408
            mov  dx, es:[si]
            mov  port, dx
            pop  dx
              pop  ax
                pop  es
      }

If protected mode is a problem, then spawn a real mode program that accesses the memory, writes a file, and terminates.  Your Win32 app then reads the file and gets the LPT1 address from the disk.
Dirty, but workable.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now