|
-
May 20th, 1999, 12:10 PM
#1
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.
-
May 20th, 1999, 04:40 PM
#2
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.
-
May 20th, 1999, 05:31 PM
#3
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?
-
May 21st, 1999, 05:09 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|