Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

COM

Posted on 2000-03-11
5
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

704 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