|
From: Sten Westerback (MVP SDK 2005-6 :) on 1 Jul 2008 07:39 <alien.0101(a)gmail.com> wrote in message news:372a50a0-61be-4a9e-ab0b-b2c7c9bb7dd1(a)s33g2000pri.googlegroups.com... > Hi Guys, > > I am creating a client server program using RPC. > > I have Server API in IDL as: > > IDL: > > HRESULT GetBlob([out] DWORD *pdwBlobByteCount,[out, > size_is(,*pdwBlobByteCount)] BYTE** ppBlob); > > This function returns an array of byte and byte count as output > params. > > Now as required by RPC I need to implement memory functions on both > client and server. > > midl_user_allocate(..) > midl_user_free(..) > > Lets look at client code: > > { > ... > DWORD dwCoun=0; > BYTE *pBlob=NULL; > HRESULT hr = GetBlob(&dwcount,&pBlob); > ... > ... > > // after using pBlob > if(pBlob!=NULL) > midl_user_free(pBlob); > } > > > Server Code: > > HRESULT GetBlob(__out DWORD *pdwBlobByteCount,__out BYTE** ppBlob){ > .... > DWORD count=10; > BYTE *pByte = (BYTE*)mild_user_allocate(sizeof(BYTE)*10); > if(pByte!=NULL){ > *pdwBlobByteCount = count; > *ppBlob = pByte; > } > > ... > } > > > Issue: > RPC > Server<<--Stub-->> ----------------------------------------<<Stub-- >>>Client > > Now Server allocate Byte array and send that array to server stub. > Server stub marshals that array and passes over RPC to client, also > server stub deallocates the memory allocated by server. > > client stub marshals the data passed by server stub, allocates memory > in client and passes that data to client. > When client is done with that data , it needs to call > midl_user_free()... > > Now my question is how the client will know how much memory to > deallocate when midl_user_free() if called. > > wheneneve I do midl_user_free() , I am getting DEBUGCHK failed in > rheap.cpp > > Any suggestions, Am i doing something wrong here???? Would you show us your implementation of the midl_user_* functions too? If you are using malloc(), maybe you are overflowing the buffer (or, use a different heap in the _alloc and _free functions). If you are using LocalAlloc, GlobalAlloc or whatever OS-supplied memory reservation API they all allocate a memory buffer with a rounded size. If you were to try to write outside that OS buffer you would get an exception but if you write between the end of your requested buffer and the OS-allocated buffer you wouldn't see a problem. Verify your buffer size and tell us the details about your routines. Unforturnately i can't say i have experience from raw RPC -- i prefer to use Named pipes and mailslots. But i may choose to dig into it as much as needed... - Sten - Sten
|
Pages: 1 Prev: WSASysCallFailure Next: Enable printer sharing in windows XP |