Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CCW count when creating managed object from native code

3 views
Skip to first unread message

a

unread,
Jun 17, 2011, 4:43:40 AM6/17/11
to
I've been trying to understand CCW management and have made a simple
win32 console app which creates (via CoCreateInstance) a simple
managed object:

IClass1.cs
=======

using System.Runtime.InteropServices;

namespace ClassLibrary1
{
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IClass1
{
void Hello();
}
}

Class1.cs
=======

using System;
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Class1 : IClass1
{
public void Hello()
{
Console.WriteLine();
}
}
}

main.cpp
=======

#include <windows.h>
#import "../ClassLibrary1/bin/Debug/ClassLibrary1.tlb"

int main()
{
HRESULT hr = E_FAIL;
hr = ::CoInitialize(0);
ClassLibrary1::IClass1Ptr p;
p.CreateInstance(_uuidof(ClassLibrary1::Class1));
p->Hello();

ClassLibrary1::IClass1Ptr p2;
p2.CreateInstance(_uuidof(ClassLibrary1::Class1));
p2->Hello();

return 0;
}


I use process explorer (http://technet.microsoft.com/en-us/
sysinternals/bb896653) to check the CCW count. After my 'p' instance
has been created the CCW count is 2. Why? I would have expected 1...
After my p2 instance has been created the CCW count is 3. Sensible
--- it's gone up by one. It looks like there is some kind of first
time CLR start up effect; i.e. on the first creation of a managed
object you get some extra CCW.

Anybody know what's really going on here?

Thanks
Simon

0 new messages