Link to home
Start Free TrialLog in
Avatar of rdno
rdno

asked on

Access parallel port directly in NT 4 (1000 pts)

I'm writing a driver for a special device on the parallel port of the computer, does anyone have a start for me like some sample code for a kernel mode device driver enabling to access the parport through a dll function? Oh and by the way Createfile("lpt1",....) is not the way it's going to work, I need something like the good old dos inport, outport

thanks in regard of your answer
    - Raymond

btw I'm offering a 1000 points for the right answer!!! I'll first check the answers. If the information suits my needs you're the lucky winner of the jackpot!
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW: If you really want to write your own driver, the NT DDK comes with various driver sawmples, which also contain a sample parralel port driver. The DDK can be found at http://www.microsoft.com/hwdev/ddk/
Hmmm - if yo uhave difficulties locating the parallel port driver sample, it can be found at
%BASEDIR%\src\comm\parport
after installing the DDK...
Avatar of rdno
rdno

ASKER

yeak I found it, but I'm totally new to device driver programming. I got the ddk already, do you know if it's possible to use the ddk kit from withing the VC++?
Avatar of rdno

ASKER

oh and I downloaded the kit already, before you mentioned, but it has to be my own device driver, It's for a school project. Even my teacher don't know how to program the parport in NT
and can you give me the way to make an device driver installer, can it be done with installshield for Vc++ enterprice?
Avatar of rdno

ASKER

do you know where the parlog.rc is located?
Avatar of rdno

ASKER

damn, do I need another ddk or SDK?
Avatar of rdno

ASKER

damn, do I need another ddk or SDK?
Hmm, sorry for the delay, but it's Europe here and half past midnight meanwhile ;-)

No, you need nothing else but the DDK and VC++. There's a .bat file in the %BASEDIR%\bin directory that sets the environment properly - you'll have to call it from the console window from where you run the 'build' command. (Hmm, being at home now, I don't have a DDK here, so please bear with me - I don't know the directory structure of the samples by heart...)
>>can you give me the way to make an device driver
>>installer, can it be done with installshield for Vc++
>>enterprice?

Yes, it can be done - all you need is the 'instdrv' sample, which installs a driver.  This one can be caled from your setup script in order to install the driver (maybe you'll need a wrapper DLL, so feel free to ask if so - been there, done that...)


But as this is a school project, I highly recommend using the package I mentioned earlier. I do SWDEV for my living, and I have to say that it's quite a *lot* of work to be able to write a stable driver...
Well, being back at work, I have acces to my links again ;-)

Be sure to check out

http://www.lvr.com/parport.htm#Programming

on this issue...


BTW: The parport.rc file resides in the same directory as the sample...

Oh, yes, and the environment is set up by calling

%SystemRoot%\SYSTEM32\cmd.exe /k %BASEDIR%\bin\setenv.bat %BASEDIR% free
Avatar of rdno

ASKER

damn, I get only this message

C:\DDK\bin>setenv c:\ddk
Error: MSTOOLS environment variable not recognized.
       The Win32 SDK must be installed.

C:\DDK\bin>

well about the school project... it has to be my own work.. not any 3rd party software
Aaah - the problem is that this batch file is looking for the 'normal' SDK or the Platform SDK, which can be found at
http://msdn.microsoft.com/downloads/sdks/platform/default.asp

Since you're using VC++, simply locate a 'setenv.bat' file in it's directory structure and

set MSTOOLS=<path to 'setenv.bat' without filename>

but, to be honest,

set MSTOOLS=trash

will also remedy the problem ;-)
.. which allows direct hardware access under NT

------------------------------------

"jkr" are you sure about this?  My entire understanding of NT is that it purposefully prevents someone from expressly doing something like this.  That's my understanding why the Hardware Abstraction Layer exist in the first place.
>>"jkr" are you sure about this?  

Of course - but I should have added 'on Intel machines'.

This package is simply a KMode driver that has a call interface which allows user mode applications to request direct port I/O and to retrieve the results.

>>My entire understanding of NT is that
>>it purposefully prevents someone from
>>expressly doing something like this

You're right - but only if 'someone' isn't a kernel mode driver ;-)

You can even have user mode code executed at Ring 0:

    case    IRP_MJ_DEVICE_CONTROL:

            // Make sure this is a valid IOCTL for us...
            if  (       IOCTL_KE_EXEC
                    !=  pIos->Parameters.DeviceIoControl.IoControlCode
                )
                {
                    ntStatus    =   STATUS_INVALID_PARAMETER;
                }
             else
                {
                    // Get the pointer to the function to call
                    VOID ( *pfnUserFuncToCall)( PULONG) =   pIrp->UserBuffer;
                    // And the argument to pass
                    PVOID   pvUserArg;

                    pvUserArg   =   pIos->Parameters.DeviceIoControl.Type3InputBuffer;

                    // Call user's function with the parameter
                    if  (   pfnUserFuncToCall)
                        {
                            DbgPrint    (   "KeExec.SYS: pfnUserFuncToCall == 0x%8.8x, arg == 0x%8.8x\n",
                                            pfnUserFuncToCall,
                                            pvUserArg
                                        );

                            ( pfnUserFuncToCall)    ( pvUserArg);

                        }

                    ntStatus    =   STATUS_SUCCESS;
                }

            break;



Avatar of rdno

ASKER

Damn microsoft... i tried to download the SDK, but after 30 retries it only gave the error message file not found, I'll try to download it on a much faster connection....
Avatar of rdno

ASKER

and redirect mstools to itself, it ended with:

C:\>set MSTOOLS=c:\ddk\bin

C:\>cd %mstools%

C:\DDK\bin>setenv

usage: setenv <directory> [free|checked]

  Example:  setenv d:\ddk checked     set checked environment
  Example:  setenv d:\ddk             defaults to free environment


C:\DDK\bin>setenv c:\ddk
******  B A T C H   R E C U R S I O N  exceeds STACK limits ******
Recursion Count=1267, Stack Usage=90 percent
******       B A T C H   PROCESSING IS   A B O R T E D      ******

C:\DDK\bin>set mstools=trash

C:\DDK\bin>setenv c:\ddk
The system cannot find the path specified.
Avatar of rdno

ASKER

I'm going to reinstall NT 4 on a clean partition, just with the SDK, DDK and VC++
>>C:\>set MSTOOLS=c:\ddk\bin

This will lead to an infinite recursion...

You don't have to do that ;-)

Simply close the console window and open a new one...
set MSTOOS=something
setenv c:\ddk free

should do it - if you examine the batch file, you'll see that it only tries to set the SDK evironment before it sets the DDK environment. And as the SDK environment is already set in your global system environment, this is obsolete...
"jkr" you remind me a lot of Scott Meyers!  Both of you are radicals when it comes to probing the software boundaries, and who knows the territory very well.
Avatar of rdno

ASKER

jkr.... I think you know the answer on my problem, if I give you the points, do you want to help me further when I need it by mail?
If so, I would be glad, cuz I am totally new to driver development, but it has to B done!

   - Raymond
>>if I give you the points, do you want
>>to help me further when I need it by
>>mail?

Sure, no problem...
Avatar of rdno

ASKER

OK. tnx.
send a mail to rdno@chello.nl
and we go on by mail..
On the way ;-)