基于COM开发的经验
来源:互联网 发布:皇室战争68淘宝 编辑:程序博客网 时间:2024/05/21 09:28
摘自:Eight Lessons from the COM School of Hard Knocks
http://msdn.microsoft.com/library/default.asp?url=/msdnmag/issues/1100/wicked/toc.asp
1.Always Call CoInitialize(Ex)
One of the fundamental rules of modern-day COM is that every thread that uses COM should first initialize COM by calling either CoInitialize or CoInitializeEx
2.Don't Pass Raw Interface Pointers Between Threads
In preparation for passing the interface pointer to thread B, thread A should marshal the interface pointer like this:
CoMarshalInterThreadInterfaceInStream (IID_IFoo, pFoo, &pStream);
Once CoMarshalInterThreadInterfaceInStream has returned, thread B can safely unmarshal the interface pointer:
IFoo* pFoo;
CoGetInterfaceAndReleaseStream (pStream, IID_IFoo, (void**) &pFoo);
you can also transfer interface pointers between threads by placing them in the Global Interface Table (GIT) and having other threads go there to retrieve them. Interface pointers retrieved from the GIT are automatically marshaled when they're retrieved
3.STA Threads Need Message Loops
(1).STA threads need message loops unless you're confident that they won't be hosting objects that are called from other threads.
MSG msg;
while (GetMessage (&msg, 0, 0, 0))
DispatchMessage (&msg);
(2).The alternative is to move COM threads to the MTA (or in Windows 2000, the neutral-threaded apartment, or NTA),
4.Apartment Model Objects Must Protect Shared Data
ThreadingModel=Apartment doesn't mean an object has to be completely thread-safe
Error:
static int nCallCount = 0;
nCallCount++;
Because all instances of this object will share one instance of nCallCount, the proper way to code these statements is as follows:
Right:
static int nCallCount = 0;
InterlockIncrement (&nCallCount);
To wit: use critical sections, interlocked functions, or whatever means you want, but don't forget to synchronize accesses to data shared by STA-based objects!
5.Beware of Launching User
6.DCOM is Firewall-unfriendly
7.Use Threads or Async Calls to Avoid Long DCOM Time-outs
8.Sharing Objects Isn't Easy
- 基于COM开发的经验
- 基于J2EE的开发的一些经验
- [转载]基于PDIUSBD12的USB通讯开发的一些经验
- 基于Torque Game Engine的游戏开发的一些经验
- 基于PDIUSBD12的USB通讯开发的一些经验
- 基于MFC的DLL开发的一些个人经验
- COM 经验的八个教训
- COM 经验的八个教训
- 基于COM组件的软件开发 技术方案一
- 基于RIA Flex Flash 平台开发的进销存企业信息管理系统开发经验
- 基于RIA Flex Flash 平台开发的进销存企业信息管理系统开发经验
- 基于.net的COM与COM+编程
- 基于.net的COM与COM+编程
- (转载)来自 COM 经验的八个教训
- 来自 COM 经验的八个教训
- 来自 COM 经验的八个教训
- 来自 COM 经验的八个教训
- 从escrow.com购买域名的经验
- VMware安装系统步骤
- InStr函数
- InStrRev函数
- 又到愚人节了
- 愚人节
- 基于COM开发的经验
- 位图
- 职场十大精辟语录
- Metasploit Framework使用图
- 让座
- 我不急躁4/1
- 一些变量在access和sql中操作的不同
- 使用EclipseME开发J2ME程序 (文章出处:豆豆技术网 )
- Frame Window Classes (Architecture) - MSDN6翻译交流