Marshalling DSOP_INIT_INFO in .net 2.0
- From: "Christoffer" <christoffer@xxxxxxxxxx>
- Date: Wed, 8 Mar 2006 17:40:50 +0100
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
.
- Prev by Date: Can I overload
- Next by Date: Re: Can I overload
- Previous by thread: Can I overload
- Next by thread: marshalling pointers to abstract types
- Index(es):
Relevant Pages
|