找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3214|回復: 0
打印 上一主題 下一主題
收起左側

(原創(chuàng))關于opc開發(fā)中碰到的一個小問題到對COM的理解

[復制鏈接]
跳轉到指定樓層
樓主
ID:102668 發(fā)表于 2016-1-16 03:40 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
鄭重聲明:本帖是作者原創(chuàng),轉載請注明作者,讓俺也沽名釣譽一把,嘿嘿

前一段時間一直在做OPCAE的服務器端和客戶端的開發(fā),在開發(fā)的過程中碰到了一個問題。要求連接的是siemens sipass的opc AE,sipass做客戶端,我做服務器,發(fā)送報警信息。開發(fā)完了以后,先運行服務器程序,然后再用客戶端來連接,連接不上,很是奇怪,因為用別的客戶端來連接都可以連接上,查看進程管理器,發(fā)現存在兩個服務器進程,這是為什么呢?明明做了進程互斥了,并且
RegisterClassObjects(CLSCTX_LOCAL_SERVER, //Registers the class factory in the Running Object Table.
   REGCLS_MULTIPLEUSE);

也使用了REGCLS_MULTIPLEUSE參數,為什么還是會出現這樣的問題呢。網上到處翻帖子也沒有結論,都說使用了REGCLS_MULTIPLEUSE就應該只初始化一個實例,但事實上確實存在著兩個實例。后來仔細觀察任務管理器發(fā)現,兩個進程的用戶名一個是當前用戶的,一個是system的,于是就懷疑,是不是因為用戶不同導致實例化了兩個進程呢,盡管使用了REGCLS_MULTIPLEUSE參數,道微軟的網站發(fā)現了一個帖子原文很長,附上一小段,大概的意思是,每個用戶對于com的服務都有安全環(huán)境上下文,是否使用存在的進程,跟設備環(huán)境上下文關系很密切,
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配置的時候畢設的一項,但是在配置的時候,沒有去琢磨,為什么這樣設置,原來是基于設備安全環(huán)境上下文相關,仔細閱讀了微軟的這篇文章,就明白了很多的東西,尤其原來在DCOM設置,網絡OPC經常不通的原因也就很明了了
微軟原文連接地址:http://support.microsoft.com/kb/169321/en-us

希望一點小經驗,對大家理解COM和opc有所幫助                                                                                             
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表