Thread: accsesing the paralell port in c++

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    13

    accsesing the paralell port in c++

    i am writing c ode for a college project i'm using dev c++

    what i was wondering is, how would you go about doing it using dev c++

    i managed to do it using microsoft visual c++ using

    Code:
    
    #include <iostream.h>
    #include<io.h>
    #include<windows.h>
    
    
    
    
    #define DATA 0x378
    #define STATUS 0x379
    #define CONTROL 0x37a
    and this in main

    Code:
    
    HANDLE h;
    h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_ EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (h == INVALID_HANDLE_VALUE) {
    printf("Couldn't accses giveio device\n");
    }
    CloseHandel(h);

    but help 'cause

    Code:
    _outp(int addres,value);
    
    _inp(addres);
    aren't working


    thanks kindly

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    _inp and _outp are most likely failing because they compile to assembly instructions that only the OS is allowed to use, and your program is running in userspace. With the VC++ code, you used OS services to send the data to the 'raw' device, which makes it allowable.

    I'm not a hardware expert, but that's the likely issue.

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Dovel, why are you using that stupid compiler?? only joking. It works on visual, so I don't see what's wrong with using that. (your laptop doesn't have a parallel port ... ) ask richie, it's something about conio.h not being standardised

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I've never actually done it... but I've done a tiny bit of research on the subject. Maybe you can find something on this site.

    You might post your question on the Windows forum too. This is a platform-specific issue, and there's probably someone there who knows the secret! <<< EDIT- ...Or, maybe not. I just did a quick search, and all I found was a suggestion to use CreateFile() with no details... Maybe you can find the details of how to use CreateFile() for an I/O port on MSDN ???? >>>

    I think you can open the port using file I/O commands, but I don't know the details.

    Stuka is right. Windows NT, 2K, or XP prevents a user mode program from directly accessing an I/O or memory address. A kernel mode (driver) program can do it, but writing drivers is an advanced topic.

    I once wrote a program to make sounds by writing to the internal speaker's hardware. It works on Win98, but I get some sort of "access violation" error when I run the program on a modern Windows system. If all else fails, can you use Win98 for your project?

    Once you find the solution, it should work on Dev-C++ or Windows... The standard WinAPI functions should work in Dev-C++.
    Last edited by DougDbug; 01-10-2006 at 05:34 PM.

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, 08: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, 04:59 PM