Behavior of out parameters and dependencies

From: Laurents C. R. Meyer (Meyer_at_discussions.microsoft.com)
Date: 01/20/05


Date: Wed, 19 Jan 2005 20:35:01 -0800

Hoi!
I am currently thinking about an interesting exception in the COM usage and
would like to hear if somebody knows about the behavior.

Let's say there is Some Interface called IFoo. This interface offers one
method called GetData. Because the caller does not know how large the buffer
has to be, it is allocated by GetData using CoTaskMemAlloc. The user has the
possibility to omit a parameter, which results in an return code of S_FALSE.
The declaration of the interface would look something like this:

[pointer_default(unique), ...]
interface IFoo : IUnknown
{
    HRESULT GetData( [out]DWORD* pdwSize, [out, size_is( ,*pdwSize)]BYTE**
ppBuffer );
};

Now, on a usual call like:

DWORD dwSize;
BYTE* pData;
GetData( &dwSize, &pData );

everything will be alright.
But what is the behavior, if I call like this:

BYTE* pData;
GetData( NULL, &pData );

Even if GetData returns immediately after a paremeter check (allocates no
memory for ppBuffer), COM would try to dereference pdwSize (i.e. *pdwSize),
which would result in an error.
Am I right, or is COM checking the pointer (pdwSize) first if it is zero of
not and in case it is zero assumes the dereferenced pointer (*pdwSize) is
zero too?

In case COM returns an error, is it one which can be handled or is COM
terminating the application?
Of course this is only a point when using a proxy.

Can anybody help me? Thanks in advance.

Laurents C. R. Meyer



Relevant Pages

  • Re: derived class how to
    ... > class DData extends Data{ ... > interface DA{ ... > DData getData(); ... but maybe DA should extend A and you can add the extra behaviour ...
    (comp.lang.java.programmer)
  • Re: filesize error
    ... > int main ... > GetData(pData); ... That shouldn't compile. ...
    (comp.lang.cpp)
  • filesize error
    ... GetData(pData); ... //so pos will have the size:) ... fread(pData, sizeof(char),pos,fp); ...
    (comp.lang.cpp)
  • Re: Some kind of wrapper class
    ... with the GetData() method and anything else ... in common which you need to call. ... communication between e.g. cSQLServer and the presenter. ... Working with an interface, as far as I know, works only in one ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: derived class how to
    ... > class DData extends Data{ ... > interface DA{ ... > DData getData(); ... > void getData; ...
    (comp.lang.java.help)