Spring 1999 Final Exam
I have neither given nor received unauthorized help
in taking this exam (HONOR PLEDGE) _________________________________ (sign here)
1) Paint4: Suppose that this program's window has just been maximized after being previously minimized. List the sequence of functions calls (in order) which will be called. Briefly describe the purpose of each function call. If a function is called more than once, you must say so. You do not need to include functions which are part of the system or MFC library. (10 points)
2) Paint 4: Why is it important that CLine is derived from CObject? Specifically which parts of Paint4 would break if CLine was NOT a derived class and why? (5 points)
Need to override Serialize and call base class to build structured storage. (2)
If not derived, would not be able to read/write files since CObjArray uses polymorphism based on pointer to CObject derived classes to call CLine's Serialize. (3)
3) Paint4: Questions about Invertline
a) What would be the effect of removing only the first call to InvertLine in the function OnMouseMove? (5 points)
Would not erase previous rubber band (temporary) line. Would end up with lots of temporary lines clutering screen
b) What would be the effect of removing only the second call to InvertLine in the function OnMouseMove? (5 points)
Basically the same effect., although it would be one line behind..
c) What would be the effect of removing only the call to InvertLine in the function OnLButtonUp? (5 points)
Last temporary line would not be erased and new permanent line would be draw over it - you would not notice this. The temporary line would disappear when the that part of the window was redrawn.
4) Questions about DCOM design.
a) Why are the interface classes abstract? (5 points)
Can't have data members. only need v-table so can use polymorphism to access derived implementation class. Never need an object instance of the interface class.
b) Why can't an application (client) create a COM object directly using the C++ new operator? (5 points)
Because it would need to know how much storage is required for the data members. This prevents the component from changing its private data members even if the public members remain the same. In addition, COM objects may exist in another process, even on another machine, hence "new" makes no sense.
c) In Listing 2.2 on page 46 of the DCOM book, what is the type of the object pointed to by pSum after the call to QueryInterface? (5 points)
CInsideDCOM (produced by class factory)
5) Consider the listing on pp. 63-66 of the DCOM book.
a) what would be the effect of removing the code associated with g_cComponents from the constructor only for CInsideDCOM? (5 points)
After first component has been created, the DLL could mistakingly be unloaded (3) (if DLLCanUnloadNow was called before a second object was created. After one object has been destroyed, can never unload DLL (2) - see DLLCanUnloadNow()
b) what would be the effect of removing the code associated with g_cComponents from the destructor only for CInsideDCOM? (5 points)
Can never unload DLL
6) Can multiple COM components use the same AppID? Why or why not? (5 points)
Yes - in fact it is a good idea to group components to share security key. (actually I had meant to say multiple COM objects, not what is stored in a DLL ( a set of objects which are sometimes referred to as "components" However because there is an association between DLL and component I allowed answers which stated only one DLL per AppID. I need to research this further to see if this is a restriction (can multiple DLLs share an APPID if they use the same DLL surrogate and security and remote machine - if applicatble). Don't know for sure but suspect its OK (how woudl you even know?)))
7) Can the same DLL be used for inproc, local and remote server usage? explain why or why not. (5 points)
Yes: It basically depends on the registry keys:
inproc uses InProceServer32 sbukey
local server uses AppID subkey in CLSID and DLLSUrrogate subkey in AppID
Remote server uses AppID subjey in CLSID and RemoteServerName subkey in AppID
8) Questions about interprocess communications in DCOM:
a) Who calls the proxy code? (2 points)
The client (application) - it thinks it is calling the member function directly
b) In a single sentence what is the purpose of the proxy code? (3 points)
To marshall the parameters into a packet to send to the server and unmarshall the output parameters
c) Who call the stub code? (2 points)
The Dll Surrogate's RPC mechanism NOTE: proxy cannot call this since it is in a different address space!
d) In a single sentence what is the purpose of the stub code? (3 points)
To read the packet sent by the proxy, get parameters and make actual call to member function., send back output parameters
9) Can any function be made into a RPC call by writing a proper IDL description of the parameters of that function. - explain why or why not? (5 points)
No - for two reasons, first some parameters (like a linked list) need custom marshalling code, second global variables cannot be handled by IDL