bit confused !!

Hi,

I'm quite new to COM implementation, and while making some applications 
I wrote following code and I got bit confused with the output
the code is as follows...


#include <iostream.h>
#include <objbase.h>

interface Ix :  IUnknown
{
	void show() { cout << a << endl; }
	int a;
	Ix():a(1) { cout << "In Ix" << endl;}
};

interface Iy :  IUnknown
{
	Iy() {cout << "in Iy" << endl; }
	~Iy() {cout << "out of Iy"; }
};

extern const IID IID_Ix;
extern const IID IID_Iy;

class A : public Ix, public Iy
{
public:
	A() {cout << "in A" << endl; }
	~A() {cout << "out of A"; }

	virtual HRESULT __stdcall QueryInterface(const IID& iid, void** ppv)
	{
		if ( iid == IID_IUnknown )
		{
			*ppv = static_cast<Ix*>(this);
		}
		else if(iid == IID_Ix)
		{
			*ppv = static_cast<Ix*>(this);
		}
		else if(iid ==  IID_Iy)
		{
			*ppv = static_cast<Iy*>(this);
		}
		else
		{
			*ppv = NULL;
			return E_NOINTERFACE;
		}

		static_cast<IUnknown*>(*ppv)->AddRef();

		return S_OK;
	}
	virtual ULONG __stdcall AddRef() {return 0; }
	virtual ULONG __stdcall Release() { return 0; }
};

static const IID IID_Ix =
{ 0xdb3d3567, 0xb104, 0x4f80, { 0x91, 0x4e, 0x4e, 0x2c, 0xfc, 0x3a, 
0x84, 0x57 } };

static const IID IID_Iy =
{ 0xfa198053, 0x7f5b, 0x43a2, { 0x88, 0x34, 0xd, 0xd3, 0x2e, 0xdb, 0x14, 
0x9 } };



IUnknown* createInstance()
{
	IUnknown* pl = static_cast<Ix*>(new A);
	pl->AddRef();

	return pl;
}

int main()
{
	HRESULT	hr;

	IUnknown* pUnknown = createInstance();

	if (! pUnknown)
		return 1;

	Ix* pIx = NULL;

	hr = pUnknown->QueryInterface(IID_Ix,(void**)&pIx);

	if ( SUCCEEDED(hr) )
	{
		pIx->show();
	}

	delete pUnknown;
	return 0;
}

now I got output as

In Ix
in Iy
in A
1


I'm wondering how did it print 'in Iy' I never created an Instance of 
interface of that type !!!!


Regards

Nk

0
8/13/2003 9:31:08 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
556 Views

Similar Articles

[PageSpeed] 34

Hi,
This is a C++ language question about inherit.  Before entering the
constructor of class A, the process will execute the constructors of its
base classes in order.
So ...

Alan


"Nk" <nilesh.karkhanis@siemens.com> wrote in message
news:3F3A055C.9090005@siemens.com...
> Hi,
>
> I'm quite new to COM implementation, and while making some applications
> I wrote following code and I got bit confused with the output
> the code is as follows...
>
>
> #include <iostream.h>
> #include <objbase.h>
>
> interface Ix :  IUnknown
> {
> void show() { cout << a << endl; }
> int a;
> Ix():a(1) { cout << "In Ix" << endl;}
> };
>
> interface Iy :  IUnknown
> {
> Iy() {cout << "in Iy" << endl; }
> ~Iy() {cout << "out of Iy"; }
> };
>
> extern const IID IID_Ix;
> extern const IID IID_Iy;
>
> class A : public Ix, public Iy
> {
> public:
> A() {cout << "in A" << endl; }
> ~A() {cout << "out of A"; }
>
> virtual HRESULT __stdcall QueryInterface(const IID& iid, void** ppv)
> {
> if ( iid == IID_IUnknown )
> {
> *ppv = static_cast<Ix*>(this);
> }
> else if(iid == IID_Ix)
> {
> *ppv = static_cast<Ix*>(this);
> }
> else if(iid ==  IID_Iy)
> {
> *ppv = static_cast<Iy*>(this);
> }
> else
> {
> *ppv = NULL;
> return E_NOINTERFACE;
> }
>
> static_cast<IUnknown*>(*ppv)->AddRef();
>
> return S_OK;
> }
> virtual ULONG __stdcall AddRef() {return 0; }
> virtual ULONG __stdcall Release() { return 0; }
> };
>
> static const IID IID_Ix =
> { 0xdb3d3567, 0xb104, 0x4f80, { 0x91, 0x4e, 0x4e, 0x2c, 0xfc, 0x3a,
> 0x84, 0x57 } };
>
> static const IID IID_Iy =
> { 0xfa198053, 0x7f5b, 0x43a2, { 0x88, 0x34, 0xd, 0xd3, 0x2e, 0xdb, 0x14,
> 0x9 } };
>
>
>
> IUnknown* createInstance()
> {
> IUnknown* pl = static_cast<Ix*>(new A);
> pl->AddRef();
>
> return pl;
> }
>
> int main()
> {
> HRESULT hr;
>
> IUnknown* pUnknown = createInstance();
>
> if (! pUnknown)
> return 1;
>
> Ix* pIx = NULL;
>
> hr = pUnknown->QueryInterface(IID_Ix,(void**)&pIx);
>
> if ( SUCCEEDED(hr) )
> {
> pIx->show();
> }
>
> delete pUnknown;
> return 0;
> }
>
> now I got output as
>
> In Ix
> in Iy
> in A
> 1
>
>
> I'm wondering how did it print 'in Iy' I never created an Instance of
> interface of that type !!!!
>
>
> Regards
>
> Nk
>


0
8/13/2003 9:38:22 AM
Reply:

Similar Artilces:

COM on 32 bit, 64 bit
I am learning COM and Windows programming so please forgive me if my question looks stupid to someone. I am writing a COM component for 32 bit platform and 64 bit platform. Consumer of my COM component runs on 32 bit platform and also on 64 bit platform using WoW64. I would like to know whether there could be any interoperability issues between my 64 bit component and my consumer, which runs on 64 bit platform using 32 bit binaries. Thanks in advance. Ganesh >I am writing a COM component for 32 bit platform and 64 bit platform. >Consumer of my COM component runs on 32 bit platform a...

Installing Publisher 2000 on Vista Home Premium 64 bit
Hello: I have a full version of Office 1997, and purchased Office 2000 upgrade version. Disk one of Office 2000 installed with no problem because I had an active version of Word already on the computer, and the product upgrade verification worked. When I tried to install disc 2 with Publisher, I got the error message that there was no compatible software to allow the upgrade, or something like that. I directed the verification process to look at my DVD drive, and inserted my full version disc 1 of Office 97. It would not verify, and therefore I can not istall Publisher. I did not h...

Certain operations EXTREMELY slow on 64 bit Vista Premium: opening file, printing,...
Certain operations are extemely slow. After I choose the command or menu item, the progress bar freezes about at the 50% point and there is no CPU or disk activity at all for over a minute. These operations have the problem: - Opening a file (even a tiny template) in CorelDraw X3 - Printing anything, on any network printer - Certain dialog boxes in certain applications Oddly, many apps seem to have no problem at all (eg Autodesk 3ds Max 2009, a 6 year old copy of Jasc Paint Shop Pro 8, etc). Also, although Coreldraw takes ages to open any file, it saves a file in normal time...

Convert 16 bit files to 32 bit files?
How can I convert 16 bit files to 32 bit files? Evan If you are talking just converting a few files I'd use Notepad. Open the file, change the type, and save it. Tom "Evan" <hurdevan@gmail.com> wrote in message news:1168888174.387049.179300@m58g2000cwm.googlegroups.com... > How can I convert 16 bit files to 32 bit files? > > Evan > Evan wrote: > How can I convert 16 bit files to 32 bit files? > > Evan > Evan: What are 16-bit and 32-bit files? Perhaps you mean 8-bit and 16-bit text files? David Wilkinson ...

Bit Locker
Is it safe/recommended to encrypt the a drive/volume which contains AD DB or SYSVOL? What kind of challenges does it pose? Hello Phillips, You can of course encrypt a DC drive with bitlocker, but in my opinion this makes only sense in an environment where a DC can not be physically safed. Also you have to keep in mind that this only helps, if the server is shutdown and should be started new without having the correct key available. there is no influence on the AD database or sysvol when bitlocker is used. See here about preparing a server core install for bitlocker: htt...

SqlConnect and ODBC on 64-bit Systems
Hi, I am calling SqlConnect as suggested by this article: http://msdn.microsoft.com/en-us/library/ms711810(VS.85).aspx On a 64-bit Vista Ultimate Sony Vaio laptop, I have noticed that SqlConnect always looks for the DSN in the 64-bit collection of ODBC connections. How can I get access, via MFC functions, to the 32-bit collection of ODBC connections? Thank you, Daniel Kemper, MCP, MCTS On Feb 1, 3:51=A0pm, dotBomb <dotB...@discussions.microsoft.com> wrote: > Hi, > > I am calling SqlConnect as suggested by this article:http://msdn.microsof= t.com/en-us/...

Change default enum size to 8-bit per definition?
Yellow In VS 6 (VC++) I would like to use enum to define a set of 8-bit opcodes in my messages destined for the serial port. The message structure itself is typedef'd with structures and unions and I would like to change the ucOpcode member to an eOpcode member. That is, instead of: UCHAR ucOpcode; I would like to use: MYOPCODE eOpcode; where I have defined: typedef enum tagMYOPCODE { MYO_OPC1 = 1, //you get the picture... } MYOPCODE; If I let the compiler use (int) for my enums, then my packet structure does not align. Is there a way to force this enum to bit 8 bits ...

8-bit color on starting Outlook 2003
Hi, Having a slight problem with Outlook 2003. I have put a shortcut in the Startup menu so that Outlook starts as soon as Windows has loaded... When I start my machine up and go into Outlook, the application displays in 8-bit color. If I close Outlook down, then open it again, it displays in the correct 32- bit color setting. Not really a huge issue, but it bugs me that I can't figure it out/fix it! Anyone have any ideas? ...

Exchange 2007 32-bit License aktivation
Hi, I have installed the 32-bit Exchange eval in our lab. This version expires in 100 days. I try to install a real license with -setExchangeServer, but I get an Productkey Error. My Lab Server have only a 32bit cpu so I can only install a 32 bit version for Testing, but I wont install a exchange server every 120 days. best regrads Holger Bunkradt It won't stop working after 120 days but afaik you'll have to live with the nag. As of now, you can't add a license key to the 32-bit version, and neither can you buy a license. -- Bharat Suneja MVP - Exchange www.zenprise.com N...

64 Bit Driver download with 32 bit machine
If I download a 64 bit video card driver, with a 32 bit machine, will there be a problem when I put the driver up on the 64 bit machine? Thanks Bob AZ no. It doesn't matter what machine does the download. It only matters that the correct driver be installed on the machine and OS for which it was designed. -- Charlie. http://msmvps.com/blogs/russel "Bob AZ" <rwatson767@aol.com> wrote in message news:2aa764a7-b454-4375-bef4-d31860d1fb98@s4g2000prh.googlegroups.com... > If I download a 64 bit video card driver, with a 32 bit machine, will >...

restoring GP 10.0 32-bit into GP 10.0 64-bit
Hello: We are going to install GP 8.0 on a 32-bit server in-house and restore a client's 8.0 data into these SQL databases. Pretty cut and dry. Next, we will upgrade this in-house server from 8.0 to 10.0. Continuing, we will install GP 10.0 on the client's new 64-bit server. Finally, we will restore the upgraded 10.0 databases from our in-house 32-bit server to the client's 64-bit server. Here's the question. Is there anything "wrong", from a technical standpoint, in restoring SQL databases from a 32-bit environment into a 64-bit environment? Thanks! chil...

flash and internet explore 8 34 bit?
Hello, Recentley i deleated the 34 bit version of what i believed to be either internet explorer 7 or 8. Currentley i am using the 64bit version of ie 8. I have recently noticed that flash does not work with this web browser. Upon going to the flash website, i am told to download the lower version of internet explorer 8. How do i do this? I go to the microsoft website and find the internet explorer download but it does not allow me to download the program. How can i install the 34bit version? Or, more preferably, how do i view webpages that require flash in internet explorer 8 6...

Confused
Can the Exchange Calendar Tool be run from a client, so long as the requirements are met, i.e., Windows XP SP2, Outlook 2003, .NET 2.0, and Outlook Zone Data Tool? If I run it from a client, do I still need to change the PickLogonProfile registry key to 0? I found this key on the Exchange, but not on the client. Next, do the users need to be logged off their Outlook when running the tool? And finally, I read the MsExTmz.ini file and I am now extremely confused. I don't know which parameters to change. I would like to be able to choose which mailboxes to update. Can anyone off...

32 bit or 64 bit
I have Windows XP on my S10 netbook. How do I determine whether it's 32 bit or 64 bit? Thanks much This has nothing to do with Word, but Control Panel > System should tell you the Windows version. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "Hank" <Ha...

Import 24-bit bitmap as an icon
I have a 24-bit bitmap of size 32 x 32, which I would like to use as the application's icon. I have two questions: 1. Can an icon have more than 256 colors? VStudio and some other icon editor applications (which I downloaded from web) do not allow more than 256 colors for icon files. 2. If #1 is not correct (i.e. if icon CAN have more than 256 colors), how do I use my 32 x 32 bitmap for application icon? Thanks in advance Abhijit Abhijit, The way to test this is to create a 24-bit icon and test it. Do this by creating an application with an icon, physically replacing the icon in the r...

Windows 7 HP upgrade 32 to 64 bit?
I have recently upgraded Windows Vista Home Premium SP2 to Windows 7 Home Premium 32bit. My desktop has 3.37 GB usable RAM and I am now considering doing a clean install to 64 bit. Is this possible using the Microsoft upgrade CD, please? -- plod A clean install is the only way you can go from 32-bit to 64-bit. Boot with the 64-bit disc and let it find the current installation then delete the partition with 32-bit Win 7 and proceed from there. On 2010-02-27 16:00, plod wrote: > I have recently upgraded Windows Vista Home Premium SP2 to Windows 7 > Home Premiu...

Confused about bitmap colours
I have to display a splash screen on startup and the splash screen component software I'm using (old Visual C++ 5 component gallery if memory serves) just puts up a bitmap. I am using VC++ 5 to build this particular app. The bitmap editor only allows me to use 16 colours. But if I edit the bitmap file using MS Paint, I can use all the colours I want, and save it as a 24-bit Bitmap, and everything appears to work fine. When I run the program, the splash screen looks OK with all colours present as far I can see. I haven't tried editing it in the Visual Studio bitmap editor - ...

32 bit and 64 bit OS
1. WinCE 4.2 is 32 bit 2. WinCE 5.0 and WinCE 6.0 is 64 bit OS. My question Are A. most of the Micro in RISC Arch. are 32 bit. Is there any advantage of using 64 bit OS with 32 bits Micro ? B. Is it possible to compile WinCE 5.0 and WinCE 6.0 as 32 Bit OS ? (I mean any compilation option) C. Any Application wich is compiled in 32 bit environment is it be possible to run in WinCE5.0 and WinCE 6.0 On Apr 15, 7:40=A0pm, S3c2410_invader <S3c2410inva...@discussions.microsoft.com> wrote: > 1. WinCE 4.2 is 32 bit > 2. WinCE 5.0 and WinCE 6.0 is 64 bit OS. > &...

Crystal Reports and 64 bit
Hi, First I want to apology if this is not the right place to ask. Please advice me where to move my question if this group is not the appropriate place. I've a .net 2.0 Windows Forms application that uses some COM components that are for 32bit only so I've set my target cpu to x86. My application uses also Crystal reports. My question is which version of the crystal reports redistributable should I use for 64 bit Windows installations - the 32, 64bit or maybe both? Thanks in advance. ...

How can I replace data in excel ?...Data positionsis a bit complic
Hello, I have in a cell : 250-PSA-AD46 I would like to replace 250 & AD46 by a space and keep the dashes and PSA in the middle. That was an example of the data I have ..Generically I would like to keep the data no matter what it is in the middle, and replace the others by a space!!! Thx ...a lot!!! Lets say your data is in cell A1: =REPLACE(REPLACE(A1,1,3,),6,4, -- renega ----------------------------------------------------------------------- renegan's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1045 View this thread: http://www.excelforum.com/show...

32 bit process & 64 bit driver, 32/64 bit pointer?
Hi, I am using MmMapLockedPagesSpecifyCache function to map my device memory RAM to user area. It is not a security conernt to me to do by this method. I want to support this for a 32 bit application, calls 64 bit driver(64 bit system), I am taking care of 32 bit process detection, In this case, if i uses above function, it returns a PVOID, I am not sure, will get a 32/64 bit pointer, but PVOID is 64 bit in 64 bit system? Is there any way to request only 32 bit User pointer from this API? Any coversion of mapping 64 bit userarea pointer to 32 bit different user area pointe...

Deleted user confused with active user w/same last name
There was a user in our org that is now deleted from the system that has the same last name as an active user still in the system. When someone tries to invite the active user to a meeting they are getting an email error back stating that the deleted user cannot be found in Exchange. The deleted user is not being selected in Outlook for the meeting but for some reason Outlook is trying to invite the wrong user to the meeting. I can't figure out why this is happening, does anyone have any suggestions what I can look for to correct this? Thanks. On 23 Jan 2006 18:25:39 -0800, tdunnusa@...

64-bit or 32-bit?
How can I tell from the content of an installation disk whether it disk is for 32-bit machine or 64? Or does it matter? Just curious. aaaaa <b@c.d> wrote in news:6kmgk59me62748ahg2rjgaqjpvo2caf4nb@4ax.com: > How can I tell from the content of an installation disk > whether it disk is for 32-bit machine or 64? Or does it > matter? Just curious. I have no personal experience with this, but I would assume that if your machine is 32bit and the software is 64bit, it will tell you it can not install or just sit there and do nothing. Also, decent software /should ...

How to Add Triangle Bit map to List Control Header
I would like to add the little triangle to a list control column header. When I look at Outlook Express columns, I can sort any column and the sorted column and direction is indicated by adding a small triangle to the right of the column header text. The triangle points up when the sort is top to bottom, down when the sort is the other way. Is there a description anywhere and/or sample showing how I can add the triangle bit map to the text inside the list control column header. I've implemented the toggling sort but I want to confirm to the user what has happened. Ed -- Edward E....

Can you Run 2 Servers 1 GP(64bit) and 1 Analysis Server (32 bit)?
I am trying to install GP9 SP3 on a Windows Server (64bit) and SQL2005 Analysis Services on a different server, Windows 2003 SP2 (32 bit). Will this configuration work? or does both GP9 and Analysis services need to be running on Window2003 Server in 32 bit mode? I know of one client that is running GP 10.0 on a 64bit Windows server. Your configuration should work. Jim "Peter" wrote: > I am trying to install GP9 SP3 on a Windows Server (64bit) and SQL2005 > Analysis Services on a different server, Windows 2003 SP2 (32 bit). > > Will this configuration work? ...