prallel port programming

This is a discussion on prallel port programming within the Windows Programming forums, part of the Platform Specific Boards category; I am trying to write a program through which I can write data on parallel port. I am using VC++ ...

  1. #1
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118

    parallel port programming!!

    I am trying to write a program through which I can write data on parallel port. I am using VC++ express in windows 7. The program compiles fine and exe files are created with out any problem. But when I run the exe file a message box pop out saying "the program have stopped execution".
    I have tried to debug it with VC++. It generates anohter massage box saying "Unhandled exception at 0x013b1375 in test1.exe: 0xC0000096: Privileged instruction."
    I have googled for the solution and found that a file named "inpout32.dll" can provide me a solution. I have tried for the solution using this file. But this is still not working. What could be the reason?
    How can I resolve this problem?
    Should I have any particular driver to handle this?
    I anticipate that this inpout32.dll might work for ME/2000/Xp etc. But it is not working with win 7.
    Please Help!

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    Note to mods: this is not a C++ problem. It is better characterised as a windows programming problem.

    inpout32.dll (which, for other folks, is available here) works by installing a kernel mode driver the first time it is used on a NT family system. This means that, the first time it is used on a NT family system (NT/2000/xp), a program using inpout32.dll needs to be run from an account with administrative privileges, as unprivileged accounts cannot install kernel mode drivers. After that first run, it may be used from less privileged accounts.

    I've never had reason to use that DLL under windows 7, or under a 64-bit OS (simply because I've yet to encounter a computer with a parallel port that has either win7 or a 64-bit OS installed). In principle, it should work on a 32-bit windows 7 though - win7 is in the NT family.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  3. #3
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    I am the only user of this computer hence I am the administrator my self. Obviously I have the administrative privileges to install any kernel mode driver on my PC. But what the problem is that the program still after loading the inpout32.dll library is giving the same message box reporting the same error.

  4. #4
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    But this is not my answer. I know t that win 7 is a member of win NT family but still inpout is not working on it!

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    Well, you're going to need to give more information on how you are using the DLL in code, and how you are deploying it - both on your development machine, and on the target systems. A small test program that illustrates your problem, and a description of how you build and run that program, will help.

    You "anticipate" (your word) the DLL works on Me/2000/XP. Does that mean you have tested it on such systems? Or are you just assuming your program works correctly on those platforms, and wondering why it doesn't work on win7?

    The way you are using (or possibly misusing) the DLL is almost certainly a factor in your problem. And you have provided no relevant information about that. Folks in forums are not mindreaders, you know.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  6. #6
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    I first tried to run a simple program before writing a code for my hardware. Following is the code
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    void  _stdcall Out32(short PortAddress, short data);
    
    int main(void)
    {
    	Out32(0x37A,0x00A);      //I have linked my program to inpout.lib for Out32()'s definition.
    	return 0;
    }
    But when I changed the code to this
    Code:
    #include <Windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    typedef void (* Out32)(short PortAddress, short data);
    
    int main(void)
    {
    	Out32 out;
    	HINSTANCE HLib;
    	HLib=LoadLibrary(L"F:/inpout32.dll");
    	if(HLib==NULL)
    	{
    		printf("Error loading Library");
    		return 0;
    	}
    	out=(Out32)GetProcAddress(HLib,"Out32");
    	if(out==NULL)
    	{
    		printf("Error loading function");
    		return 0;
    	}
    	out(0x37A,0x00A);
    	FreeLibrary(HLib);    // <- error is occurring first at this line
    	
    	return 0;               // <- then after pressing continue same error occurs at this line
    }
    It started giving a new error!
    "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."
    Last edited by C_programmer.C; 02-19-2012 at 01:34 AM.

  7. #7
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    Quote Originally Posted by grumpy View Post
    You "anticipate" (your word) the DLL works on Me/2000/XP. Does that mean you have tested it on such systems? Or are you just assuming your program works correctly on those platforms, and wondering why it doesn't work on win7?
    No I didn't tried to run my program on any other operating system. But I did tried to run the available project from internet to run on my computer. But those project are also giving the same error. Despite they are using inpout32.dll and also its .lib version.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    The functions in inpout32.dll use the stdcall calling convention. Depending on compilation options (which you haven't specified) Out32 may not be a pointer to such a function. Try changing the typedef for Out32 to
    Code:
       typedef void _stdcall (*Out32)(short PortAddress, short data);
    Also .... if GetProcAddress() fails, it is a good ideal to call FreeLibrary(HLib) before exiting. It is probably not necessary to pass a long string to LoadLibrary().
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  9. #9
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    Well You say some thing like this
    Code:
    #include <Windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
     
    typedef void _stdcall (* Out32)(short PortAddress, short data); //Error:a calling convention may not be followed by a nested declarator
    int main(void)
    {
        Out32 out;
        HINSTANCE HLib;
        HLib=LoadLibrary("F:/inpout32.dll");   //Error: Can not convert const char* to LPCWSTR
        if(HLib==NULL)
        {
            printf("Error loading Library");
            return 0;
        }
        out=(Out32)GetProcAddress(HLib,"Out32");
        if(out==NULL)
        {
            printf("Error loading function");
            FreeLibrary(HLib);      //fine
            return 0;
        }
        out(0x37A,0x00A);
        FreeLibrary(HLib);
         
        return 0;
    Errors again!!

  10. #10
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    The calling convention goes inside the first set of brackets, before the *

  11. #11
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    The accepted location of the _stdcall modifier actually varies between compilers (and even compiler versions). One of those non-standard things that different vendors interpret differently (but, then again, so is use of DLLs).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  12. #12
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    yes! done
    Declaring the function in (_sydcall *) manner have solved the problem.
    Thanx a lot.

  13. #13
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    The programm is running fine but it is not giving any data at out put. I mean it is not writing the data at port's pins
    here is the code
    Code:
    #include <Windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    typedef void (_stdcall *Out32)(short PortAddress, short data);
    
    int main(void)
    {
    	int port=0x0378,data;
    	Out32 out;
    	HINSTANCE HLib;
    	HLib=LoadLibrary(L"F:/inpout32.dll");
    	if(HLib==NULL)
    	{
    		printf("Error loading Library");
    		return 0;
    	}
    	out=(Out32)GetProcAddress(HLib,"Out32");
    	if(out==NULL)
    	{
    		printf("Error loading function");
    		return 0;
    	}
    	while(port!=(-1))
    	{
    		scanf_s("%d%d",&port,&data);
    		out((short)port,(short)data);
    		printf("Data sent!\n");
    	}
    	//getche();
    	FreeLibrary(HLib);
    	
    	return 0;
    }
    I am giving the input as
    888 0
    888 255
    but there is no change in the out put. pins connected to the port are still at HIGH. giving 888 0 should let them low. but it is not!!

  14. #14
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    Assuming your circuit is wired correctly, there are various modes of the parallel port that disable outputs. For example, if the port supports PS/2 mode and bit 5 of the control port is set, all output to the data port is disabled.

    You're going to have to start reading up on various details of the parallel port. Have a look here for starters.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  15. #15
    Infant of C
    Join Date
    May 2010
    Location
    Karachi, Pakistan
    Posts
    118
    Well!!!!
    Today I took my program as well as the exe file to my academy to check whether the problem is with my PC, with my program or with the OS it self!!
    And my finding are same as I have anticipated!. the program works well and good in windows Xp. But in win 7 the programs runs with out any error. But neither writes any thing on the port nor it reads any thing from the port.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. port programming
    By Anuradh_a in forum C Programming
    Replies: 3
    Last Post: 03-19-2008, 03:23 PM
  2. port programming
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 11-20-2005, 06:53 AM
  3. I/O port programming in C???
    By shraddha in forum C Programming
    Replies: 1
    Last Post: 09-12-2005, 11:59 AM
  4. C++ I/O port programming????
    By shraddha in forum C++ Programming
    Replies: 2
    Last Post: 09-12-2005, 11:58 AM

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