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

Started by
14 comments, last by MichaBen 12 years, 1 month ago
If you're willing to go as-far-as COM you may as well just switch to C#.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement

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

There's nothing stopping you from using illegal types in your interface, you've just got to be careful about managing the types whose data size may change.




class Foo
{
public:

EXPORT Foo();
EXPORT virtual ~Foo();

EXPORT void func(const char* str);
inline void func(const std::string& str) { func(str.c_str()); }
};


This will partially work (in that you can create and use the class, but you can't use it as a base class, and it will generate a warning)


class Foo
{
public:

EXPORT Foo();
EXPORT virtual ~Foo();

EXPORT void func(const char* str);
inline void func(const std::string& str) { func(str.c_str()); }

EXPORT const char* getStr() const;

private:
std::string m_str;
};



[font=helvetica, arial, verdana, tahoma, sans-serif][size=2][color=#282828]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. [/quote][/font]
[font=helvetica, arial, verdana, tahoma, sans-serif][size=2][color=#282828]It's got nothing to do with compiler packing, it's simply the inability to guarantee the size of the CSL containers (due to additional debugging nonsense). [/font]


[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

I think COM style interface is the best (at least it's best to me) to work cross DLLs.[/quote][/font]



I can't say I agree with you.... ;)




[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

I'm not sure if COM is still as popular as before .Net was born. [/quote]
It was never popular ;)[/font]





[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

For operator overloading, in COM, forget any C++ specified features, such as operator overloading, template, etc.[/font]


[/quote]

Why do you say that? There's nothing stopping you using template specialisations and operator overloading with COM or dlls.


This will partially work (in that you can create and use the class, but you can't use it as a base class, and it will generate a warning)

Did you notice that the OP mentioned different compilers? Standard library classes do not have a single implementation. std::string could be implemented with the small string optimization on one compiler and not with another. Try using a DLL with the first implementation with a different compiler is completely undefined.


[font=helvetica, arial, verdana, tahoma, sans-serif][size=2][color=#282828]It's got nothing to do with compiler packing, it's simply the inability to guarantee the size of the CSL containers (due to additional debugging nonsense). [/font]
[/quote]


Again, size is only part of the problem. Standard library containers can have fundamentally different implementations with different compilers.


"I think COM style interface is the best (at least it's best to me) to work cross DLLs."

I can't say I agree with you.... ;)


Please explain why you don't agree, what's the reason you don't agree.
It doesn't help to just say "I can't say I agree".
It will help if you say "I don't agree because point 1, point 2, point 3", etc.
If there is no any points, why you don't agree?

And I emphasized "at least it's best to me", why don't you agree that I think it's best to me?
I don't think I need your agree on what I can think of.


"I'm not sure if COM is still as popular as before .Net was born."

It was never popular ;)



Is DirectX popular? It's using COM interface.
Is Windows popular? It's full of COM components.
Please give data to support your opinion "it was never popular".
Or please give me your definition for "popular".
I thought it's popular is because it's in any copy of Windows since Win2000 (or maybe Win95, not sure), and Windows is the most popular OS in the planet.
What do you think about "popular"?


"For operator overloading, in COM, forget any C++ specified features, such as operator overloading, template, etc."

Why do you say that? There's nothing stopping you using template specialisations and operator overloading with COM or dlls.


OK, please give me an example you use template via COM interface.
COM is not only for C++. You can use COM in C, Delphi, etc.
I have much interesting if you can tell me how to use C++ template and operator overloading in COM interface by C and Delphi.

Finally, is it you down vote me that much? If it is, please give your reason, otherwise, you are offending me. Down voting others for no reason is always offending.
If you didn't down vote me, that's OK. I just want to know why I got that lot of down vote.
I down voted your that reply because it's full of misleading and offending. You are denying others' opinion without any reason, that's not fine in a public forum.
OK, I gave you the reason that why I down vote you, now it's your turn to give your reason if you really down voted me.

Thanks.

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

[quote='SiCrane' timestamp='1331326585' post='4920756]Did you notice that the OP mentioned different compilers?[/quote]

Yes, I did notice. Look again at my first solution. Find the flaw if you can..... I dare you! tongue.png

Is DirectX popular? It's using COM interface.

Cars are popular. Cars emit exhaust gas. Exhaust gas is not popular. Just because component A, that is popular, uses component B internally doesn't mean B is popular. Also the word 'popular' can be used differently. Is something populair if many people use it, even if they still hate it? Lots of people visit the dentist just as often as they go on holiday, does that make going to the dentist popular? I don't think DirectX is popular, but many people choiced it as their API to build their game engine upon. That doesn't mean they admire it's quality OO principle though (at least I don't think many developers admire the C-with-classes type of OO that Microsoft has been using for way to long).

This topic is closed to new replies.

Advertisement