Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 13th, 2005, 06:43 AM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Debug assertion about m_pCtrlSite

Dear
I am working with the visual C++ version 6 for some programming in
which it can handle input and output data storage and data displaying
system. for all purpose I am using around 4 dialog boxes.

In one dialog(CReportDlg derived from CDialog) box I used an ActiveX Control named m_cell for output. In my main dialog I have defined:
 CReportDlg dlg;
and I defined a button to call the CReportDlg like this:

void CMainDlg::OnButton(void)
{
    dlg.m_cell.SetCols(6,0);//debug assertion£¡£¡£¡
    dlg.m_cell.SetRows(100,0);//debug assertion!!!
    ...
    dlg.DoModal();

}

The trueth is there will be a debug assertion while I call any m_cell's function in main dialog.

I figured that it comes from the line

ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)

which is inside:

void AFX_CDECL CWnd::InvokeHelper(DISPID dwDispID, WORD wFlags, VARTYPE vtRet,
void* pvRet, const BYTE* pbParamInfo, ...)
{
ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)

if (m_pCtrlSite == NULL)
return;

va_list argList;
va_start(argList, pbParamInfo);
m_pCtrlSite->InvokeHelperV(dwDispID, wFlags, vtRet, pvRet, pbParamInfo,
argList);
va_end(argList);
}



But what is m_pCtrlSite? It's COleControlSite* object in the afxwin.h file. Did I miss anything while using the ActiveX object?

Thanks in advance.



[email protected]
 
Old November 13th, 2005, 08:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

The control on the dialog box is not getting initialized. It will get initialized only after you have called DoModal() 'cause that is when the dialog box prepares to load itself and the cotrol on it get initilized.
Dealing with a member element outside the class it belongs to is against the priniciple of modularity as well.

So pass the values that you want to set to your ActiveX Control as a parameter of a constructor of the CReportDlg when you declare its object and set these values to the ActiveX control later in OnInitDialog of CReportDlg (u'll have to define a contructor for CReportDlg for this purpose)
or
define a function and a few data members in CReportDlg. Use this function to set the values of these data members
instead of this code

    dlg.m_cell.SetCols(6,0);
    dlg.m_cell.SetRows(100,0);

Then once you have called DoDialog the OnInitDialog of CReportDlg will be called where you can set the values to the activex control on the dialog.

Regards
Ankur Verma
 
Old November 13th, 2005, 10:07 AM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for you fervor.

I tried as you said, but still some problems as above.first,I set the ActiveX Control to be protected and initialize it in the OnInitDialog:

CCell2000 m_cellReport;//defined in ReportDlg.h

BOOL CReportDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    m_cellReport.ShowHScroll(0,0); //here I and the code
    m_cellReport.SetCols(6,0);
    m_cellReport.SetRows(100,0);

    return TRUE;
}

then I add a member function SetData like this:

void CReportDlg::SetData(int row, int col, int num)
{
    m_cellReport.SetCellDouble(row, col, 0, num);
}

after that I call the function in main dialog:

void CMainDlg::OnButton(void)
{
    CReportDlg dlg = new CReportDlg;
    dlg.SetData(1, 1, 10); //function call
    dlg.DoModal();
}
at all when i run the program the debug assertion come out as i mentioned above.

ASSERT(m_pCtrlSite != NULL); // not an OLE control (not yet, at least)

How can I solve this problem?

Thanks in advance

Terry Yu


[email protected]
 
Old November 13th, 2005, 09:00 PM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OnButton function should like this:
void CMainDlg::OnButton(void)
{
    CReportDlg* dlg = new CReportDlg;
    dlg->SetData(1, 1, 10); //function call
    dlg->DoModal();
}

but debug assertion failure still appear when I click the button.

thanks in advance.
Terry Yu


[email protected]
 
Old November 13th, 2005, 09:28 PM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I use ActiveX control's Create function to initial it instead of DDX_Control,the problem occurs same way.

[email protected]
 
Old November 14th, 2005, 12:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

If you move the line of code

m_cellReport.SetCellDouble(row, col, 0, num);

from SetData to OnInitDialog your problem should be solved.

You have to understand that you cannot expect m_cellReport to be in proper shape before the call to DoModal.
SetData should be used only to set the values of some internal member variables.
Declare threee member variables in report dialog col, row and num and set their values in SetData.
then call DoModal, which subsequently invokes oninit....
where you could initialize m_cellReport.

Regards
Ankur Verma
 
Old November 14th, 2005, 03:21 AM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Ankur_Verma
Thanks for you fervor and insight.I know what the problem is,the CReportDlg and m_cellReport are not initialized properly.and i think you haven't understood what i done exactly.

There are two dialogs CMainDlg and CReportDlg, the m_cellReport is included in CReportDlg.In CMainDlg.cpp I want to set data into the m_cellReport(activex control),so i call it's member function in CMainDlg.cpp or CReportDlg.cpp to set data or do some other things. the problem is listed above.

when i debug by step i found the CReportDlg's hWnd = 0x0 and CCell2000's hwnd is also 0x0(so m_pCtrlSite have to be 0x0),they were not initialized properly. now my question is where should i initialize these two class instance and how to initialize them?

(I am a newer plz bear me)

thanks in advance.

Terry Yu

[email protected]
 
Old November 14th, 2005, 06:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

 Terry, I think your earlier mails communicated the problem quite descriptively and I understood your problem.
CMainDlg loads CReportDlg and m_cellReport is a member of CReportDlg. This is what I've been able to gatther. (please verify)

Now let me walk you through the right sequence again.
The sequence has to be
Load CReportDlg, and only when its loaded (Remember- only once the CReportDlg has loaded, because its then that the ActiveX control gets initialized), do whatever it is that you wanna do with the ActiveX control.


Now, because you cannot deal with m_cellReport before CReportDlg has loaded itself, you will have to wait for
CReportDlg to load itself properly. Untill then you'll have to store the data temporarily in some member variable.
Since DoModal will load the CReportDlg in a modal way the control will shift to CReportDlg and you wont be able
to call any fucntion of CReportDlg class from outside till you close the CReportDlg dialog.

So what you have to do is to define some member variables in CReportDlg and store the data in them (instead of dealing with m_cellReport at this point) and wait for CReportDlg to load itself completely. Once it is detected that CReportDlg has loaded (which also means that m_cellReport is in proper shape) you can deal with m_cellReport without running into any problem. CReportDlg's OnInitDlg... thus is the ideal place to deal with m_cellReport.

So what you have to do now is
1. define some member variables in CReportDlg and
2. set their values with the relevent data from CMainDlg (dont poke CReportDlg's m_cellReport at this point).
3. call DoModal, which will shift the control to CReportDlg
4. in CReportDlg's OnInit... set the values of these member values to the ActiveX control and deal with m_cellReport in whatever way you want.

and yes, all my friends call me Ankur_Verma (pronounce Ankur underscore Verma) only, so what you did was nothing new. I'm also known to have responded to just "Ankur" though. So you might wanna try that.

Regards
Ankur Verma
 
Old November 14th, 2005, 07:25 AM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Ankur
Thanks for you help,I am very delight to cummunicate and discuss program things with you. your enthusiasm impressed me so much and I learnt a lot through your words and advice.

Now i know how to deal with the problem i encountered. thanks indeed once more.

i still have a question. is the domodal the only way to initialize a dialog?

i want to store some data into the m_cellReport real time,and let the CReportDlg to report them wherever i want, is there any way i can call the ActiveX control's member function directly in the CMainDlg?if the CReportDlg is initialized before the function call, my thought may feasible. so how can i initialize the CReportDlg invisible? if it is initialized along with CMainDlg,it will make me easier.

Thanks in advance
Terry Yu

[email protected]
 
Old November 14th, 2005, 11:00 AM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Ankur

 I'v got through the problem with you help.

 Thank you very much.

Terry Yu

[email protected]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmer's assertion in getNextStepPos dishant XSLT 1 April 11th, 2008 09:48 AM
what is an assertion? coreyalbrightsr Java Basics 3 October 2nd, 2007 06:54 PM
Debug assertion failure for wincore aparnakamath2000 Visual C++ 0 August 28th, 2007 05:49 AM
"Debug Assertion Failure" elleetan Visual C++ 3 September 20th, 2005 06:25 AM
Help in Assertion failure abdelkader Visual C++ 0 December 30th, 2003 10:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.