Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

COM

Posted on 2000-03-11
5
Medium Priority
?
283 Views
Last Modified: 2013-11-25
In inprocserver the methods that an interface expose is specified as pure virtual, therefore when the com class(implementation class) is instantiated the compiler generates Vtable which has address of the interface methods.Now the question is why should we use QuerryInterface() to get an interface pointer when we can get the address of Vtable and subsiquently get the method address?
0
Comment
Question by:r_sam_14
  • 5
5 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2607821
->why should we use QuerryInterface() to get an interface pointer when we can get the address of Vtable and subsiquently get the method address
==========================
Put it simply,because QueryInterface is not only for get pointer but mainly for change the kind of the pointer to let it point to another interface.

Sure you can get pointer easily buy create it by yourself but it's against what COM is for.Com has the duty to create a class and cast it and pass pointer to you,it's not your duty.This is the main reason we use QueryInterface().

Regards
W.Yinan
0
 
LVL 5

Accepted Solution

by:
Wyn earned 90 total points
ID: 2607822
->why should we use QuerryInterface() to get an interface pointer when we can get the address of Vtable and subsiquently get the method address
==========================
Put it simply,because QueryInterface is not only for get pointer but mainly for change the kind of the pointer to let it point to another interface.

Sure you can get pointer easily buy create it by yourself but it's against what COM is for.Com has the duty to create a class and cast it and pass pointer to you,it's not your duty.This is the main reason we use QueryInterface().

Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2607828
I find your main problem is you forget we are using COM and it's a specification which give us the way to use COM.If you use it as common way,like you get pointer to interface by creating COM object in your code(client code),you are not using COM and you lose the points/benifits here.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2607859
->we can get the address of Vtable and subsiquently get the method address?
=================
Yes,you can do that if you know what you are doing clearly,like you know how different kinds of interfaces are structured in a class ,e.g:by multiple inherit or aggregation and so on,but it's not always the case,more often than not we dont know how they compose together.And again you are not using COM,it's standard we should obey to get pointer from QueryInterface and sometimes it's the only way.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2607870
->is instantiated the compiler generates Vtable which has address of the interface methods
==============================
No,compiler doesnt has it.Only thing it knows is the sequence of functions and the address will be filled at runtime.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question