阅读:1261回复:5
看驱动开发书后几个不明白的地方,还望大虾们指点
我的理解,驱动和应用程序之间的联系为:由CReatFile获取设备句柄,然后就可以
对设备操作,然后用DeviceIoControl或ReadFile/WriteFile等具体实施操作。 问1:在驱动中,由什么函数来对应上述函数以完成I/O操作?我的意思是:比如我要对一 端口(如EPP)写,驱动中用什么函数来完成实际的对端口的写呢? 问1续:我看到有些用KIoRange类,里面用inputb和outputb来操作硬件读写,这个行得通 否? 问2:对DeviceIoControl,我看了下,其参数中只有写的地址,无写的内容,那么写的内 容(数据)在哪里体现呢?比如我要对EPP数据寄存器写个数,如何操作? 问3:操作系统都会自带类驱动和迷你驱动,比如并口。那么,我们是不是可以利用它, 直接编写应用程序调用呢?如果可以,那么如何操作? |
|
沙发#
发布于:2004-11-20 11:15
问2:对DeviceIoControl,我看了下,其参数中只有写的地址,无写的内容,
你象理解错了 ! DeviceIoControl The DeviceIoControl function sends a control code directly to a specified device driver, causing the corresponding device to perform the corresponding operation. BOOL DeviceIoControl( HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped ); Parameters hDevice [in] Handle to the device on which the operation is to be performed. The device is typically a volume, directory, file, or stream. To retrieve a device handle, use the CreateFile function. For more information, see Remarks. dwIoControlCode [in] Control code for the operation. This value identifies the specific operation to be performed and the type of device on which to perform it. For a list of the control codes, see Remarks. The documentation for each control code provides usage details for the lpInBuffer, nInBufferSize, lpOutBuffer, and nOutBufferSize parameters. lpInBuffer [in] Pointer to the input buffer that contains the data required to perform the operation. The format of this data depends on the value of the dwIoControlCode parameter. This parameter can be NULL if dwIoControlCode specifies an operation that does not require input data. nInBufferSize [in] Size of the input buffer, in bytes. lpOutBuffer [out] Pointer to the output buffer that is to receive the data returned by the operation. The format of this data depends on the value of the dwIoControlCode parameter. This parameter can be NULL if dwIoControlCode specifies an operation that does not return data. nOutBufferSize [in] Size of the output buffer, in bytes. lpBytesReturned [out] Pointer to a variable that receives the size of the data stored in the output buffer, in bytes. If the output buffer is too small to receive any data, the call fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and lpBytesReturned is zero. If the output buffer is too small to hold all of the data but can hold some entries, some drivers will return as much data as fits. In this case, the call fails, GetLastError returns ERROR_MORE_DATA, and lpBytesReturned indicates the amount of data received. Your application should call DeviceIoControl again with the same operation, specifying a new starting point. If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation returns no output data and lpOutBuffer is NULL, DeviceIoControl makes use of lpBytesReturned. After such an operation, the value of lpBytesReturned is meaningless. If lpOverlapped is not NULL, lpBytesReturned can be NULL. If this parameter is not NULL and the operation returns data, lpBytesReturned is meaningless until the overlapped operation has completed. To retrieve the number of bytes returned, call GetOverlappedResult. If hDevice is associated with an I/O completion port, you can retrieve the number of bytes returned by calling GetQueuedCompletionStatus. lpOverlapped [in] Pointer to an OVERLAPPED structure. If hDevice was opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored. If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredictable ways. For overlapped operations, DeviceIoControl returns immediately, and the event object is signaled when the operation has been completed. Otherwise, the function does not return until the operation has been completed or an error occurs. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. |
|
板凳#
发布于:2004-11-20 11:47
恩,兄台说得对,不是我理解错了,实在是我c/c++太菜,没能理解。
不过还是谢谢了哈! |
|
地板#
发布于:2004-11-20 15:17
问(1):
我觉得不是某一个单独的函数完成数据的读写的, 如果你用的是buffered io 那么主要是由RtlCoppyMem()(好像写错了,呵呵)完成数据的读写阿, 如果用的是direct io呢,只要你设置好传输的环境, (主要是对硬件寄存器的编程,) 由硬件自动完成传输了! 答的不好, 但希望对你有所帮助! :D |
|
|
地下室#
发布于:2004-11-21 13:32
还是感谢aiwadgj网友!
我的本意是找驱动程序最底层中对硬件端口操作的具体函数 在DDK中已经找到了,是WRITE(READ)_PORT_UCHAR等 不过还是很感谢你哈! |
|
5楼#
发布于:2004-11-21 13:51
我晕哦,这个系统同一帖给分只能一次么?想给都还给不出去哈,虽然分不多!
|
|