How can I get the device name to call CreateFile() in my AVSTREAMminidriver's plug-in?

Discussion in 'Windows Vista Drivers' started by eraser, May 6, 2009.

  1. eraser

    eraser Guest

    I'm writing a AVSTREAM minidriver for a Video Capture & MPEG-4
    Compress Card. I use property set to send ioctl code to the
    minidriver. In the plug-in I try to call CreateFile() to get the
    device handle. But the AVSTREAM minidriver doesn't need me to call
    IoCreateDevice(), so I wonder how can I get the device name which is
    usually provided by the WDM driver writer before.

    Thanks a lot!
    eraser, May 6, 2009
    1. Advertisements

  2. Is there any DirectShow ways to open the driver?
    Maxim S. Shatskih, May 6, 2009
    1. Advertisements

  3. eraser

    Tim Roberts Guest

    You use the system device enumerator, CLSID_SystemDeviceEnum. You
    enumerate through all of the devices in whatever category your device is
    in, until you find a match on your friendly name.

    There are lots of samples of this on the web, but here's an MSDN page with
    a sample:

    The code can be made a little simpler by using the ATL CComPtr classes.
    Tim Roberts, May 7, 2009
  4. eraser

    eraser Guest

    Thank you very much!
    I've succeeded in getting the device handle. But there is another
    I want to call fopen( ''c:\windows\system32\filename.txt", "rt") in
    plug-in, but it returns error code 0x80070002: "The system cannot find
    the file specified." I've copied the filename.txt to c:\windows
    \system32, what does the error mean?

    eraser, May 8, 2009
  5. eraser

    Tim Roberts Guest

    You could answer this question yourself by compiling and running this
    #include <stdio.h>
    int main() {
    puts( "c:\windows\system32\filename.txt" );

    You need to write "c:\\windows\\system32\\filename.txt".

    However, \windows\system32 is not a good spot for you to put your own
    Tim Roberts, May 9, 2009
  6. eraser

    eraser Guest

    Yes, I tried this.
    The compiler regards "\\" as "\".
    By the way, I'd like to know that, in the AVSTREAM minidriver, I
    needn't to call IoCreateDevice(), but in the property-processing
    routine I need to create the dummy device object:
    ntStatus = IoCreateDevice (pdx->DriverObject, 4, NULL,

    FILE_DEVICE_UNKNOWN, 0, FALSE, &pdx->StreamDevObj);
    However this will cause to a fatal error.
    Can I call IoCreateDevice this way in the AVSTREAM minidriver?
    eraser, May 9, 2009
  7. eraser

    Tim Roberts Guest

    Sure, you can, but there is no real reason to do so. Almost anything you
    can do with a control device object can be done using properties through
    the AVStream device object.
    Tim Roberts, May 11, 2009
  8. eraser

    eraser Guest

    Yes, I've succeeded in create the dummy device object.
    There is another question:
    If I want to send a data and then get another data of the same
    structure from the device, if I send IKspropertySet::Get(
    IN REFGUID PropSet,
    IN ULONG Id,
    IN LPVOID InstanceData,
    IN ULONG InstanceLength,
    OUT LPVOID PropertyData,
    IN ULONG DataLength,
    OUT ULONG *BytesReturned

    Can I input the data first and in the minidriver get the data needed
    from pIrp->AssociatedIrp.SystemBuffer, and then output the data to
    PropertyData and return?
    eraser, May 13, 2009
  9. eraser

    Tim Roberts Guest

    What do you mean by "input the data first"? Are you thinking about feeding
    your AVStream driver from a user-mode application? Is that what you are
    using the control device object for? That's just making things harder.
    Your feeder application can send KS properties just as easily as sending
    ioctls, and that will use the normal AVStream dispatch mechanism -- no ugly
    Tim Roberts, May 13, 2009
  10. eraser

    eraser Guest

    I want to use IKspropertySet::Set to send ioctl code and data of
    special structure, and IKspropertySet::Get to get the returned data of
    the same structure from the minidriver, all I want to do is to use the
    IKspropertySet interface to do what DeviceIoControl can do.
    Can this be realized easily?
    eraser, May 13, 2009
  11. eraser

    Tim Roberts Guest

    That's exactly how the KS property scheme works, through the normal
    AVStream mechanism -- no extra device objects necessary. Every AVStream
    sample handles properties, so you have ample examples of how this works.
    Tim Roberts, May 15, 2009
    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.