开发者

GetInterfaceFromGlobal() call fails with an out-of-process COM server in Visual Studio 2010

开发者 https://www.devze.com 2023-01-25 06:57 出处:网络
I have an Out-of-process COM server executable which was developed using Visual Studio 6.0 and it has been working fine for the past 10 years. Now I converted this project to Visual Studio 2010 and en

I have an Out-of-process COM server executable which was developed using Visual Studio 6.0 and it has been working fine for the past 10 years. Now I converted this project to Visual Studio 2010 and encountered a problem with GetInterfaceFromGlobal().

I'm using the GIT to hold IDispatch pointers to each of my COM clients so I can send them events from the Out-of-Process COM server. After debugging, the reason I found out is that the no. of connections returned by m_vec.Getsize() is coming as 4 instead of 1. Even if I add only one client, the value is coming as 4. I checked ATLCOM.h and in that file _DEFAULT_VECTORLENGTH is changed from 1 to 4 in the recent versions.

#ifndef _DEFAULT_VECTORLENGTH
#define _DEFAULT_VECTORLENGTH 4
#endif

Any advice o开发者_StackOverflow中文版n how I can override this value? Shall I simply redefine this to 1 in my code? Would this have any side effects? or am I missing anything?

Thanks in advance Harish


Don't touch that constant - just ignore the change. _DEFAULT_VECTORLENGTH controls how CComDynamicUnkArray::Add() works and your code that traverses the CComDynamicUnkArray object should just skip the null pointers stored inside.

Something like this:

for( int i = 0; i < array.GetSize(); i++ ) {
  IUnknown* pointer = array.GetAt( i );
  if( pointer == 0 ) {
      continue;
  }
  //proceed with the pointer
}

If you decide to change that constant make sure you statically link to ATL and make sure you change that constant in ATL as well and rebuild ATL. Otherwise you risk running into undefined behavior for reasons described here

0

精彩评论

暂无评论...
验证码 换一张
取 消