找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2958|回复: 0
打印 上一主题 下一主题
收起左侧

(原创)关于opc开发中碰到的一个小问题到对COM的理解

[复制链接]
跳转到指定楼层
楼主
ID:102668 发表于 2016-1-16 03:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
郑重声明:本帖是作者原创,转载请注明作者,让俺也沽名钓誉一把,嘿嘿

前一段时间一直在做OPCAE的服务器端和客户端的开发,在开发的过程中碰到了一个问题。要求连接的是siemens sipass的opc AE,sipass做客户端,我做服务器,发送报警信息。开发完了以后,先运行服务器程序,然后再用客户端来连接,连接不上,很是奇怪,因为用别的客户端来连接都可以连接上,查看进程管理器,发现存在两个服务器进程,这是为什么呢?明明做了进程互斥了,并且
RegisterClassObjects(CLSCTX_LOCAL_SERVER, //Registers the class factory in the Running Object Table.
   REGCLS_MULTIPLEUSE);

也使用了REGCLS_MULTIPLEUSE参数,为什么还是会出现这样的问题呢。网上到处翻帖子也没有结论,都说使用了REGCLS_MULTIPLEUSE就应该只初始化一个实例,但事实上确实存在着两个实例。后来仔细观察任务管理器发现,两个进程的用户名一个是当前用户的,一个是system的,于是就怀疑,是不是因为用户不同导致实例化了两个进程呢,尽管使用了REGCLS_MULTIPLEUSE参数,道微软的网站发现了一个帖子原文很长,附上一小段,大概的意思是,每个用户对于com的服务都有安全环境上下文,是否使用存在的进程,跟设备环境上下文关系很密切,
When a client requests a class object for a registered class, COM either returns an existing class object or launches a process that is registered as containing the requested class object. The process of obtaining a class object reference for a requesting client (whether or not that results in process creation or "launching") is called "activation."
Under certain conditions, COM may launch a new server process even when an existing class object is running and has been registered as multiple use. Moreover, when COM creates a new process that process may be launched in a new security environment known as a "window station" rather than sharing an existing window station such as the interactive window station. (For more information on window stations, search the Win32 SDK documentation for that phrase.)
Understanding COM's algorithms for creating new processes and window stations during an activation request is important for several reasons. First, COM may create more than one process instance of a multiple-use class object because of security issues. Second, "single-use" servers will always be launched in separate processes, but they may or may not be launched in separate window stations. This difference might manifest itself to application code in certain unusual cases, such as when two COM servers try to communicate via window messages or secure communication facilities such as COM or RPC. Third, since the number of window stations that can simultaneously be created in Windows NT is limited, it is important to know when your COM server gets a new window station.
This article examines different activation scenarios and explains when new processes and window stations are created.


其实解决问题的方法非常的简单,就是设置成交互式用户就可以了,这是做DCOM配置的时候毕设的一项,但是在配置的时候,没有去琢磨,为什么这样设置,原来是基于设备安全环境上下文相关,仔细阅读了微软的这篇文章,就明白了很多的东西,尤其原来在DCOM设置,网络OPC经常不通的原因也就很明了了
微软原文连接地址:http://support.microsoft.com/kb/169321/en-us

希望一点小经验,对大家理解COM和opc有所帮助                                                                                             
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表