Jump to content
  • Advertisement
Sign in to follow this  
wack

DCOM with BSTR data types

This topic is 3893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Let's get enterprisey, old-school style. Picture the following scenario: A DCOM server as an exe file, and a client app - both written in C++. The server may be either on the same machine as the client, or some other computer on the network. I am not sure if this scenario would make the answers differ from normal COM usage. Now - the questions. 1) When using a BSTR return type on a COM interface method (declared [out, retval] in IDL file), how should it be handled on the client? Should SysFreeString be used on the returned value? Would it be better to use a _bstr_t than a raw BSTR - and does it need to be freed in that case too, or would the _bstr_t take care of it? (Three questions for the price of one, yay!) 2) For the same BSTR return type from the server, it should be allocated but not freed on the server, right? 2) If a BSTR is declared in the IDL-file as [out] only, I would guess it needs to be allocated manually on the client, and freed after the COM call. On the server it's neither allocated nor freed manually. Is this correct? 3) I am guessing the same as 2) generally applies to parameters that are declared [in, out]. Correct? Getting this wrong seems to cause subtle bugs that are hard to detect. I would be very grateful if someone experienced with COM could advice.

Share this post


Link to post
Share on other sites
Advertisement
If a method accepts a BSTR the caller allocates it, passes it in, and frees it upon returning. As far as I know the callee is okay to free and re-allocate this string in order to change the value passed back to the caller, since you're not supposed to write to them in-place (they live in memory controlled by RPC).

The COM marshaler takes care of all the BSTR memory management stuff behind the scenes, so from my understanding you just have to make sure that whoever allocates the resource frees it on the same side. That is if the server allocates it then it needs to free it after the call and vice versa.

I'm not sure what the difference between BSTR and _bstr_t is, as I haven't used IDL much at all.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!