port programming

This is a discussion on port programming within the C Programming forums, part of the General Programming Boards category; hi guys I have a problem.I'm trying to learn port programming I'm referring Interfacing with C++ Code: Programming Real-World Applications ...

  1. #1
    Just a Human Anuradh_a's Avatar
    Join Date
    Jan 2008
    Posts
    50

    port programming

    hi guys
    I have a problem.I'm trying to learn port programming
    I'm referring
    Interfacing with C++
    Code:
    Programming Real-World Applications
    by Jayantha Katupitiya .
    I found this code in his book .My problem is that it's gives me this error
    
    My Code is 
    
    
    Code:
    #include <dos.h> 
    #include <conio.h>
    #include <stdio.h>
    #define BASE 0x378
    inportb(int);
    void main() 
    {
       unsigned char InputData;     // Declare data type for 
                                    // various InputData. 
       InputData = inportb(BASE+1); // Read port at BASE+1.
       printf("%2X\n",InputData);   // Print result to screen 
                                    // as a hexadecimal number. 
       getch();                     // Wait for key press. 
    }
    Linking... simple1.obj : error LNK2001: unresolved external symbol _inportb Debug/simple1.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe.
    I'm using
    MS VC++ 6.0
    Windows XP Profeesional Service pack 2
    please help me

    simple1.exe - 2 error(s), 0 warning(s)

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm pretty sure that even if you manage to translate inportb() to the relevant Microsoft-ism, it won't work because a user-mode application can't read/write the LPT interface directly in Windows.

    You need either:
    1. a miniature device driver that "releases" the port to user-mode.
    2. a device driver in itself.
    3. Another OS [such as DOS itself] that doesn't restrict your access [and a different compiler to compile 16-bit code]. MS hasn't produced a 16-bit compiler for a LONG time.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,248
    Quote Originally Posted by matsp View Post
    I'm pretty sure that even if you manage to translate inportb() to the relevant Microsoft-ism, it won't work because a user-mode application can't read/write the LPT interface directly in Windows.
    Does Windows not have a call equivalent to Linux ioperm()? But yeah, I'd be suspicious of accessing ports from user space. Even if you do it safely, the kernel might schedule you out while in the middle of some time-critical exchange with the hardware. And how are you going to deal with interrupts (if the device generates them?) You really need total control when interfacing with hardware.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by brewbuck View Post
    Does Windows not have a call equivalent to Linux ioperm()? But yeah, I'd be suspicious of accessing ports from user space. Even if you do it safely, the kernel might schedule you out while in the middle of some time-critical exchange with the hardware. And how are you going to deal with interrupts (if the device generates them?) You really need total control when interfacing with hardware.
    Yes and no. There is a way to do the same thing as ioperm, but it involves using a kernel driver [as the "ioperm" thingy is a kernel only API - at least IIRC].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. Segmentation Fault - Trying to access parallel port
    By tvsinesperanto in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 03:28 AM
  4. Basic port scanner code .. pls help ???
    By intruder in forum C Programming
    Replies: 18
    Last Post: 03-13-2003, 07:47 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 03:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21