Bit's World

Hope the best,plan the worst!

Subscribe to RSS feed

Posts tagged with "com"

Why COM

,

Dll works well for C library, but as for C++'s new feature, Dll has some defects that it can not work well for C++. So COM is invented. Here is a short summary for the problems when using dll as C++ dynamical library.

1. link problem
To export C++ member funtion to global function, compiler have to deal with
a important step - name mangling.But as different compiler will choose different
name mangling scheme, so client that are cmpiled using a different compiler will not
be able to link successfully with the dll compiled with another compiler.

For name mangling, please reference:

http://www.agner.org/optimize/calling_conventions.pdf

2. binary problem
As for the fundamental weaknesses of c++, lack of standardization at the binary levlel. For
all but the simplest language constructs, compiler vendors often elect to implement language
features in proprietary ways that render objects "untouchable" by code generated by any other
compiler.

Exception are a classic example of such a language feature. Different compiler implement exception
mechanims in different manner, so one program compiled with Microsoft compiler can not catch the
exception throwed by the Dll compiled by WatCom compiler.

This is because the DWP does not mandate what a language feature must look like at runtime, so it
is perfectly legal for each compiler vendor to implement a language feature in a unique and innovative
manner.

reference for the ABI:

http://www.codesourcery.com/cxx-abi/


3. dll version problem

It's hard to add a vraible member to a class when we want to update our dll. Since after we add a new
variable member, the layout of class member is different, though we can correctly call the member function,
but class_ptr->class_member will work wrongly. Also, the sizeof(class) will be different too, which will cause
a fatal error in running time.

reference for the Essencial COM:
http://www.awprofessional.com/content/images/0201634465/samplechapter%5Cchap01.pdf
May 2013
S M T W T F S
April 2013June 2013
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31