Jump to content
  • Advertisement
Sign in to follow this  
incertia

COM as a way to implement the use of STL containers across a DLL

This topic is 2468 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

So using STL in a class that will be exported by a DLL is a big no-no due to problems with differently compilers packing data in different formats. With that in mind, would COM be a viable option for secretly using STL containers in an interface/class that you wish to share across a DLL? That way, the compiler only needs to know of the methods of the interface and not how the data is packed.

Share this post


Link to post
Share on other sites
Advertisement
As long as the implementation is completely hidden and the interface contains only legal types, then it shouldn't be a problem.

Share this post


Link to post
Share on other sites
I think COM style interface is the best (at least it's best to me) to work cross DLLs.
It has two dominant advantages,
1, Binary compatibility. There is only function pointers in the interface with fixed layout (one pointer after another).
2, Safe memory management. No explicitly free function, all resources are freed by calling "release". The object implementing the "release" function knows how to free itself safely.

Share this post


Link to post
Share on other sites

As long as the implementation is completely hidden and the interface contains only legal types, then it shouldn't be a problem.


Would something like std::string be a legal type? Or should I resort to C types only?

EDIT: I should be able to return COM interface pointers, correct?

Share this post


Link to post
Share on other sites


Would something like std::string be a legal type? Or should I resort to C types only?

EDIT: I should be able to return COM interface pointers, correct?

Don't pass any STL classes across DLLs.
Different DLLs may be compiled with different STL.
Yes, you can return COM interface pointers, and it's the safe way.

Share this post


Link to post
Share on other sites
How about operator overloading within a COM interface?

EDIT: If a function is going to receive varying number of string arguments, I should be creating something like IArgumentList and passing that to a function instead of using std::vector<const char*> right?

Share this post


Link to post
Share on other sites
You are right on the argument list thing.

For operator overloading, in COM, forget any C++ specified features, such as operator overloading, template, etc.
I suggest you read some COM books such as "inside COM", "essential COM" to see how interface works.

Share this post


Link to post
Share on other sites

You are right on the argument list thing.

For operator overloading, in COM, forget any C++ specified features, such as operator overloading, template, etc.
I suggest you read some COM books such as "inside COM", "essential COM" to see how interface works.


I would if I could. My dad just recently got me a few dx11 books, and he won't be too happy seeing me requesting other books when I haven't finished the dx11 ones yet. Oh the joys of high school. So what kind of free resource would be the best at instructing one the ways of COM?

As a final question for this post, when I return references to an interface via a get function, the get method should call AddRef right?

Share this post


Link to post
Share on other sites


I would if I could. My dad just recently got me a few dx11 books, and he won't be too happy seeing me requesting other books when I haven't finished the dx11 ones yet. Oh the joys of high school. So what kind of free resource would be the best at instructing one the ways of COM?

As a final question for this post, when I return references to an interface via a get function, the get method should call AddRef right?


http://en.wikipedia.org/wiki/Component_Object_Model
Also google "c++ Component Object Model", without quote marks.

Since you are only using the COM idea than COM itself, you don't need to go too deep in COM.
Just learn about the interface, object life management, that's enough.
I'm not sure if COM is still as popular as before .Net was born.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!