CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Location
    Indiana
    Posts
    21

    Determing Interface type

    I want to pass either an IStorage* or an IStream* parameter to a method. I am planning on passing it as a long and then casting it back as an IStorage* or IStream*.

    I have several concerns. The first is I am not sure if I am going to have reference count problems.

    Another is how to determine if it is an IStorage* or IStream* since I would prefer to use the same method with only the one parameter. I was planning on using code like the following:

    IStorage* p1;
    IStream* p2;
    p1 = CComQIPtr<IStorage>((IUnknown*)lPointer);
    p2 = CComQIPtr<IStream>((IUnknown*)lPointer);
    if (p1 != NULL)
    {
    ....
    }
    else if (p2 != NULL)
    {
    ....
    }

    I have not seen any problems so far. Does anybody have any suggestions on the soundness of this design or any potential problems? Are there better methods of accomplishing this?

    Thank you for any assistance that you are able to provide.


  2. #2
    Join Date
    May 1999
    Posts
    69

    Re: Determing Interface type

    The supplied code takes the I/P and asks whether it supports IStorage and then IStream. This will work fine as long as the object implementing the interface that you passed does not support both interfaces.

    I think the only problem you'll get with passing it as a long is if you intend marshaling it across processes.

    The way that many of the COM functions resolve this is to pass an additional parameter (i.e. the IID of the interface) see both QueryInterface and CoCreateInstance for examples.


  3. #3
    Join Date
    May 1999
    Location
    Indiana
    Posts
    21

    Re: Determing Interface type

    Thank you for your help.

    An additional question:
    I am using these objects in-process. If I wanted to use them cross-process, won't a long end up marshalling (assuming universal marshaller) as just a long and not really be an interface to my object? Would an IUnknown* work better?



  4. #4
    Join Date
    May 1999
    Posts
    69

    Re: Determing Interface type

    Absolutely, you have to pass across an interface pointer for cross process/machine calls.


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