驱动中牛
|
阅读:5127回复:17
TWAIN\WIA的驱动是怎么使用USBScan.sys地
TWAIN\WIA的驱动是怎么使用USBScan.sys的
是不是通过createfile进行读写数据呢,还是别的方式 再就是怎么在inf中指定我的driver适用的就是usbscan.sys呢? 高手、大牛请指教! |
沙发#
发布于:2007-10-23 17:10
wowking
|
|
|
板凳#
发布于:2007-10-23 17:13
//Create by WangSheng Since 2003-8-25
//Dymamic Link Library Have Some Problem,So Used Hide Mode Link 2003-8-29 #ifndef _INC_DEVICE_H #define _INC_DEVICE_H #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ //Description: Get Device State //Parameter: //Return: 0-No Pape // 1-Device Ok // 2-Device is not exist _declspec(dllexport) int GetScanState(); //Description: Set Scan Attribute //Parameter: //Return: false-Set Ok // true-Set Wrong _declspec(dllexport) BOOL SetScanAttribute(USHORT Cmd,USHORT Par); //Description: Read User Code //Parameter: Usercode Buffer //Return: Boolean _declspec(dllexport) BOOL GetDevUserCode(LPBYTE lpBuf); //Description: Set Block Size //Parameter: Block Size //Return: Boolean _declspec(dllexport) BOOL SetBlockSize(ULONG ulBlockSize); //Description: Read Scan Data //Parameter: // Receive Data Buffer // Buffer Length //Return: Get Data Length _declspec(dllexport) DWORD GetScanData(LPBYTE lpBuf,DWORD dwBufSize); #ifdef __cplusplus } #endif /* cplusplus */ #endif _INC_DEVICE_H |
|
|
驱动中牛
|
地板#
发布于:2007-10-23 17:14
呵呵,谢谢你的回复,好像没有看明白耶,
|
地下室#
发布于:2007-10-23 17:15
扫描得到自己的数据然后填充到剪切板上,目的就是为了在twain中显示自己的图像
|
|
|
驱动中牛
|
5楼#
发布于:2007-10-23 17:16
//Description: Get Device State
//Parameter: //Return: 0-No Pape // 1-Device Ok // 2-Device is not exist _declspec(dllexport) int GetScanState(); //Description: Set Scan Attribute //Parameter: //Return: false-Set Ok // true-Set Wrong _declspec(dllexport) BOOL SetScanAttribute(USHORT Cmd,USHORT Par); //Description: Read User Code //Parameter: Usercode Buffer //Return: Boolean _declspec(dllexport) BOOL GetDevUserCode(LPBYTE lpBuf); //Description: Set Block Size //Parameter: Block Size //Return: Boolean _declspec(dllexport) BOOL SetBlockSize(ULONG ulBlockSize); //Description: Read Scan Data //Parameter: // Receive Data Buffer // Buffer Length //Return: Get Data Length _declspec(dllexport) DWORD GetScanData(LPBYTE lpBuf,DWORD dwBufSize); 这些函数就是Twain自动调用USBScan.sys 来控制Scanner的吗 |
6楼#
发布于:2007-10-23 17:17
我是自己做了一个dll,调用sys,在twain中调用自己的dll,明白了么?
Device.h就是我自己的dll的导出函数 |
|
|
驱动中牛
|
7楼#
发布于:2007-10-23 17:20
呵呵,可能俺太笨了,我知道您是导出了几个供外部调用的函数接口,但俺还没有明白Twain 是怎么自动从Scanner 上获取数据的,
|
8楼#
发布于:2007-10-23 17:21
彻底曝光代码:
以下为dll中的一个导出函数: //////////////// //Description: Open the Device //Parameter: //Return: Device Handle HANDLE OpenDevice(DWORD dwInstance, PDWORD pdwError) { HANDLE hDev; // Class GUID used to open device // GUID ClassGuid = SnUSBDevice_CLASS_GUID;// Class GUID used to open device CDeviceInterfaceClass DevClass(&ClassGuid, pdwError); if(*pdwError != ERROR_SUCCESS) return INVALID_HANDLE_VALUE; CDeviceInterface DevInterface(&DevClass, dwInstance, pdwError); if(*pdwError != ERROR_SUCCESS) return INVALID_HANDLE_VALUE; hDev = CreateFile( DevInterface.DevicePath(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if(hDev == INVALID_HANDLE_VALUE) *pdwError = GetLastError(); return hDev; } //////////////////// //Description: Get Device User Code //Parameter: Usercode Buffer //Return: Boolean BOOL GetDevUserCode(LPBYTE lpBuf) { DWORD dwError; DWORD dwIO; BOOL bReturn=FALSE; CString str; HANDLE hDev = OpenDevice(0, &dwError); if(hDev != INVALID_HANDLE_VALUE) { UCHAR ucCode[16]; ZeroMemory(ucCode, sizeof(ucCode)); if(DeviceIoControl( hDev, SNUSB_IOCTL_READ_DATA, NULL, 0, ucCode, sizeof(ucCode), &dwIO, NULL)) { bReturn=TRUE; } else { bReturn=FALSE; } memcpy(lpBuf,ucCode,sizeof(ucCode)); CloseHandle(hDev); } return bReturn; } |
|
|
驱动中牛
|
9楼#
发布于:2007-10-23 17:25
太谢谢您了,这不还是用createfile 来进行通讯的,我明白了,您的一小步,人类的一大步,谢谢您了,
|
驱动中牛
|
10楼#
发布于:2007-10-23 17:26
您就是中国的比尔盖茨,谢谢啦,
|
驱动中牛
|
11楼#
发布于:2007-10-23 17:26
by the way, WIA的也是这种方式吗
|
12楼#
发布于:2007-10-23 17:30
rrr,真不知道你是在夸人还是在贬人!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
驱动中牛
|
13楼#
发布于:2007-10-23 17:54
我可是诚心诚意的, 真心的吆
|
驱动中牛
|
14楼#
发布于:2007-10-24 07:49
|
驱动中牛
|
15楼#
发布于:2007-10-24 07:51
看来打印机也是使用这种方式来调用 USBPrint.sys了,我明白了,谢谢您了,
我能不能做一个scanner的驱动,使他既符合Twain 又符合WIA呢,请指教! |
驱动中牛
|
16楼#
发布于:2007-10-24 11:33
怎么没人理呢
|
17楼#
发布于:2010-03-04 11:42
楼上大侠,你现在即符合wia又符合TWAIN的驱动做好了吗?
我想问下我有个wia的驱动,如何改成符合TWAIN的方式呢? |
|