Solved

Access parallel port directly in NT 4 (1000 pts)

Posted on 2000-03-05
25
303 Views
Last Modified: 2013-11-14
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!
0
Comment
Question by:rdno
  • 12
  • 11
  • 2
25 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 2585808
See the 'Sybera Hardware Access' Kit at http://www.sybera.de/home.htm which allows direct hardware access under NT without developing your own driver. Can be downloaded for free at http://www.sybera.de/download/sha.exe
0
 
LVL 86

Expert Comment

by:jkr
ID: 2585817
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/
0
 
LVL 86

Expert Comment

by:jkr
ID: 2588771
Hmmm - if yo uhave difficulties locating the parallel port driver sample, it can be found at
%BASEDIR%\src\comm\parport
after installing the DDK...
0
 

Author Comment

by:rdno
ID: 2589187
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++?
0
 

Author Comment

by:rdno
ID: 2589195
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?
0
 

Author Comment

by:rdno
ID: 2589210
do you know where the parlog.rc is located?
0
 

Author Comment

by:rdno
ID: 2589312
damn, do I need another ddk or SDK?
0
 

Author Comment

by:rdno
ID: 2589349
damn, do I need another ddk or SDK?
0
 
LVL 86

Expert Comment

by:jkr
ID: 2589540
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...)
0
 
LVL 86

Expert Comment

by:jkr
ID: 2589551
>>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...
0
 
LVL 86

Expert Comment

by:jkr
ID: 2591476
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
0
 

Author Comment

by:rdno
ID: 2592713
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
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 86

Expert Comment

by:jkr
ID: 2592844
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 ;-)
0
 
LVL 3

Expert Comment

by:Try
ID: 2593066
.. 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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 2593192
>>"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;



0
 

Author Comment

by:rdno
ID: 2593283
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....
0
 

Author Comment

by:rdno
ID: 2593293
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.
0
 

Author Comment

by:rdno
ID: 2593298
I'm going to reinstall NT 4 on a clean partition, just with the SDK, DDK and VC++
0
 
LVL 86

Expert Comment

by:jkr
ID: 2593316
>>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...
0
 
LVL 86

Expert Comment

by:jkr
ID: 2593327
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...
0
 
LVL 3

Expert Comment

by:Try
ID: 2594030
"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.
0
 

Author Comment

by:rdno
ID: 2595358
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 2595896
>>if I give you the points, do you want
>>to help me further when I need it by
>>mail?

Sure, no problem...
0
 

Author Comment

by:rdno
ID: 2596341
OK. tnx.
send a mail to rdno@chello.nl
and we go on by mail..
0
 
LVL 86

Expert Comment

by:jkr
ID: 2596774
On the way ;-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Installations often have prerequisites, such as “Microsoft .Net framework is required for this product”. The usual implementation in MSI installations is system search for a particular registry setting representing the required prerequisite, followe…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now