Basic COM   «Prev  Next»

Com Client Code - Exercise

Write COM client code


Objective: Write code to access interfaces IF1 and IF2 in COM object O2.

Instructions

Using the CLSID, the IID, interface declarations, write code to implement a COM client. Use the steps below as a guide. Place the code in main. You can use pseudo-code to handle error conditions.

void main() {    //any function name will do
//Step 1 : Declare HRESULT and interface pointer
//variables for IF1 and IF2
  
//Step 2 : Initialize COM - thread can use
//COM services and objects.

//Step 3 : Call CoCreateInstance to create an
//instance of COM object O1, get a pointer to IF1.
//Use the FAILED macro to check for errors.

//Step 4 : Call method X1 in IF1. Pass in any value.
   hr = pIF1->X1(45);

//Step 5 : Call IF1::QueryInterface to get a
//pointer to IF2. Use the FAILED macro to check
//for  errors

//Step 6 : Call Z1 in IF2

//Step 7 : Release all COM interface pointers

//Step 8 : Uninitialize COM for this thread

Exercise scoring


This exercise is worth a total of 40 points. Error handling in your answer need not be complete.

Exercise submission


Write or paste your answer in the text area below. When you are done, click Submit to submit your answer.