Archived from groups: microsoft.public.windowsnt.terminalserver.misc (
More info?)
That seems to be a better solution, but I don't see the real difference
between converting each chunk/cumulate and cumulate/convert... Any
suggestion?
Thx.
Thomas T. wrote:
> Don't convert right a way each chunk like that, cumulate them in a buffer
> (use memcopy),
> when the whole buffer is received then you convert it to BSTR. I never have
> problem when using
> this technic .
>
>
> "R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
> news:Ow0MdzF5EHA.2592@TK2MSFTNGP09.phx.gbl...
>
>>Yes, gbstrMensaje is a global buffer. I convert each chunk received to
>>BSTR and concatenates to the global buffer. The strange thing is that it
>>usually works well, but sometimes the global buffer have the complete
>>message but with small chunks of noise inserted at some points (notice:
>>if i remove the noise, the result BSTR is OK)
>>
>>Thomas T. wrote:
>>
>>>I think, problem is in the logic of the code, you should use a global
>>>buffer, cumulate
>>>all arrived buffer , at the end (CHANNEL_FLAG_LAST) convert the buffer
>
> to
>
>>>BSTR
>>>
>>>Regards
>>>
>>>"R. Oliva" <ramiro_oliva@hotmail.com> wrote in message
>>>news:ua$Z8eB5EHA.1452@TK2MSFTNGP11.phx.gbl...
>>>
>>>
>>>>I write a buffer bigger than CHANNEL_CHUNK_SIZE with
>>>>WTSVirtualChannelWrite. The problem happens sometimes in the client, not
>>>>in the server (so WTSVirtualChannelRead is OK). In the client, when I
>>>>concatenate the chunks received, finally the result has noise inserted.
>>>>This is the code I use to concatenate the chunks:
>>>>
>>>>BSTR ConcatenateBSTR (BSTR a, BSTR b) {
>>>> int ca = SysStringLen (a); // Does not include terminating '\0'
>>>> int cb = SysStringLen (b);
>>>>
>>>> BSTR c = SysAllocStringLen (NULL, ca + cb); // Accounts for
>>>>terminating '\0'
>>>>
>>>> if (! c)
>>>> return NULL;
>>>>
>>>> memcpy ((WCHAR *)c, a, ca * sizeof(WCHAR));
>>>> memcpy (((WCHAR *)c) + ca, b, (cb+1) * sizeof(WCHAR)); // copies
>>>>b AND '\0'
>>>>
>>>> return c;
>>>>}
>>>>
>>>>void WINAPI VirtualChannelOpenEvent(DWORD openHandle, UINT event, LPVOID
>>>>pdata, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
>>>>{
>>>>
>>>>...
>>>> switch(event)
>>>> {
>>>> case CHANNEL_EVENT_DATA_RECEIVED:
>>>> {
>>>>static int bBusy = 0;
>>>>
>>>>while(bBusy);
>>>>bBusy = 1;
>>>>
>>>>if (!(dataFlags & CHANNEL_FLAG_FIRST)) { BSTR bstrTmp =
>>>>SysAllocString(pdata);
>>>>BSTR bstrAux = gbstrMensaje;
>>>>gbstrMensaje = ConcatenateBSTR(gbstrMensaje, bstrTmp);
>>>>SysFreeString(bstrTmp);
>>>>SysFreeString(bstrAux);
>>>>} else {
>>>>gbstrMensaje = SysAllocString(pdata);
>>>>}
>>>>
>>>>bBusy = 0;
>>>>
>>>>if (dataFlags & CHANNEL_FLAG_LAST) {
>>>>... }
>>>>
>>>> }
>>>> break;
>>>>
>>>
>>>
>>>
>
>