inpout32.dll function help

This is a discussion on inpout32.dll function help within the C++ Programming forums, part of the General Programming Boards category; Hallo I am having trouble with a small piece of code that I have downloaded from the internet. The code ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

    inpout32.dll function help

    Hallo

    I am having trouble with a small piece of code that I have downloaded from the internet. The code is the example program for "inpout32.dll"

    The thing I am trying to find out is how to use following commands in an other project.
    Code:
    short _stdcall Inp32(short PortAddress);
    void _stdcall Out32(short PortAddress, short data);
    The project is for VC++, but I would prefer to work in dev-cpp. Is that possible without recompiling a whole lot of stuff?

    Here is the rest of the code:
    Code:
    // InpoutTest.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include "stdio.h"
    #include "string.h"
    #include "stdlib.h"
    #include <iostream>
    /* ----Prototypes of Inp and Outp--- */
    
    short _stdcall Inp32(short PortAddress);
    void _stdcall Out32(short PortAddress, short data);
    
    /*--------------------------------*/
    
    int main(int argc, char* argv[])
    {
    
    	int data;
    
    	if(argc<3)
    	{
    		//too few command line arguments, show usage
    		printf("Error : too few arguments\n\n***** Usage *****\n\nInpoutTest read <ADDRESS> \nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n");
    	} 
    	else if(!strcmp(argv[1],"read"))
    	{
    
    		data = Inp32(atoi(argv[2]));
    
    		printf("Data read from address %s is %d \n\n\n\n",argv[2],data);
    	
    	}
    	else if(!strcmp(argv[1],"write"))
    	{
    		if(argc<4)
    		{
    			printf("Error in arguments supplied");
    			printf("\n***** Usage *****\n\nInpoutTest read <ADDRESS> \nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n");
    		}
    		else
    		{
    		Out32(atoi(argv[2]),atoi(argv[3]));
    		printf("data written to %s\n\n\n",argv[2]);
    		}
    	}
    
        int stuff;
    	std::cin >> stuff;
    	return 0;
    }
    Thank you for your time

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What exactly is the problem you are having, you don't say in your post? [It's quote common to know what you yourself is talking about, but others don't!]

    --
    Mats

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    What exactly is the problem you are having, you don't say in your post? [It's quote common to know what you yourself is talking about, but others don't!]
    That why they try to force you to re-read your own essays from when you learn to write utile you die. Sorry for that.

    I am going to use the .dll file on a older computer without VC++, so is there some way to make that code work in dev-cpp? I only need the Inp32/Out32 functions.
    When I try to compile it in de-cpp right now I get "unknown reference to 0576363@23"

    (Dont remember to exact number now, sorry)

    Hope it makes more sense now, time for bed soon

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If all you want to do is some simpl IN/OUT instructions, it seems completely overkill to link with a DLL. I found this snipped about linking with DLL's. http://www.cygwin.com/cygwin-ug-net/dll.html

    How about using (unportable) inline assembler instead? Something like this:

    Code:
    typedef unsigned char byte;
    typedef unsigned short word;
    typedef unsigned long dword;
    
    byte inb(word port) {
        byte res;
        __asm__ __volatile__("in %dx,%al": "=a"(res):"d"(port));
       return res;
    }
    
    word inw(word port) {
        word res;
        __asm__ __volatile__("in %dx,%ax": "=a"(res):"d"(port));
       return res;
    }
    
    word inl(word port) {
        word res;
        __asm__ __volatile__("in %dx,%eax": "=a"(res):"d"(port));
       return res;
    }
    
    void outb(word port, byte val) {
        __asm__ __volatile__("out %al,%dx"::"a" (val), "d"(port));
    }
    
    void outw(word port, word val) {
        __asm__ __volatile__("out %ax,%dx"::"a" (val), "d"(port));
    }
    
    
    void outl(word port, dword val) {
        __asm__ __volatile__("out %eax,%dx"::"a" (val), "d"(port));
    }
    It's been a few weeks since I last did inline assembler in gcc, but I think that should compile and work correctly.

    --
    Mats

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Thank you, but the thing is that I have never touched assembly before. I hardly know basic c++.

    Can I past the code from you post into a header file and use it in my project? Or does I have to do something else?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, you can paste that into either a header or a .c(pp) file (and create prototypes in a .h file).

    If you use it in a header, I would suggest adding "static inline" before each function, which will mean to the compiler "don't keep a copy of this function unless someone is calling it, and if possible, just stuff the code in where the call is".

    I suspect that there are some Linux header files that contains these as macros/inline functions.

    If you are planning to learn about hardware and "direct access to io-devices", I think you will need some understanding of assembler.

    --
    Mats

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    If you are planning to learn about hardware and "direct access to io-devices", I think you will need some understanding of assembler.
    Not in any near future. Right now im learning cpp and are more than happy with that. I only need to open and close parallel ports. Which turned into a real pain in winXP.

    Thanks for you great help. I will try it out tomorrow morning.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    I did not get the above code to work. It is probably my fault, as I have never touched assembly before.

    So here I am, asking to be spoon feed.

    Code:
    #include <iostream>
    
    
    using namespace std;
    
    
    typedef unsigned char byte;
    typedef unsigned short word;
    typedef unsigned long dword;
    
    byte inb(word port) {
        byte res;
        __asm__ __volatile__("in %dx,%al": "=a"(res):"d"(port));
       return res;
    }
    
    word inw(word port) {
        word res;
        __asm__ __volatile__("in %dx,%ax": "=a"(res):"d"(port));
       return res;
    }
    
    word inl(word port) {
        word res;
        __asm__ __volatile__("in %dx,%eax": "=a"(res):"d"(port));
       return res;
    }
    
    void outb(word port, byte val) {
        __asm__ __volatile__("out %al,%dx"::"a" (val), "d"(port));
    }
    
    void outw(word port, word val) {
        __asm__ __volatile__("out %ax,%dx"::"a" (val), "d"(port));
    }
    
    
    void outl(word port, dword val) {
        __asm__ __volatile__("out %eax,%dx"::"a" (val), "d"(port));
    }
    
    main()
    {
          system ("PAUSE");
          return 0;  
    }
    Thats "my" code, just to check if I can get it to compile.

    The error I get is:
    In function `byte inb(word)':
    operand number missing after %-letter
    operand number missing after %-letter
    What do I need to do to make it work?

    I have not added anything in the project settings which says I use assembly, do I have to do that in some way maybe?

    Using Dev-c++ 4.9.9.2

    Sorry for posting a follow up question so late, but summer is here and I have been in Turkey for a while.

    Thanks for all help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

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