It depends on few things. Most importantly what bussiness logic is there in B.
For example suppose B function is responsible to read data from a very large file and you want to return that from B. There are changes that file open error may occure then:
int B(CString &out_string) will be best option because of two reasons.
1. The error code can be returned as return parameter
2. You dont need to accumulate the content of file in a local variable which gets added and deleted on stack while transferring that as return value.
Microsoft products still make use of these. If you are developing something that is interconnected for example with office products than chances are good that you have to mess with COM as some programming interfaces of these products are exposed with COM. Sometimes interconnection between 2 softwares written in different languages is the easiest via COM if both language compilers have COM support (this is also dependent on the kind of interconnection - its quite rare when a pipe or loopback socket isn't enough). In my opinion if you are developing your own software then the best is to avoid COM if possible. Keep it simple. Use a technology/library only if it makes your job easier or if it is explicitly requested by your client. Don't use something "just because" its a fashion or because it is used by another product. It can be possible that a famous product uses technology X but the architects are cursing the day of choosing that technology and today they simply cant afford (time/$) getting rid of it. Before you start using something do some research and compare different solutions on a simple example program. Investing the time in this pays off in the long run especially in case of a bigger project.
I think that these technologies still using by Microsoft and I think also that they are very important.
but it's not wrong to use a new software builder and coder , they all the same but the new are easier to use.
Iam currently developing window application using VC6 and VC2008 and interested to learn ATL, STL, WTL and COM. I have refered many article and tutorial in the net. But I felt difficult to understand the concepts and explanation. Friends kindly suggest me any material or site which many helpful to learn it from beginning.
Introduction to COM - What It Is and How to Use It.[^] by Michael Dunn, is an excellent introdiuction, as are his other articles on the subject. Scott Meyers has written some useful books on STL which you can probably find on Amazon. I don't use ATL/WTL so cannot offer suggestions for those. However, I would say that if you find these subjects difficult to understand then it is important to focus on only one at a time.
Inside COM by Dale Rogerson (very good intro)
Professional COM Applications with ATL by Sing Li and Panos Economopoulos (more advanced)
COM IDL & Interface Design by Al Major (everything you ever wanted to know about interfaces)
When using jscipt9 (Chakra) from C++ with the AddNamedItem() / GetScriptDispatch() functionality to create a module-like behaviour (context separation) I get E_OUTOFMEMORY from GetScriptDispatch().
This happens only when omitting the SCRIPTITEM_GLOBALMEMBERS flag with AddNamedItem(), no matter what other flags are given.
I tried already everything, including different flags (all possible flags, not only the known ones), changing the order of calls to IActiveScript, calling it in different states of the script engine, invoking different versions via SCRIPTPROP_INVOKEVERSIONING, implementing all requested interfaces in my IActiveScriptSite etc - no result.
For older versions (means: not using jscript9) of jscript everything works as expected. But as soon as I switch the CLSID to Chakra it breaks.
I'm developing a web game, which uses ATL based ActiveX control to display the 3d game world. When the game activex control was loaded by IE, a seperate game thread was created and the game HWND was created in the thread as child window of the activeX window. Then a message loop was running in the thread to process game logic, rendering,..etc.
In the game thread, I created a windowless mode Shockwave Flash player COM interface to display 2D content, which uses OleDraw to render the image to a texture.
Ok, All these things runs fine in IETab on chrome, BUT not in the IE! The flash player displays nothing in IE! In fact, some web browser which used IE core does work correctly, except IE!
So what could be the reason, and how can I fix this problem?
Define what? The link I gave you uses fairly simple words, and explains exactly what the difference is. If you do not understand the difference between single-threaded and multi-threaded code, then you should avoid using COM.
First of all an apartment is an abstract concept, means, there is no physical thing behind. When a thread starts it decides in which apartment it wants to "live". It does so by calling CoInitialize or CoInitializeEx.
An apartment is a kind of a convention how to handle things. A thread that initializes a single-threaded apartment states, that it does not allow any other threads to enter the same apartment. COM knows then, that all objects living in this apartment can be accessed only from this same thread and makes sure that these objects are used only from within this thread.
A thread that initializes a multi-threaded apartment allows other threads. COM knows then, that multiple threads might access the objects in this apartment and relies on these objects to handle thread synchronization by themselfs.
So how do other threads enter the same apartment? Simply also via CoInitializeEx. By requesting a multi-threaded apartment they will automatically resist in the same apartment as the other MTA threads since there can only be one MTA.
So in the end each thread that initializes a STA creates its own apartment, while threads initializing MTA enter the one and only MTA. And the same is of course valid for all COM objects created from this thread.