本文整理汇总了C#中UnsafeNativeMethods.SetSearchPreference方法的典型用法代码示例。如果您正苦于以下问题:C# UnsafeNativeMethods.SetSearchPreference方法的具体用法?C# UnsafeNativeMethods.SetSearchPreference怎么用?C# UnsafeNativeMethods.SetSearchPreference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnsafeNativeMethods
的用法示例。
在下文中一共展示了UnsafeNativeMethods.SetSearchPreference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoSetSearchPrefs
private static void DoSetSearchPrefs(UnsafeNativeMethods.IDirectorySearch adsSearch, AdsSearchPreferenceInfo[] prefs)
{
int structSize = Marshal.SizeOf(typeof(AdsSearchPreferenceInfo));
IntPtr ptr = Marshal.AllocHGlobal((IntPtr)(structSize * prefs.Length));
try
{
IntPtr tempPtr = ptr;
for (int i = 0; i < prefs.Length; i++)
{
Marshal.StructureToPtr(prefs[i], tempPtr, false);
tempPtr = IntPtr.Add(tempPtr, structSize);
}
adsSearch.SetSearchPreference(ptr, prefs.Length);
// Check for the result status for all preferences
tempPtr = ptr;
for (int i = 0; i < prefs.Length; i++)
{
int status = Marshal.ReadInt32(tempPtr, 32);
if (status != 0)
{
int prefIndex = prefs[i].dwSearchPref;
string property = "";
switch (prefIndex)
{
case (int)AdsSearchPreferences.SEARCH_SCOPE:
property = "SearchScope";
break;
case (int)AdsSearchPreferences.SIZE_LIMIT:
property = "SizeLimit";
break;
case (int)AdsSearchPreferences.TIME_LIMIT:
property = "ServerTimeLimit";
break;
case (int)AdsSearchPreferences.ATTRIBTYPES_ONLY:
property = "PropertyNamesOnly";
break;
case (int)AdsSearchPreferences.TIMEOUT:
property = "ClientTimeout";
break;
case (int)AdsSearchPreferences.PAGESIZE:
property = "PageSize";
break;
case (int)AdsSearchPreferences.PAGED_TIME_LIMIT:
property = "ServerPageTimeLimit";
break;
case (int)AdsSearchPreferences.CHASE_REFERRALS:
property = "ReferralChasing";
break;
case (int)AdsSearchPreferences.SORT_ON:
property = "Sort";
break;
case (int)AdsSearchPreferences.CACHE_RESULTS:
property = "CacheResults";
break;
case (int)AdsSearchPreferences.ASYNCHRONOUS:
property = "Asynchronous";
break;
case (int)AdsSearchPreferences.TOMBSTONE:
property = "Tombstone";
break;
case (int)AdsSearchPreferences.ATTRIBUTE_QUERY:
property = "AttributeScopeQuery";
break;
case (int)AdsSearchPreferences.DEREF_ALIASES:
property = "DerefAlias";
break;
case (int)AdsSearchPreferences.SECURITY_MASK:
property = "SecurityMasks";
break;
case (int)AdsSearchPreferences.EXTENDED_DN:
property = "ExtendedDn";
break;
case (int)AdsSearchPreferences.DIRSYNC:
property = "DirectorySynchronization";
break;
case (int)AdsSearchPreferences.DIRSYNC_FLAG:
property = "DirectorySynchronizationFlag";
break;
case (int)AdsSearchPreferences.VLV:
property = "VirtualListView";
break;
}
throw new InvalidOperationException(Res.GetString(Res.DSSearchPreferencesNotAccepted, property));
}
tempPtr = IntPtr.Add(tempPtr, structSize);
}
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}