Is it windows bug ? Callback routine get wrong argument ?!

Discussion in 'Windows Vista Drivers' started by SL Chang, Jul 25, 2005.

  1. SL Chang

    SL Chang Guest

    It's a strange problem.
    I use IoQueueWorkItem( ) and pass a structure DATA to it's callback routine
    ROUTINE_XXX.
    ROUTINE_XXX get pointer by argument Context.
    But I always can't catch correct data from DATA, so I check the address of
    variable and find an interesting thing.
    The address of DATA and Context are different !
    That's why I can't get correct data inside ROUTINE_XXX.
    I have no idea about this strange situation.
    Could anyone give me a hint?
     
    SL Chang, Jul 25, 2005
    #1
    1. Advertisements

  2. SL Chang

    Don Burn Guest

    Post some code here, this description is useless except to indicate that you
    are doing something wrong.
     
    Don Burn, Jul 25, 2005
    #2
    1. Advertisements

  3. I suppose your IO_WORKITEM is not allocated on stack?
     
    Alexander Grigoriev, Jul 25, 2005
    #3
  4. SL Chang

    SL Chang Guest

    Driver is base on USBCAMD code inside DDK sample.
    Before I replace ExXxxxWorkItem with IoXxxxWorkItem, the address is match
    and data is correct too.
    I don't know why.

    ////////////////////////////////////////////////////////////////////////////
    /////////////////////
    typedef struct _USBCAMD_WORK_ITEM {
    PIO_WORKITEM WorkItem;
    PUSBCAMD_READ_EXTENSION Request;
    PUSBCAMD_CHANNEL_EXTENSION ChannelExtension;
    ULONG StreamNumber;
    BOOLEAN CopyFrameToStillPin;
    NTSTATUS status;
    PHW_STREAM_REQUEST_BLOCK Srb;
    } USBCAMD_WORK_ITEM, *PUSBCAMD_WORK_ITEM;
    ////////////////////////////////////////////////////////////////////////////
    /////////////////////
    ROUTINE_A(...) {
    PUSBCAMD_WORK_ITEM usbWorkItem;
    usbWorkItem = (PUSBCAMD_WORK_ITEM) USBCAMD_ExAllocatePool(NonPagedPool,
    sizeof(USBCAMD_WORK_ITEM));
    if (usbWorkItem) {
    usbWorkItem->WorkItem = IoAllocateWorkItem(
    ChannelExtension->DeviceExtension->SCDeviceObject);
    usbWorkItem->Request = NULL;
    usbWorkItem->ChannelExtension = ChannelExtension;
    usbWorkItem->status = ntStatus;
    DbgPrint("Address before callback routine = %x\n", usbWorkItem);
    if (usbWorkItem->WorkItem && !IsStop) {
    IoQueueWorkItem(usbWorkItem->WorkItem,
    (PIO_WORKITEM_ROUTINE)
    USBCAMD_ProcessStillReadWorkItem,
    DelayedWorkQueue,
    usbWorkItem);
    }
    else
    ExFreePool(usbWorkItem);
    }
    }
    }
    ////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////
    VOID USBCAMD_ProcessStillReadWorkITem(PVOID Context) {
    PUSBCAMD_WORK_ITEM usbWorkItem = (PUSBCAMD_WORK_ITEM) Context;

    //--------------------------------------------------------------------------
    ----
    // here get wrong structure context and address isn't match also.
    //--------------------------------------------------------------------------
    ----
    DbgPrint("Address inside callback routine = %x\n", Context);

    // do something ...

    IoFreeWorkItem(usbWorkItem->WorkItem);
    }
     
    SL Chang, Jul 26, 2005
    #4
  5. SL Chang

    cristalink Guest

    Apparently you use an explicit cast to shut up the compiler that warned you
    about the type mismatch.

    (PIO_WORKITEM_ROUTINE) USBCAMD_ProcessStillReadWorkItem

    It must be
    VOID
    USBCAMD_ProcessStillReadWorkItem (
    IN PDEVICE_OBJECT DeviceObject,
    IN PVOID Context
    );
     
    cristalink, Jul 26, 2005
    #5
  6. SL Chang

    SL Chang Guest

    Bingo !
    You are right.
    I miss 1 argument in callback routine.

    Thank you :)
     
    SL Chang, Jul 26, 2005
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.