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