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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Pointers

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB
Dear All,

I have a problem with pointers. I have a pointer to a class that is used to call a function. Within the called function i wish to access a pointer that is declared in the class that contains the called function.

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);

}

Using the debugger i know that the function is called but my program breaks when i attempt to use the m_pWinTV pointer.

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 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?


I just don't follow most of that,
this pointer is used by other functions in the method
is really confusing. What is the "value" of m_pWinTV at the time the error occurs?

certainly if m_pWinTV is NULL or even worse, invalid, you would get the error you are seeing.

-pete

 
Hey there,

Sorry, my post is really confusing. I have redesigned my code since i posted on here.

My program works like this: A thread is calling a function which executes at a given time. In the (thread called) function i wish to change a variable of an ActiveX control that is inserted into my dialog. I access functions in the ActiveX control i using the m_pWinTV pointer.

This pointer is initialised when the dialog is created. It is possible to set handler functions in the dialog class to access functions of the ActiveX control when a button is pressed.

For example:

void COneDlg::OnBnClickedButton4()
{
m_pWinTV->SetFrequency(105.8);

}

All i wish to do is execute the same function with a given parameter to SetFrequency when the thread tells me the time is correct to change the frequency.

I have attempted to do this by getting a pointer to OneDlg then passing the SetFrequency function a parameter.

Therefore the thread executes when the time is correct and runs a given function. The function includes a pointer to OneDlg and runs a function in OneDlg that attempts to excute code similar to the code given above. i.e. SetFrequency method.

I know the SetFrequency method is executed but i recieve an assertion failure error farer into the method. I dont understand why this is happening as i am able to change the Frequency with a button press (in the above example) using the same code.

I originally thought the problem arouse due to the thread calling member functions accross thread boundaries. So i changed the code so it posted a message to OneDlg instead but still recieved the same error.

Hope this makes it a little clearer, it is quite hard to explain i hope you understand.

Mark.
 
Hey everyone,

I have solved this problem so require no further help.

Thanks anyway to everyone.

Good luck with your programming.

Mark.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top