Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

QuickOPC-COM C++ Application crashing on callback

More
More
26 May 2014 13:50 #2000 by forestro
Hello,

Please, could you give me an example of your code of itemchanged ?

Please Log in or Create an account to join the conversation.

More
10 Mar 2011 09:31 - 27 May 2014 06:33 #328 by support
R.,

In order to resolve the crash, the customer needs to change the event handler signature from

HRESULT _stdcall OnItemChanged(_variant_t varSender, _variant_t varE);

to

HRESULT _stdcall OnItemChanged(VARIANT varSender, VARIANT varE);

Explanation: The handler is called from a system function and its parameters must match the function in sink interface precisely. While _variant_t is a class that is derived from tagVARIANT, it has different memory footprint from it.
If plain VARIANT is not convenient to use inside the handler code, it can be assigned to local variable of _variant_t type (but see the comment below – even that may not be necessary).

Other observation:

It would be much easier to access the parameters in the event handler using native COM support in C++. E.g. the beginning of the event handler can be rewritten like this, giving much more concise and readable code:
HRESULT COpcClient::OnItemChanged(VARIANT varSender, VARIANT varE) 
{
   UNREFERENCED_PARAMETER(varSender);
   try
   {
      IEasyDAItemChangedEventArgsPtr EventArgsPtr = varE;
      IDAItemDescriptorPtr ItemDescriptorPtr = EventArgsPtr->ItemDescriptor;
      _bstr_t bstrItemId = ItemDescriptorPtr->ItemId;
      // ...
   }
   catch (_com_error e)
   {
      return e.Error();
   }
   return S_OK;
}


Best regards,
Zbynek Zahradnik
Last edit: 27 May 2014 06:33 by support.

Please Log in or Create an account to join the conversation.

More
10 Mar 2011 09:31 #327 by support
<span style="font-family: "Tahoma","sans-serif"; font-size: 10pt; mso-fareast-font-family: 'Times New Roman'">From:<span style="font-family: "Tahoma","sans-serif"; font-size: 10pt; mso-fareast-font-family: 'Times New Roman'"> R.
Sent: Wednesday, March 09, 2011 2:39 PM
To: Zbynek Zahradnik
Subject: RE: Data-COM Application Crashing on Callback

Zbynek,

Attached is the sample project that the customer sent. I ran it on my machine and I was able to reproduce the issue.

R.

Please Log in or Create an account to join the conversation.

More
10 Mar 2011 09:29 #326 by support
<span style="font-family: "Tahoma","sans-serif"; font-size: 10pt; mso-fareast-font-family: 'Times New Roman'">From:<span style="font-family: "Tahoma","sans-serif"; font-size: 10pt; mso-fareast-font-family: 'Times New Roman'"> R.
Sent: Tuesday, March 08, 2011 7:37 PM
To: Zbynek Zahradnik
Subject: RE: Data-COM Application Crashing on Callback

The customer said he has both In-Process server and Local Server checked. He is working on extracting some code for a sample program.

R.

Please Log in or Create an account to join the conversation.

More
10 Mar 2011 09:28 #325 by support
Thank you.

I have realized one more thing that has big influence: Whether his settings allow Local server, In-process server (or both – not really recommended):




Untitled.png

When everything is alright, any setting should work, but since they work quite differently, it is important to know which one the customer is using – and also give a try to a different setting.

Regards,

<span style="font-family: "Arial","sans-serif"; color: #1f497d; font-size: 10pt">Zbynek Zahradnik

Please Log in or Create an account to join the conversation.

More
10 Mar 2011 09:27 #324 by support
<span style="font-family: "Tahoma","sans-serif"; font-size: 10pt; mso-fareast-font-family: 'Times New Roman'">From:<span style="font-family: "Tahoma","sans-serif"; font-size: 10pt; mso-fareast-font-family: 'Times New Roman'"> R.
Sent: Tuesday, March 08, 2011 5:43 PM
To: Zbynek Zahradnik
Subject: RE: Data-COM Application Crashing on Callback

Zbynek,

I have sent him a request for the smallest amount of code in his project that will reproduce the issue. Let’s see what he comes back with.

R.

Please Log in or Create an account to join the conversation.

More
10 Mar 2011 09:26 #323 by support
R.,
I will try to write a similar thing here and let you know then; can you please tell the customer to wait.

It could be related to threading, but not precisely the way you have suggested.

Can the customer provide bigger piece of his [code] to save us some work – and quickly get me closer to his state?

Regards,
<span style="font-family: "Arial","sans-serif"; color: #1f497d; font-size: 10pt">Zbynek Zahradnik

Please Log in or Create an account to join the conversation.

More
10 Mar 2011 09:24 #322 by support
From: R.
Sent: Tuesday, March 08, 2011 5:01 PM
To: Zbynek Zahradnik
Subject: Data-COM Application Crashing on Callback

Hello Zbynek,

I have a customer who submitted the following information regarding an issue he is seeing with the Data-COM.
***
I am trying to use EasyOPC-DA DLL (EasyOpcDALib) to get notifications when item state changes.

I created event sync by deriving a class from

IDispEventImpl<0, CQtOpcClient, &__uuidof(EasyOpcDALib::_IEasyDAClientEvents), &__uuidof(EasyOpcDALib::__EasyOpcDALib), 5, 0>

Then registered to receive item changed event:

BEGIN_SINK_MAP(CQtOpcClient)
SINK_ENTRY_EX(0, __uuidof(EasyOpcDALib::_IEasyDAClientEvents), 1002, &CQtOpcClient::OnItemChanged)
END_SINK_MAP()

Here 1002 is the ID of the ItemChanged method in _IEasyDAClientEvents interface

OnItemChanged method has the following signature:

HRESULT _stdcall OnItemChanged(_variant_t varSender, _variant_t varE)

The function is called properly with varSender and varE both being instances of IDispatch. However, upon return from OnItemChanged (I return S_OK) the OPC library crashes by jumping off to an invalid address (usually 0xfeeefeee). My OnItemChanged does not do anything with the arguments right now - it just returns S_OK.
***
W. and I have both looked this over, but as neither one of us knows C++ that well, we are a little lost for what to do. I have attached the dump file he provided me with. I was trying to run it through a dump file analysis tool, but the results I got weren’t helpful.

I’m guessing based on the error that is in the file that this is a threading issue- the event is coming back on a different thread than it was called on?

Thanks in advance,

R.
[attachment removed for privacy]

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.057 seconds