If anyone has ideas, please respond.
"Dave" <no...@nowhere.com> wrote in message
news:eoGZqnV8BHA.1292@tkmsftngp07...
> See the attached screenshot for what is happening.
>
> Basically, the "groups" variable should have a value of an object of
> OPCGroups but it appears to have a value of OPCServer. I don't understand
> why. server.OPCGroups returns an OPCGroups object but in the debug window
> it shows it as an OPCServerClass object..
>
> Can anyone see anything wrong with that code? Why in the world is it
doing
> that?
>
> The equivalent code works fine in VB6. Is this some weird bug in COM
> interop?
>
>
>
read
http://www.codeproject.com/useritems/opcdotnet.asp
(updated download: http://www.viscomvisual.com/dotnet/ )
also visit:
http://www.opcconnect.com/tooltech.shtml
--
NETMaster (Thomas Scheidegger)
http://www.cetus-links.org/oo_csharp.html
"Dave" <no...@nowhere.com> wrote in message news:eWoEy3V8BHA.1380@tkmsftngp03...
So what we're saying is, COM Interop doesn't really work 100% of the time?
I thought the /sysarray switch on tlbimp was supposed to compensate for
non-zero based Automation arrays?
This statement from http://www.opcconnect.com/tooltech.shtml just isn't true
then:
"If you're happy using the OPC Automation interfaces, then a reference to
the Automation server or DLL may be added directly to your .NET project.
Coding with C# or your favorite .NET language is then straightforward."
"NETMaster" <spam.ne...@swissonline.ch> wrote in message
news:#pGUwpa8BHA.2152@tkmsftngp02...
first AFAIK console apps should have [MTAThread] for Main().
I guess you have the good old collection / CreateWrapperOfType problem:
this quick & dirty hack works for me:
// ===============================================================
server = new OPCServerClass();
server.Connect( "?????????????", null );
// this cast fails:
// OPCGroupsClass ogrps = (OPCGroupsClass) server.OPCGroups;
object tmpg = server.OPCGroups;
OPCGroupsClass ogrps = (OPCGroupsClass) Marshal.CreateWrapperOfType( tmpg, typeof(OPCGroupsClass) );
tmpg = null;
int ct = ogrps.Count;
OPCGroupClass og = (OPCGroupClass) ogrps.Add( "MyNewGroup" );
ct = ogrps.Count;
int ur = og.UpdateRate;
Marshal.ReleaseComObject( og );
og = null;
ogrps.RemoveAll();
Marshal.ReleaseComObject( ogrps );
ogrps = null;
server.Disconnect();
Marshal.ReleaseComObject( server );
server = null;
// ===============================================================
--
NETMaster (Thomas Scheidegger)
http://www.cetus-links.org/oo_csharp.html
"Dave" <no...@nowhere.com> wrote in message news:#7CIi#f8BHA.2540@tkmsftngp04...
What is this "collection / CreateWrapperOfType problem" you speak of? Do
you have any links to information about it?
--
NETMaster (Thomas Scheidegger)
http://www.cetus-links.org/oo_csharp.html
"Dave" <no...@nowhere.com> wrote in message news:uqycliu8BHA.2244@tkmsftngp03...
The opcdaauto.dll behaves different from what its type library says. The
type library indicates that there are three different coclasses: the
server, the groups, and the group. It indicates that when you call
get_OPCGroups you get a Groups object.
You don't.
The server object and the Groups object are one and the same. When you
call get_OPCGroups you just get a different interface pointer to the same
object (the server object). This does not pose a problem with classic COM
clients (VB6, C++) but it causes a big problem with .NET.
NET checks the COM identity rule of the interface pointer that it gets
back from get_OPCGroups, and realizes that it is the same object as the
server object. Since it already has a RCW for the server object, it just
uses the same wrapper for the new pointer.
Andy DeMaurice
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--
NETMaster (Thomas Scheidegger)
http://www.cetus-links.org/oo_csharp.html
"Andy DeMaurice [MS]" <andr...@online.microsoft.com> wrote in message news:H512aCMDCHA.1908@cpmsftngxa07...