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.

How to pass a pointer to the CallBack method assigned to an item by "SubscribeMultipleItems" method in VS C++?

More
09 Mar 2016 08:44 - 09 Mar 2016 08:45 #3913 by fluppe
Hi and thanks again,

"2)" is exactly what i am trying right now. And thanks for hint with pointer sized variables.
That will definitely help me a lot.
I think i will check the example you mentioned as soon as possible.

Thanks and best regards,
...

p.s.: I could not find how to mark that as "solved", is there some way ?
Last edit: 09 Mar 2016 08:45 by fluppe.

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

More
04 Mar 2016 12:03 #3906 by support
QuickOPC is exposed to the C/C++ world in form of Microsoft COM objects. The State argument appears as Windows VARIANT structure (msdn.microsoft.com/en-us/library/windows/desktop/ms221627(v=vs.85).aspx ) there. That's all we care about on our side. On the consuming (C/C++) side, the VARIANT can be processed e.g.

1) "as is", with help of Win32 API functions that work with VARIANT-s (e.g. msdn.microsoft.com/en-us/library/windows/desktop/ms221673(v=vs.85).aspx ).

2) Using Microsoft C++ "Native COM support" - which is what you are using if you #import the type library. In this case, VARIANT is wrapped as _variant_t (msdn.microsoft.com/en-us/library/x295h94e.aspx ).

3) Using Microsoft ATL; in this case, one uses the CComVariant class (msdn.microsoft.com/en-us/library/ac97df2h.aspx ). Actually, in some our example, we combine ATL with the native COM support, because ATL allows to write the event hooking code better.

4) and obviously the list is open and other methods can be used as well. For example, I am aware that one of our customers have used a portable library called VOLE which has its own encapsulation for VARIANT-s.

Yes, I suggest to use integers to store the pointers. Besides traditional options such as VT_INT or VT_LONG, there are even pointer-sized VARTYPE-s (see msdn.microsoft.com/en-us/library/windows/desktop/ms221170(v=vs.85).aspx ) such VT_INTPTR, VT_UINTPTR that are properly sized to the bitness of the project. It might be even be possible to use VT_PTR, but we have not tested it.

BTW, are you aware of the SubscribeMultipleItems example project for C++ which comes with the product? It does not have the State passing part, but besides that, it is a good starting point.

Best regards

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

More
02 Mar 2016 08:30 #3897 by fluppe
Hi again and thanks for answering my question so quick.

I am not sure if i got everything right so far.
To clarify: That "Object" in C# is transformed into a variant because i #import the ".tlb" files ? I am quite a newbie in that field, and i do not know what really happens behind the scenes ...
What is meant by " ... only one of the options" ??

And you suggest to use the integer values to store the pointers, is that right ?

I' ll have a look at that link.
Thanks and best regards so far,
...

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

More
02 Mar 2016 07:30 #3896 by support
_variant_t is a C++ wrapper around Windows VARIANT structure, which can hold many different data types, including 32- and 64-bit integers which can represent pointers. QuickOPC, in fact, has no knowledge of the fact that the 'object' in the underlying .NET interface becomes a VARIANT when exported to COM, and then this further is transformed to a _variant_t when you use #import to import the COM type library of QuickOPC into C/C++ (which is just one of the options).

Passing a pointer is therefore a matter of storing it into _variant_t, and then extracting it back. Various _variant_c constructors and other members are described here: msdn.microsoft.com/en-us/library/x295h94e.aspx .

Let me know if you need further help with that.

Best regards

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

More
01 Mar 2016 17:08 - 02 Mar 2016 07:10 #3895 by fluppe
Hi,

i am not sure, maybe that was posted before ... [EDIT] it was! i just thought it was somehow not transmitted, sorry [/EDIT]
Last edit: 02 Mar 2016 07:10 by fluppe.

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

More
01 Mar 2016 17:00 #3894 by fluppe
Hi,
i am using the QuickOPC libraries for few hours now and i wonder how to get a pointer into the CallBack function ...

I tried that while editing the "ExampleCom\CPP\VS2012" ... SubscribeMultipleItems"

The callbacks interface is
STDMETHOD(ItemChanged)(VARIANT varSender, _EasyDAItemChangedEventArgs* pEventArgs)

The thing is that i have read here that one can use the "_EasyDAItemChangedEventArgs* pEventArgs" -> "State" in C# to supply a reference to some object, but it turned out to be a "_variant_t" in C++ and i do not know how to put a pointer into that.

So is there a way to put a pointer somewhere else into the "pEventArgs" ? Or can anyone tell me how to achieve that via a variant ?

I know that i can put my address value into a suitable integer value, but I'd like to avoid that, if possible. Also i did not use globals yet.

Any hint will be greatly appreciated and thanks in advance,

....

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

Moderators: support
Time to create page: 0.057 seconds