CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2007
    Posts
    258

    Using GetDevice function of IPortableDeviceManager interface...

    Hi all,

    I want to open a connection with portable device connected to my pc for this i am using COM and a interface called IPortableDeviceManager.

    To get devices i am using GetDevice function from this interface but i am
    not getting how to pass parameters to this function

    http://msdn.microsoft.com/en-us/libr...56(VS.85).aspx

    Can anybody please help me in this...

    Thanks in advance

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Using GetDevice function of IPortableDeviceManager interface...

    I've never used this interface before, but it seems similar to other COM routines that return a list. As the documentation says, call it first with NULL to determine how many items exist, the allocate memory for the list, then call it again with your list. If I'm reading the docs correctly the list is an array of wide string pointers. The caller need only allocate the list of pointers. The function allocates memory for each string in the list and assigns them to your pointer list. Later, the caller is responsible for freeing the memory for each string. The code flow should be something like this:

    Code:
    int doit()
    {
      DWORD count=0;
      HRESULT hr;
      wchar_t **devlist;
      IPortableDeviceManager *p;
    
      //assume p is instantiated and points to the proper interface. 
    
      hr=p->GetDevices(NULL,&count);
      //check hr
      //count should be number of devices (maybe do sanity check).
      devlist=new wchar_t *[count]; 
      hr=p->GetDevices(devlist,&count);
      
      for(int i=0;i<count;i++){
        DoWhateverWith(devlist[i]);
      }
    
      //cleanup
    
      for(int i=0;i<count;i++){
        CoTaskMemFree(devlist[i]);
      }
      delete[] devlist;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured