ObjectPicker Wrapper and Marshaling

  • Thread starter Thread starter Rodger Brennan
  • Start date Start date
R

Rodger Brennan

I'm tring to implement the ObjectPicker for a project I'm working on. I'm
using the DSObjectPickerWrapper found at
http://dotnet.org.za/armand/articles/2453.aspx

This works fine as is, but I need to get additional Attributes back from the
Picker specifically "objectSid" Unfortunately, I can figure out how to
marshal the initInfo.apwzAttributeNames Property. In the API documention
for the ObjectPicker, it is defined as a PCWSTR data type "Pointer to an
array of null-terminated Unicode strings that contain the names of the
attributes to retrieve for each selected object."

I've tried this several ways, but I can't figure out how to properly marshal
this datatype. Here is the code for the Initialize Method

private IDsObjectPicker Initialize()
{

DSObjectPicker picker = new DSObjectPicker();

IDsObjectPicker ipicker = (IDsObjectPicker)picker;



DSOP_SCOPE_INIT_INFO[] scopeInitInfo = new
DSOP_SCOPE_INIT_INFO[2];



// Initialize 1st search scope

scopeInitInfo[0].cbSize =
(uint)Marshal.SizeOf(typeof(DSOP_SCOPE_INIT_INFO));

scopeInitInfo[0].flType =
DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_GLOBAL_CATALOG;
//Convert.ToUInt32("3FE",16);

scopeInitInfo[0].flScope =
DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_DEFAULT_FILTER_COMPUTERS + 1; //
Starting !?

scopeInitInfo[0].FilterFlags.Uplevel.flBothModes =
DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_COMPUTERS + 1; // +1 = advanced view,
Check MSDN for the available options

scopeInitInfo[0].FilterFlags.flDownlevel =
DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_COMPUTERS;

scopeInitInfo[0].pwzADsPath = null;

scopeInitInfo[0].pwzDcName = null;

scopeInitInfo[0].hr = 0;



// Initialize 2nd search scope

scopeInitInfo[1].cbSize =
(uint)Marshal.SizeOf(typeof(DSOP_SCOPE_INIT_INFO));

scopeInitInfo[1].flType = Convert.ToUInt32("37F",16);

scopeInitInfo[1].flScope =
DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS |

DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS;

scopeInitInfo[1].FilterFlags.Uplevel.flBothModes =
Convert.ToUInt32("3FF",16);

scopeInitInfo[1].FilterFlags.flDownlevel =
DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS + 7;

scopeInitInfo[1].pwzADsPath = null;

scopeInitInfo[1].pwzDcName = null;

scopeInitInfo[1].hr = 0;





// Allocate memory from the unmananged mem of the
process, this should be freed later!??

IntPtr refScopeInitInfo = Marshal.AllocHGlobal

(Marshal.SizeOf (typeof (DSOP_SCOPE_INIT_INFO)) *
2);



// Marshal structs to pointers

Marshal.StructureToPtr (scopeInitInfo[0],

refScopeInitInfo,true);



Marshal.StructureToPtr (scopeInitInfo[1],

(IntPtr) ((int) refScopeInitInfo + Marshal.SizeOf

(typeof (DSOP_SCOPE_INIT_INFO))),true);





// Initialize structure with data to initialize an
object picker dialog box.

DSOP_INIT_INFO initInfo = new DSOP_INIT_INFO ();

initInfo.cbSize = (uint) Marshal.SizeOf (initInfo);

initInfo.pwzTargetComputer = null; // local computer

initInfo.cDsScopeInfos = 2;

initInfo.aDsScopeInfos = refScopeInitInfo;

// Flags that determine the object picker options.
Allow user to select

// multiple objects and specify that this is not a
domain controller

initInfo.flOptions =
DSOP_INIT_INFO_FLAGS.DSOP_FLAG_MULTISELECT |
DSOP_INIT_INFO_FLAGS.DSOP_FLAG_SKIP_TARGET_COMPUTER_DC_CHECK;



// We're not retrieving any additional attributes

initInfo.cAttributesToFetch = 0;

initInfo.apwzAttributeNames = IntPtr.Zero;



// Initialize the Object Picker Dialog Box with our
options

ipicker.Initialize (ref initInfo);



return ipicker;

}



Thanks in Advance for any assistance.



Rodger
 
Back
Top