Board index » cppbuilder » COM Automation Events Problems

COM Automation Events Problems


2004-05-11 09:28:06 PM
cppbuilder77
I created a COM Automation server with events that worked fine with the
default code when I had 4 events or less. I exapanded the number of events
and then started to get the following error:
0@ c:\program files\borland\cbuilder6\include\atl\atlcom.h/4848
multiple time corresponding to the number of events that I added. I was
able to make this error go away by changing the auto-generated code as
recommended by the autogenerated comments:
class TEvents_ASDS_HM_CommsC : public IConnectionPointImpl<T,
&DIID_IASDS_HM_CommsCEvents,
CComUnkArray<CONNECTIONPOINT_ARRAY_SIZE>>
/* Note: if encountering problems with events, please change CComUnkArray
to CComDynamicUnkArray in the line above. */
I Changed the CComUnkArray<CONNECTIONPOINT_ARRAY_SIZE>to
CComDynamicUnkArray and everything compiles fine and I no longer get the
above error. Now, though, my events fail to execute. The fire methods
generated by Borland don't execute properly - Example:
template <class T>HRESULT
TEvents_ASDS_HM_CommsC<T>::Fire_Run(void)
{
T * pT = (T*)this;
pT->Lock();
IUnknown ** pp = m_vec.begin();
while (pp < m_vec.end())
{
if (*pp != NULL)
{
m_EventIntfObj.Attach(*pp);
m_EventIntfObj.Run();
m_EventIntfObj.Attach(0);
}
pp++;
}
pT->Unlock();
}
The above function doesn't pass the if (*pp != NULL) test, and therefore
never executes the .Run() function. The m_vec seems to be the problem. Any
Idea how to fix this issue?
Thanks,
Jason Stipes
 
 

Re:COM Automation Events Problems

Jason,
I used to work on C++Builder COM Automation Events and wrote the original
utilcls.h. Back then my intention was to have someone redefine
CONNECTIONPOINT_ARRAY_SIZE. There's a comment to that effect in utilcls.h
still:
// CONNECTIONPOINT_ARRAY_SIZE is used by the Fire_xxxx Event templates
generated for
// outgoing interfaces in the xxxx_TLB.H file.
//
// Redefine this macro if you want your server to support more (or fewer )
sinks.
#if !defined(CONNECTIONPOINT_ARRAY_SIZE)
#define CONNECTIONPOINT_ARRAY_SIZE 5
#endif
But that was a long long time ago and the person who took over might have
found a better approach that adjusts the array dynamically.
It turns out that I might be working on COM again soon [after being away
from that area of code for about 5 years].... so I'll take a look at that.
In the meantime I would suggest the old remedy: In the C++ file that
includes the header with TEvents_ASDS_HM_CommsC, add the following
#define CONNECTIONPOINT_ARRAY_SIZE 10
Adjust the size accordingly.
Make sure that the macro precedes the inclusion of the file utilcls.h.
Alternatively you can also define this macro in the compiler options for
that particular C++ file.
Let me know if this does not work somehow - it used to :)
Regards,
Bruneau.
"Jason Stipes" < XXXX@XXXXX.COM >wrote in message
Quote
I created a COM Automation server with events that worked fine with the
default code when I had 4 events or less. I exapanded the number of
events
and then started to get the following error:

0@ c:\program files\borland\cbuilder6\include\atl\atlcom.h/4848

multiple time corresponding to the number of events that I added. I was
able to make this error go away by changing the auto-generated code as
recommended by the autogenerated comments:

class TEvents_ASDS_HM_CommsC : public IConnectionPointImpl<T,

&DIID_IASDS_HM_CommsCEvents,

CComUnkArray<CONNECTIONPOINT_ARRAY_SIZE>>
/* Note: if encountering problems with events, please change CComUnkArray
to CComDynamicUnkArray in the line above. */

I Changed the CComUnkArray<CONNECTIONPOINT_ARRAY_SIZE>to
CComDynamicUnkArray and everything compiles fine and I no longer get the
above error. Now, though, my events fail to execute. The fire methods
generated by Borland don't execute properly - Example:

template <class T>HRESULT
TEvents_ASDS_HM_CommsC<T>::Fire_Run(void)
{
T * pT = (T*)this;
pT->Lock();
IUnknown ** pp = m_vec.begin();
while (pp < m_vec.end())
{
if (*pp != NULL)
{
m_EventIntfObj.Attach(*pp);
m_EventIntfObj.Run();
m_EventIntfObj.Attach(0);
}
pp++;
}
pT->Unlock();
}

The above function doesn't pass the if (*pp != NULL) test, and therefore
never executes the .Run() function. The m_vec seems to be the problem.
Any
Idea how to fix this issue?

Thanks,

Jason Stipes


 

Re:COM Automation Events Problems

No, it is still CONNECTIONPOINT_ARRAY_SIZE.
Generally, we manually write ours usin CComDynamicUnkArray.
"Jean-Marie Babet" < XXXX@XXXXX.COM >wrote in message
Quote
Jason,

I used to work on C++Builder COM Automation Events and wrote the original
utilcls.h. Back then my intention was to have someone redefine
CONNECTIONPOINT_ARRAY_SIZE. There's a comment to that effect in utilcls.h
still:

// CONNECTIONPOINT_ARRAY_SIZE is used by the Fire_xxxx Event templates
generated for
// outgoing interfaces in the xxxx_TLB.H file.
//
// Redefine this macro if you want your server to support more (or fewer )
sinks.

#if !defined(CONNECTIONPOINT_ARRAY_SIZE)
#define CONNECTIONPOINT_ARRAY_SIZE 5
#endif


But that was a long long time ago and the person who took over might have
found a better approach that adjusts the array dynamically.


It turns out that I might be working on COM again soon [after being away
from that area of code for about 5 years].... so I'll take a look at that.
In the meantime I would suggest the old remedy: In the C++ file that
includes the header with TEvents_ASDS_HM_CommsC, add the following

#define CONNECTIONPOINT_ARRAY_SIZE 10

Adjust the size accordingly.

Make sure that the macro precedes the inclusion of the file utilcls.h.

Alternatively you can also define this macro in the compiler options for
that particular C++ file.

Let me know if this does not work somehow - it used to :)

Regards,


Bruneau.




"Jason Stipes" < XXXX@XXXXX.COM >wrote in message
news:40a0d4e5$ XXXX@XXXXX.COM ...
>I created a COM Automation server with events that worked fine with the
>default code when I had 4 events or less. I exapanded the number of
events
>and then started to get the following error:
>
>0@ c:\program files\borland\cbuilder6\include\atl\atlcom.h/4848
>
>multiple time corresponding to the number of events that I added. I was
>able to make this error go away by changing the auto-generated code as
>recommended by the autogenerated comments:
>
>class TEvents_ASDS_HM_CommsC : public IConnectionPointImpl<T,
>
>&DIID_IASDS_HM_CommsCEvents,
>
>CComUnkArray<CONNECTIONPOINT_ARRAY_SIZE>>
>/* Note: if encountering problems with events, please change
CComUnkArray
>to CComDynamicUnkArray in the line above. */
>
>I Changed the CComUnkArray<CONNECTIONPOINT_ARRAY_SIZE>to
>CComDynamicUnkArray and everything compiles fine and I no longer get the
>above error. Now, though, my events fail to execute. The fire methods
>generated by Borland don't execute properly - Example:
>
>template <class T>HRESULT
>TEvents_ASDS_HM_CommsC<T>::Fire_Run(void)
>{
>T * pT = (T*)this;
>pT->Lock();
>IUnknown ** pp = m_vec.begin();
>while (pp < m_vec.end())
>{
>if (*pp != NULL)
>{
>m_EventIntfObj.Attach(*pp);
>m_EventIntfObj.Run();
>m_EventIntfObj.Attach(0);
>}
>pp++;
>}
>pT->Unlock();
>}
>
>The above function doesn't pass the if (*pp != NULL) test, and
therefore
>never executes the .Run() function. The m_vec seems to be the problem.
Any
>Idea how to fix this issue?
>
>Thanks,
>
>Jason Stipes
>
>


 

{smallsort}