Click here to Skip to main content
15,892,298 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.3K   4.5K   57  
This article describes how to use the "Select Users or Groups" system dialog.
#pragma once
#include "resource.h"       // main symbols
#include "ADObjectColl.h"
#include "ShowActiveDirUsers.h"
#include "_ObjectPickerHelper_i.c"





// IADObjectPicker
[
	object,
	uuid("D50186DE-C1E8-46FB-A8FD-5D2DBA64605B"),
	dual,	helpstring("IADObjectPicker Interface"),
	pointer_default(unique)
]
__interface IADObjectPicker : IDispatch
{
	[propget, id(1), helpstring("property ScopeTypeFlags")] HRESULT ScopeTypeFlags([out, retval] ULONG* pVal);
	[propput, id(1), helpstring("property ScopeTypeFlags")] HRESULT ScopeTypeFlags([in] ULONG newVal);
	[propget, id(2), helpstring("property ScopeFlags")] HRESULT ScopeFlags([out, retval] ULONG* pVal);
	[propput, id(2), helpstring("property ScopeFlags")] HRESULT ScopeFlags([in] ULONG newVal);
	[propget, id(3), helpstring("property UplevelFilterFlags_Both")] HRESULT UplevelFilterFlags_Both([out, retval] ULONG* pVal);
	[propput, id(3), helpstring("property UplevelFilterFlags_Both")] HRESULT UplevelFilterFlags_Both([in] ULONG newVal);
	[propget, id(4), helpstring("property UplevelFilterFlags_Mixed")] HRESULT UplevelFilterFlags_Mixed([out, retval] ULONG* pVal);
	[propput, id(4), helpstring("property UplevelFilterFlags_Mixed")] HRESULT UplevelFilterFlags_Mixed([in] ULONG newVal);
	[propget, id(5), helpstring("property UplevelFilterFlags_Native")] HRESULT UplevelFilterFlags_Native([out, retval] ULONG* pVal);
	[propput, id(5), helpstring("property UplevelFilterFlags_Native")] HRESULT UplevelFilterFlags_Native([in] ULONG newVal);
	[propget, id(6), helpstring("property DownLevelFilterFlags")] HRESULT DownLevelFilterFlags([out, retval] ULONG* pVal);
	[propput, id(6), helpstring("property DownLevelFilterFlags")] HRESULT DownLevelFilterFlags([in] ULONG newVal);
	[propget, id(7), helpstring("property ComputerName")] HRESULT ComputerName([out, retval] BSTR* pVal);
	[propput, id(7), helpstring("property ComputerName")] HRESULT ComputerName([in] BSTR newVal);
	[propget, id(8), helpstring("property InitInfo_OptionFlags")] HRESULT InitInfo_OptionFlags([out, retval] ULONG* pVal);
	[propput, id(8), helpstring("property InitInfo_OptionFlags")] HRESULT InitInfo_OptionFlags([in] ULONG newVal);
	[id(9), helpstring("method InvokeDialog")] HRESULT InvokeDialog([in] LONG hWnd);
	[propget, id(10), helpstring("property ADObjects")] HRESULT ADObjectsColl([out, retval] IDispatch** pVal);
};



// CADObjectPicker

[
	coclass,
	threading("apartment"),
	aggregatable("never"),
	vi_progid("ObjectPickerHelper.ADObjectPicker"),
	progid("ObjectPickerHelper.ADObjectPicker.1"),
	version(1.0),
	uuid("0A386264-8872-483F-85B8-84F83F30AB49"),
	helpstring("ADObjectPicker Class"),
	default(IADObjectPicker)
]
class ATL_NO_VTABLE CADObjectPicker : 
	public IADObjectPicker
{
public:
	CADObjectPicker()
	{
	}

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		HRESULT hr;
		hr = m_ADObjectColl.CoCreateInstance(CLSID_CADObjectColl);
		// provide reasonable defaults USERS, GROUPS
		m_ScopeTypeFlags = 0x37f;
		m_ScopeFlags = 0xc3;
		m_UplevelFilterFlags_Both = 0x42;
		m_UplevelFilterFlags_Mixed = 0;
		m_UplevelFilterFlags_Native = 0;
		m_DownlevelFilterFlags = 0x800000005;
		m_InitInfoFlags = 0x3;
		return hr;
	}
	
	void FinalRelease() 
	{
	}

public:
	STDMETHOD(get_ScopeTypeFlags)(ULONG* pVal);
	STDMETHOD(put_ScopeTypeFlags)(ULONG newVal);
	STDMETHOD(get_ScopeFlags)(ULONG* pVal);
	STDMETHOD(put_ScopeFlags)(ULONG newVal);
	STDMETHOD(get_UplevelFilterFlags_Both)(ULONG* pVal);
	STDMETHOD(put_UplevelFilterFlags_Both)(ULONG newVal);
	STDMETHOD(get_UplevelFilterFlags_Mixed)(ULONG* pVal);
	STDMETHOD(put_UplevelFilterFlags_Mixed)(ULONG newVal);
	STDMETHOD(get_UplevelFilterFlags_Native)(ULONG* pVal);
	STDMETHOD(put_UplevelFilterFlags_Native)(ULONG newVal);
	STDMETHOD(get_DownLevelFilterFlags)(ULONG* pVal);
	STDMETHOD(put_DownLevelFilterFlags)(ULONG newVal);
	STDMETHOD(get_ComputerName)(BSTR* pVal);
	STDMETHOD(put_ComputerName)(BSTR newVal);
	STDMETHOD(get_InitInfo_OptionFlags)(ULONG* pVal);
	STDMETHOD(put_InitInfo_OptionFlags)(ULONG newVal);
	STDMETHOD(InvokeDialog)(LONG hWnd);
	STDMETHOD(get_ADObjectsColl)(IDispatch** pVal);

protected:
	friend class CShowActiveDirUsers;
	ULONG					m_ScopeTypeFlags;
	ULONG					m_ScopeFlags;
	ULONG					m_UplevelFilterFlags_Both;
	ULONG					m_UplevelFilterFlags_Mixed;
	ULONG					m_UplevelFilterFlags_Native;
	ULONG					m_DownlevelFilterFlags;
	CComBSTR				m_bstrComputerName;
	ULONG					m_InitInfoFlags;
	CComPtr<IADObjectColl>	m_ADObjectColl;
	CShowActiveDirUsers		m_adUsers;

};

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