Marshalling DSOP_INIT_INFO in .net 2.0

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello, I'm using .Net 2.0 and I'm trying to use the IDSObjectPicker to show
the Active Directory picker. I'm not sure I'm marshalling the DSOP_INIT_INFO
struct correctly. I get this error (which pretty much could mean anything):
The parameter is incorrect. (Exception from HRESULT: 0x80070057
(E_INVALIDARG))

This is the code:

DSOP_SCOPE_INIT_INFO[] scopes = new DSOP_SCOPE_INIT_INFO[1];

DSOP_SCOPE_INIT_INFO scope = new DSOP_SCOPE_INIT_INFO();

scope.cbSize = (uint)Marshal.SizeOf(typeof(DSOP_SCOPE_INIT_INFO));

scope.flType = (uint)DsopScopeInfoTypes.DSOP_SCOPE_TYPE_TARGET_COMPUTER;

scope.flScope =
(uint)DsopScopeInfoScopes.DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP;

scope.FilterFlags.flDownlevel =
(uint)(DsopFilter.DSOP_DOWNLEVEL_FILTER_USERS |
DsopFilter.DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS);

scope.FilterFlags.Uplevel.flBothModes =
(uint)DsopUplevelFilter.DSOP_FILTER_USERS;

scope.FilterFlags.Uplevel.flMixedModeOnly = 0;

scope.FilterFlags.Uplevel.flNativeModeOnly = 0;

scope.pwzADsPath = null;

scope.pwzDcName = null;

scope.hr = 0;

scopes[0] = scope;

// DSOP_INIT_INFO

DSOP_INIT_INFO initInfo = new DSOP_INIT_INFO();

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

initInfo.pwzTargetComputer = _targetComputer;

initInfo.flOptions = _options;

initInfo.cAttributesToFetch = 0;

initInfo.apwzAttributeNames = IntPtr.Zero;

initInfo.cDsScopeInfos = (uint)scopes.Length;

initInfo.aDsScopeInfos = scopes;

Type objectPickerType =
Type.GetTypeFromCLSID(NativeMethods.CLSID_DsObjectPicker, true);

object pickerObj = Activator.CreateInstance(objectPickerType);

_picker = (IDSObjectPicker)pickerObj;

And the declaration of the structs:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

internal struct DSOP_INIT_INFO

{



public uint cbSize;

[MarshalAs(UnmanagedType.LPWStr)]

public string pwzTargetComputer;

public uint cDsScopeInfos;

public DSOP_SCOPE_INIT_INFO[] aDsScopeInfos;

public uint flOptions;

public uint cAttributesToFetch;

public IntPtr apwzAttributeNames;

}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto), Serializable]

internal struct DSOP_SCOPE_INIT_INFO

{



public uint cbSize;

public uint flType;

public uint flScope;

[MarshalAs(UnmanagedType.Struct)]

public DSOP_FILTER_FLAGS FilterFlags;

[MarshalAs(UnmanagedType.LPWStr)]

public string pwzDcName;

[MarshalAs(UnmanagedType.LPWStr)]

public string pwzADsPath;

public uint hr;

}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

internal struct DSOP_UPLEVEL_FILTER_FLAGS

{

public uint flBothModes;

public uint flMixedModeOnly;

public uint flNativeModeOnly;

}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

internal struct DSOP_FILTER_FLAGS

{

public DSOP_UPLEVEL_FILTER_FLAGS Uplevel;

public uint flDownlevel;

}



Could anyone give me a hint?

Cheers,
Chris


.



Relevant Pages

  • Re: Process List
    ... always returns 556 for the size of my struct. ... //Indicates that the snapshot handle is to be inheritable. ... public uint cntUsage; ... public uint th32ProcessID; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Process List
    ... If you pass a struct, which is a value type, you must add the ... "ref" decoration to the parameter to tell it to pass it by ref. ... snapshot using Process32First and Process32Next. ... public uint cntUsage; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: marshaling more complex structures
    ... You need to just pass the entire struct as a 40-byte array, ... public uint spectrumNumber; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: FTP FtpFindFile
    ... Also as a struct you should be passing the find data by reference e.g. ... public uint fileAttributes; ... public FILETIME lastAccessTime; ...
    (microsoft.public.dotnet.framework.compactframework)
  • RE: Anyone have a good example on using P/Invoke SendInput ?
    ... I found a sample online which works for Keyboard inputs. ... INPUT struct to SendInput. ... internal struct KEYBOARDINPUT ... public uint flags; ...
    (microsoft.public.dotnet.languages.csharp)