|
[ pc 与usb 传输 writefile问题 ]vc 6.0关于usb传输的几个问题
[复制链接]
1我们用的是usbaudio.sys驱动程序
2vc 6.0开发pc端程序 已用createfile(异步打开)成功获取usb句柄在writefile的时候出现问题
返回的错误代码是87
下面是可能出现的错误代码,请各位指教下出错的地方
另外就是如何获取usbaudio.sys提供的函数接口
用google怎么也搜不到合适的
/***********************************************************************************/
DWORD dwWrite=0;
DWORD dwTimerout=20;
OVERLAPPED ovInternal;
ovInternal.Offset = 0;
ovInternal.OffsetHigh = 0;
memset(&ovInternal,0,sizeof(OVERLAPPED));
//set up a overlapped event
//创建异步标志
ovInternal.hEvent=CreateEvent(
NULL,
TRUE,
FALSE,
NULL);
if(NULL==ovInternal.hEvent)
{
return ;
}
LPOVERLAPPED lpOverlapped;
lpOverlapped=&ovInternal;
//给pData指向的内存赋值
int* pData=NULL;
int iLen=200;
pData=new int[200];
memset(pData,256,4);
int a[200]={1,7,20,3,5,6,7,10,20,30,56,12,98,89,78,17,0,1,18};
pData=a;
for(int i=0;i<200;i++)
{
*pData++=a;
}
int p=*pData;
pData=a;
BOOL b;
LPDWORD pdwWrite=NULL;
//write data to usb
//串口的异步通信
COMSTAT ComStat;
DWORD dwErrorFlags;
ClearCommError(hwrite,&dwErrorFlags,&ComStat);
//出错的地方
if(!WriteFile(hwrite,pData,iLen,&dwWrite,lpOverlapped))
{
long lLastError=::GetLastError();
if(lLastError!=ERROR_IO_PENDING)
{
int o=0;
return;
}
/***********************************************************************/
else
//
{
switch(::WaitForSingleObject(ovInternal.hEvent,dwTimerout))
{
//返回指定的异步操作对象的结果
b=::GetOverlappedResult(hwrite,lpOverlapped,pdwWrite,TRUE);
//指定的对象处于有信号状态
case WAIT_OBJECT_0:
if(!b)
{
return ;
}
break;
//时间超时指定对象处于无信号状态
case WAIT_TIMEOUT:
::CancelIo(hwrite);
break;
default:
::CancelIo(hwrite);
break;
}
}
}
// if( pData!=NULL)
// delete pData;
CloseHandle(hwrite);
}
|
|