Solved

COM

Posted on 2000-03-11
5
233 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
Comment Utility
->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 30 total points
Comment Utility
->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
Comment Utility
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
Comment Utility
->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
Comment Utility
->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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maven archtype selection in eclipse 1 51
Example of WebAPI 7 29
twoTwo  challenge 35 86
Trouble with References... 5 22
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now