Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT! Object Pointer Problem

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB
Dear All,

I have quite a major problem. I have a dialog MFC application with an ActiveX component embedded into the dialog. I have created objects that are generated on pressing certain buttons in the dialog. (COneDialog class). The objects are generated one after each other.
The problem i am having is that i now wish to access a pointer to the ActiveX component (the pointer is produced in the Dialog class). I cannot simply

#include "OneDlg.h"

in my calling class as this ripples to the top of the object tree and causes compilation errors.

Does anyone know of another method i can get around this problem?

I've been stuck on this for ages and any suggestions would be very much appreciated.

Thank you to anyone who supplies me with idea's.

Mark.
 
This is just two sample classes.

//////////////////////
// CLASS_A.H


class A {
// ...
}

//////////////////////
// CLASS_B.H


class A; // this is what you do.

class B {
public:
B::B();
B::~B();

A* GetPointerToA();

private:
A* pointer_to_A;
}

/////////////////////////
// CLASS_B.CPP


#include "Class_B.h"
#include "Class_A.h" // HERE is where you include the class

B::B
{
}

B::~B
{
delete pointer_to_A;
}

A* B::GetPointerToA()
{
return pointer_to_A;
}
 
I'm not sure what you mean;
>>the pointer is produced in the dialog class

Does this mean that the pointer is already there, but you want to access it from somewhere else in your application?

>>I cannot simply

#include "OneDlg.h"

in my calling class as this ripples to the top of the object tree and causes compilation errors.


Is this maybe the actual problem? In that case, have you tried forward declarations in the class definitions that need to access "OneDlg"?

Greetings,
Rick
 
Dear All,

Thank you to apatterno for allowing me to call a method in the class i needed to. I have another problem though as i wish to use a pointer that is within that class: For example i have called the pointer to the class and this runs the following method:

void COneDlg::ChangeRecordingFrequency(double RecordingFrequency)
{
m_pWinTV->SetFrequency(RecordingFrequency);

}

The following error is given on the break:

Unhandled exception at 0x00414c1e in One.exe: 0xC0000005: Access violation reading location 0xcdcdce41.

I know that the error comes from using the m_pWinTV pointer. Although this pointer is used by other functions in the method so i know it works.

I have tried calling the functions within the class and i still get the same problem. Therefore does the computer know that i'm trying to access this pointer from another pointer?

Does anyone know how i get around this problem?

Thank you again to anyone who helps.

Mark.
 
I could amost bet that m_pWinTV never gets instantiated.

Do you
m_pWinTV = new TheCassName;

in the constructor or elsewhere?
 
Hi thebarslider
That error might be coming due to line "delete pointer_to_A;"..stop this line and it will work for you
hope it helps
 
Dear pankajkumar,

Thank you for your suggestions but i have got this working with the above apatterno method.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top