Re: out param question



"mysteron" <acornatom66@xxxxxxxxx> wrote in message
news:uzNaFfBHGHA.2012@xxxxxxxxxxxxxxxxxxxx
> the GetThumbnail() method needs to pass a bitmap out to the caller
> ... an arbitrary length array of bytes....
>
> Q: what would be the best way to do this?
>
> GetThumbnail([out] ?? )

If you don't need to be automation-compatible (usable from VB or
scripts), use conformant arrays:

HRESULT GetThumbnail([out] DWORD* pSize, [out, size_is(, *pSize)] BYTE**
pData);

You allocate a block of memory with CoTaskMemAlloc, store the pointer to
it in *pData and its length in *pSize. The caller eventually frees the
data with CoTaskMemFree.

If you do need to be automation-compatible, use a safearray of bytes:

HRESULT GetThumbnail([out, retval] SAFEARRAY(BYTE)* psa);

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: out param question
    ... > use conformant arrays: ... > You allocate a block of memory with CoTaskMemAlloc, ... > it in *pData and its length in *pSize. ... The caller eventually frees the ...
    (microsoft.public.win32.programmer.ole)
  • Re: Marshal Not Copying all Data to Fixed Byte Array
    ... the original byte array. ... DeadReckoning dr = new DeadReckoning; ... IntPtr pData = Marshal.AllocHGlobal; ... // If there are articulations, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: array verses ArrayList
    ... > I have a class that contains a collection of reference types. ... > needs to have a method that returns the collection to the caller. ... If the size cannot change, then no, an Array of MyObject is preferable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: About Memory Allocation and function calls
    ... function(because the caller don't know the exact size). ... how should the caller access this array for future use? ... Allocated memory remains allocated until it is explicitly freed. ... the calling function has access to. ...
    (comp.lang.c)
  • Re: Pass long* to VC++COM object from C#
    ... If you pass some kind of managed array like byte, ... declare void PutData(IntPtr pData, int nBytes); ... IntPtr pData = Marshal.UnsafeAddrOfPinnedArrayElement ...
    (microsoft.public.dotnet.framework.interop)