From: Eric W Hanson [ehanson@microsoft.com] Sent: Tuesday, March 19, 2002 2:50 PM To: NT Developers Interest List Subject: [ntdev] Re: tdi SetEventHandler Your code is missing a couple of things. One is a call to TdiBuildReceiveDatagram the other is a call to SetNextIrpStackLocation. 1) set *BytesTaken = 0 2) Allocate an IRP 3) Pass the IRP to the TdiBuildReceiveDatagram() macro 4) Call SetNextIrpStackLocation() on the IRP. 5) Assign the IRP to *IoRequestPacket 6) return STATUS_MORE_PROCESSING_REQUIRED Some pseudo code would look like: PIRP irp; irp=IoAllocateIrp(...,False); TdiBuildReceiveDatagram(...); // Set the completion routine for the IRP here. SetNextIrpStackLocation(irp); // Necessary to advance the stack pointer. *IoRequestPacket=irp; *BytesTaken=0; return STATUS_MORE_PROCESSING_REQUIRED; Below is a sample completion routine for the above pseudo code. NTSTATUS IoCompletionAsync(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context) { IoFreeIrp(Irp); return STATUS_MORE_PROCESSING_REQUIRED; } Now the only thing missing would be a buffer to receive the data into. If your TDI Client allocates the buffer then it will be responsible for either freeing the buffer or reusing the buffer. This would be done in the completion routine before calling IoFreeIrp(). For the case where BytesIndicated == BytesAvailable you can still do steps 1-6 above or you can do the following steps: 1) Copy the data at Tsdu for the BytesIndicated 2) Set *BytesTaken = BytesAvailable 3) return STATUS_SUCCESS - Eric This posting is provided "AS IS" with no warranties, and confers no rights. -----Original Message----- From: sampo [mailto:jd1970@voila.fr] Sent: Tuesday, March 19, 2002 9:15 AM To: NT Developers Interest List Subject: [ntdev] Re: tdi SetEventHandler I try this but windows crash. Have you an example ? Thanks for your help. This is my code : /////////// /// Install Event Handler (Work Fine) pIrp=TdiBuildInternalDeviceControlIrp(TDI_RECEIVE_DATAGRAM,pDeviceObject ,pTdiTransportObject,NULL,NULL); if(pIrp==NULL) dStatus=STATUS_INSUFFICIENT_RESOURCES; else { TdiBuildSetEventHandler(pIrp,pDeviceObject,pTdiTransportObject,NULL,NULL ,TDI_EVENT_RECEIVE_DATAGRAM,RcvDatagram,NULL); dStatus=TdiCall(pIrp,pDeviceObject,&IoStatusBlock); } /////////////////// // Event Handler (crash) NTSTATUS RcvDatagram(IN PVOID TdiEventContext,IN LONG SourceAddressLength,IN PVOID SourceAddress,IN LONG OptionsLength, IN PVOID Options,IN ULONG ReceiveDatagramFlags,IN ULONG BytesIndicated,IN ULONG BytesAvailable, OUT ULONG *BytesTaken,IN PVOID Tsdu,OUT PIRP *IoRequestPacket) { static int BytesRcv=0; BytesRcv+=BytesIndicated; DbgPrint("BytesIndicated=%lu\n\r",BytesIndicated); DbgPrint("BytesAvailable=%lu\n\r",BytesAvailable); if(BytesRcv<10000) { //PIRP Test (global) Test=TdiBuildInternalDeviceControlIrp(TDI_RECEIVE_DATAGRAM,IoGetRelatedD eviceObject(pTdiTransportObject), pTdiTransportObject,NULL,NULL); if(Test==NULL) { DbgPrint("ERROR IoRequestPacket\n\r"); return STATUS_DATA_NOT_ACCEPTED; } else { IoRequestPacket=&Test; *BytesTaken=BytesIndicated; return STATUS_MORE_PROCESSING_REQUIRED; } } else return STATUS_SUCCESS; --- You are currently subscribed to ntdev as: ehanson@microsoft.com To unsubscribe send a blank email to %%email.unsub%% --- You are currently subscribed to ntdev as: GlennEverhart@FirstUSA.com To unsubscribe send a blank email to leave-ntdev-247T@lists.osr.com