最近在做USB3.0控制传输,使用new实例化了类CCyUSBDevice,但是发现new之后该类中的指针,有的为空,有的不为空,这是为什么呢?
void send_control_cmd(unsigned char cmd, unsigned char *buf, LONG buflen)
{
CCyUSBDevice* ppUSB = new CCyUSBDevice;
CCyControlEndPoint *ept = ppUSB->ControlEndPt; //new之后ppUSB->ControlEndPt为空,导致下面的赋值操作出错
ept->Target = TGT_DEVICE; //不必关注,固定
ept->ReqType = REQ_VENDOR; //请求类型:自定义请求(标准请求等)
ept->Direction = DIR_TO_DEVICE; //传输方向:主机->usb设备(out)
ept->ReqCode = cmd; //自定义请求码
ept->Value = 0; //这里的设定值将传给setupdat的[2:3]位 wValue
ept->Index = 0; //这里的设定值将传给setupdat的[4:5]位 wIndex
ept->Write(buf,buflen);
delete ppUSB;
}
类CCyUSBDevice的部分定义为:
class CCyUSBDevice
{
/* The public members are accessible (i.e. corruptible) by the user of the library
* Algorithms of the class don't rely on any public members. Instead, they use the
* private members of the class for their calculations. */
public:
CCyUSBDevice(HANDLE hnd = NULL, GUID guid = CYUSBDRV_GUID, BOOL bOpen = true);
~CCyUSBDevice(void);
CCyUSBEndPoint **EndPoints; /* Shortcut to USBCfgs[CfgNum]->Interfaces[IntfcIndex]->Endpoints */
CCyUSBEndPoint *EndPointOf(UCHAR addr);
CCyUSBBOS *UsbBos;
CCyIsocEndPoint *IsocInEndPt;
CCyIsocEndPoint *IsocOutEndPt;
CCyBulkEndPoint *BulkInEndPt;
CCyBulkEndPoint *BulkOutEndPt;
CCyControlEndPoint *ControlEndPt;
CCyInterruptEndPoint *InterruptInEndPt;
CCyInterruptEndPoint *InterruptOutEndPt;
.
.
.
}
单步调试,可以看到new之后类中的BulkInEndPt、BulkOutEndPt等不为空,但是ControlEndPt为空:
麻烦大神们帮忙看看,问题出在哪里,怎么解决指针为空的问题啊,多谢多谢!