Solved

COM

Posted on 2000-03-11
5
256 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 30 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
dialer.exe 4 68
Build VS2015 project in bat command 3 101
Trouble with References... 5 62
x-bar in Google Sheets 2 91
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

685 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