Adding a New Control to an Existing OCX

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to add a feature to this OCX: http://www.codeproject.com/KB/miscctrl/ntgraph_activex.aspx. Im trying to add a boolean flag to turn Engineering Notation on and off.<br/>
<br/>
I havent done much with OLE up to now, but have been programming in C and C++ for over 20 years. I believe the functionality of the connection should be very much like the functionality for ShowGrid at least as far as the interface goes. I copied
and renamed the functions and variables for ShowGrid, including adding a check box to the properties dialog.<br/>
<br/>
As far as I can tell, I got everything, but it wont initialize with the code in there. I can get it to initialize by commenting out the DISP_PROPERTY_NOTIFY and PX_Bool lines for the new variable, but I think Im missing something. I wwent back
to the original in VC 6 and added the new variable with the following tutorial: http://www.codeguru.com/Cpp/COM-Tech/activex/controls/article.php/c5517. It failed the same way my first attempt under VS 2005 failed.<br/>
<br/>
When I run an application in Debug mode, it crashes in occcont.cpp at line 926:<br/>
<br/>

<div style="color:black; background-color:white
<pre> COleControlSiteOrWnd *pTemp =
<span style="color:blue new COleControlSiteOrWnd(
hwndCtrl,
pOccDlgInfo->m_pItemInfo.bAutoRadioButton);
ASSERT(IsWindow(pTemp->m_hWnd));
[/code]

<br/>
When I run an application in Release mode, it crashes with a message saying "An unsupported operation was attempted" and the application hangs.<br/>
<br/>
In NTGraphCtl.h:<br/>
<br/>
<div style="color:black; background-color:white
<pre> BOOL m_bEngNotation;
afx_msg <span style="color:blue void OnEngNotation();

In the <span style="color:blue enum
dispidEngNotation = 43L,
[/code]

<br/>
In NTGraphCtl.cpp:<br/>
<div style="color:black; background-color:white
<pre> In function BEGIN_DISPATH_MAP
DISP_PROPERTY_NOTIFY(CNTGraphCtrl, <span style="color:#a31515 "EngNotation", m_bEngNotation, OnEngNotation, VT_BOOL)

In function DoPropExchange
PX_Bool(pPX,_T(<span style="color:#a31515 "EngNotation"),m_bEngNotation ,FALSE);

<span style="color:blue void CNTGraphCtrl::OnEngNotation() <span style="color:green //WDO 8/11/11
{
InvalidateControl();
SetModifiedFlag();
}
[/code]

<br/>
In NTGraphPpg.h:<br/>
<div style="color:black; background-color:white
<pre> BOOL m_bEngNotation;

[/code]

<br/>
In NTGraphPpg.cpp:<br/>
<div style="color:black; background-color:white
<pre> Function CNTGraphPropPage() (constructor)
m_bEngNotation = FALSE;

DoDataExchange
DDP_Check(pDX, IDC_CHECK_ENGNOTATION, m_bEngNotation, _T(<span style="color:#a31515 "EngNotation") );
DDX_Check(pDX, IDC_CHECK_ENGNOTATION, m_bEngNotation);

[/code]

<br/>
What am I doing wrong?
EDIT:
1) I am unregistering and reregistering the OCX after each build.
2) I get the same behavior with the Debug and Release versions of the OCX.

EDIT2:
Figured out how to run the debugger on an OCX. The failure is happening in DoPropExchange. If the PX_Bool line is in the middle of the function, it fails on the second call from the end which is this line:

<pre lang="x-cpp PX_Picture(pPX, "PlotAreaPicture",m_picPlotArea);[/code]
If I put the PX_Bool line for the new variable as the last line in the function, it fails on that line.

I still dont understand why though.



View the full article
 
Back
Top