Skip to content

Instantly share code, notes, and snippets.

@Javran
Created December 3, 2012 15:13
Show Gist options
  • Save Javran/4195626 to your computer and use it in GitHub Desktop.
Save Javran/4195626 to your computer and use it in GitHub Desktop.
COM mgmt test
#include <stack>
#include <cstdio>
class Dummy
{
public:
void Release()
{
printf("remove: %p\n", this);
}
};
class COMHolder
{
public:
std::stack<Dummy *> comStk;
COMHolder() {}
void hold(Dummy *c)
{
printf("create: %p\n", c);
comStk.push( c );
}
virtual ~COMHolder()
{
for ( ;!comStk.empty(); comStk.pop())
{
Dummy *d = comStk.top();
if (d)
{
d->Release();
#ifndef COM
delete d;
#endif
}
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
COMHolder h;
h.hold(new Dummy());
h.hold(new Dummy());
h.hold(new Dummy());
h.hold(new Dummy());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment