Re: out param question



and reading up about size_is I see that :

'the size_is() attribute of a sized pointer is fixed when the param that
points to it is first marshalled'

well i set that to zero on the client side, because i don't now how big the
bitmap is going to be at that point...

even though the server side set's the pSize on the way out, that aparently
is too late for the underlying stub marshaller ...

'therefore the size_is() attribute is only applied in the [in] direction'

so this isn't what i want - i want the server to alloc the buffer and pass
it back to the client, along with its length ... and then after using the
data, the client would free the buffer ...

what IDL am i looking for here?


TIA



"mysteron" <acornatom66@xxxxxxxxx> wrote in message
news:O4mnHnHHGHA.3896@xxxxxxxxxxxxxxxxxxxxxxx
> hmm - that IDL doesn't compile - it says you cant derive the thing in
> size_is() from an out-only param.
>
> should the server or the caller be cotaskalloc-ing the memory?
>
> the IDL i'm trying now is this:
>
> HRESULT GetThumbnail([in] BSTR szFilename, [in] cxThumb, [in, out] DWORD*
> pSize, [in, out, size_is(*pSize)] BYTE** ppBMPData);
>
> on the server, in the implementation of GetThumbnail I do something along
> the lies of:
>
> HRESULT GetThumbnail([in] BSTR szFilename, [in] cxThumb, [in, out] DWORD*
> pSize, [in, out, size_is(*pSize)] BYTE** ppBMPData)
> {
> if (generated thumbnail for szFilename OK){
>
> *pSize = dwBMPBytes;
> *ppBMPData = (LPBYTE)CoTaskMemAlloc(*pSize);
> if (*ppBMPData==NULL)
> return E_FAIL
> memcpy(*ppBMPData, pThumbnailBits, *pSize);
> return S_OK;
> {
> return E_FAIL;
> }
>
> On the client, I call the function like so:
>
> DWORD dwBytes = 0;
> BYTE* pBMPBits = NULL;
> HRESULT hr = pSvr->GetThumbnail(CComBSTR("c:\\foo.jpg"), 256, &dwBytes,
> &pBMPBits);
>
> and it is currently failing with hr = 0x3f833147 which is no doub't some
> low-level RPC thing...
>
> should i be allocing a buffer on the client side, and passing in the
> length of that from that side? thing is, only the server side knows the
> actual length of the buffer required .. at runtime....
>
> i always get this wrong .. lol
>
> Helge's IDL was slightly different, but he didn't explain exactly what the
> params meant or who was doing the alloc-ing/free-ing... maybe his is the
> correct way?
>
> TIA
>
> "Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
> news:ekMomADHGHA.1728@xxxxxxxxxxxxxxxxxxxxxxx
>> "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: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: UCX connect function timeout
    ... This is an example of a VMS client program communicating with ... In this example the T3_DEMO server is listening on port 1024 at node ... The Access Control Information buffer must be the first buffer transmitted ... the communication server. ...
    (comp.os.vms)
  • Re: Buffersize for Socket.Recieve() method
    ... > i have a problem with the buffer size at the client. ... > Server -> Server sends 100 bytes of data ... oder ebenso mit vorherigen/nachfolgenden Daten kombiniert [zB Recv liefert 110 Bytes aufs mal]. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: TCPClient Synchronous or Asynchronous Writes
    ... acting as the "server" receives quality assurance data from different ... Each client can register to look at differnt data so there ... is actually a Circular Buffer for each client. ... >> stream data to my clients over a TCPClient connection. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Informix 7 slow over WAN yet fast over LAN
    ... Server and Client. ... This could be a symptom of the second problem, but another may be the amount of data that's really needed versus the comm buffer size. ... Examine the SQL and code to determine if the filtering and the joins are optimal. ...
    (comp.databases.informix)