Behavior of out parameters and dependencies
From: Laurents C. R. Meyer (Meyer_at_discussions.microsoft.com)
Date: 01/20/05
- Next message: vidhya: "Capturing key press/release events on keyboard for all keys in VC+"
- Previous message: Craig Kelly: "Re: Interace property's case changed when viewed/used in tlb and c"
- Next in thread: Alexander Nickolov: "Re: Behavior of out parameters and dependencies"
- Reply: Alexander Nickolov: "Re: Behavior of out parameters and dependencies"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: vidhya: "Capturing key press/release events on keyboard for all keys in VC+"
- Previous message: Craig Kelly: "Re: Interace property's case changed when viewed/used in tlb and c"
- Next in thread: Alexander Nickolov: "Re: Behavior of out parameters and dependencies"
- Reply: Alexander Nickolov: "Re: Behavior of out parameters and dependencies"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|