Click here to Skip to main content
15,891,184 members
Articles / Programming Languages / C#

Using the Windows 2000/XP Object Selection Dialog

Rate me:
Please Sign up or sign in to vote.
4.92/5 (29 votes)
21 Nov 2005CPOL14 min read 251.1K   4.5K   57  
This article describes how to use the "Select Users or Groups" system dialog.
#pragma once

#include "resource.h"       // main symbols
#include "ADObjectInfo.h"

[
	object,
	uuid("B7FA5AB6-104F-4B75-BDA2-AD53513FF760"),
	dual,	helpstring("IADObjectColl Interface"),
	pointer_default(unique)
]
__interface IADObjectColl : IDispatch
{
	[propget, id(1), helpstring("property Count")] HRESULT Count([out, retval] ULONG* pVal);
	[id(DISPID_VALUE), helpstring("method Item")] HRESULT Item([in] long index, [out, retval] IADObjectInfo** pVal);
	[propget, id(DISPID_NEWENUM), helpstring("property _NewEnum")] HRESULT _NewEnum([out, retval] LPUNKNOWN *pVal);
	[id(2), helpstring("method Add")] HRESULT Add([out,retval] IADObjectInfo** ppObjInfo);
	[id(3), helpstring("method RemoveAll")] HRESULT RemoveAll(void);
};

[
	coclass,
	threading("apartment"),
	vi_progid("ObjectPickerHelper.ADObjectColl"),
	progid("ObjectPickerHelper.ADObjectColl.1"),
	version(1.0),
	uuid("CFB801A3-660A-4B85-9FA5-DE0C0333C216"),
	helpstring("ADObjectColl Class"),
	default(IADObjectColl)
]
class ATL_NO_VTABLE CADObjectColl : 
	public IADObjectColl
{
public:
	CADObjectColl()
	{
	}

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
		Zap();
	}
	void Zap()
	{
		// cleanup of the dispatch pointers we are storing
		IADObjectInfo* p;

		std::vector<IADObjectInfo*>::iterator i;
		std::vector<IADObjectInfo*>::iterator begin = m_coll.begin();
		std::vector<IADObjectInfo*>::iterator end = m_coll.end();
		for (i = begin; i !=end; ++i)
		{
			p = *i;
			p->Release();
		}
		
		m_coll.resize(0);
	}

public:

	STDMETHOD(get_Count)(ULONG* pVal);
	STDMETHOD(get__NewEnum)(/*[out, retval]*/ LPUNKNOWN *pVal);
	STDMETHOD(Item)(/*[in]*/ long index, /*[out, retval]*/ IADObjectInfo**  pVal);
	STDMETHOD(Add)(IADObjectInfo** ppObjInfo);

protected:
	typedef std::vector<IADObjectInfo*> ADObjectInfoVector;
	ADObjectInfoVector	m_coll;

public:
	STDMETHOD(RemoveAll)(void);
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) AB SCIEX
Canada Canada
I was born and grew up in Northern Germany grew up in Quebec in a French Language environment. I finished High School in Fergus, Ontario. After a 4 year training as a Pipe Organ Builder in Germany, I returned to Canada to get a B.Sc. in Computer Science. I'm currently working for a company called AB SCIEX working on Mass Spectrometer Software, am married, and have three often wonderful children. What you believe in matters - I am a follower of Jesus Christ - we attend a German-Lutheran congregation in downtown Toronto.

Comments and Discussions