Gopi Krishna Komanduri wrote:
> Hi Folks,
> I have written a code ... which is some simulation for COM (not a
> complete COM , just Query Interface .. that tooo only 1 method I kept) . But
> my app is crashing whenever I am trying to access that medthod. I copy
> pasted the code . Please look into it . I marked those lines in red which are
> making app to crash.
>
>
>
>
> #include<stdio.h>
> #include<conio.h>
> #include<windows.h>
>
> struct IUnkn
> {
> virtual HRESULT QI(int IId,IUnkn **ptr) = 0;
> virtual void display()=0;
>
> };
> class MyOuterClass
> {
> public:
> int refCount;
> class MyInnerClass:public IUnkn
> {
> public:
> virtual HRESULT QI(int IId,IUnkn **ptr)
> {
> if(IId == 1)
> {
> IUnkn *pThis = (IUnkn *)((BYTE *)this+(int )(&(((class
> MyOuterClass *)0)->m_InnerObj)));
I have no idea what you are wanting to accomplish here, but this is
likely the culprit. '((class MyOuterClass *)0)' is essentially NULL and
-> then dereferences the pointer.
> *ptr = pThis;
> return 1;
> }
> *ptr = NULL;
> return 0;
> }
> virtual void display()
> {
> printf("\n I am in show method");
> }
>
> }m_InnerObj;
> friend class MyInnerClass;
> };
> void CreateObject(int IId,IUnkn **ptr)
> {
> MyOuterClass obj;
> obj.m_InnerObj.QI(IId,ptr);
> (*ptr)->display();
>
> }
>
> void main()
> {
>
> IUnkn *x;
> CreateObject(1,&x);
> x->display();
> }
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/