private static void GetLibraryHandle() { // first get AD handle string systemPath = Environment.SystemDirectory; IntPtr tempHandle = UnsafeNativeMethods.LoadLibrary(systemPath + "\\ntdsapi.dll"); if (tempHandle == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } else { ADHandle = new LoadLibrarySafeHandle(tempHandle); } // not get the ADAM handle // got to the windows\adam directory DirectoryInfo windowsDirectory = Directory.GetParent(systemPath); tempHandle = UnsafeNativeMethods.LoadLibrary(windowsDirectory.FullName + "\\ADAM\\ntdsapi.dll"); if (tempHandle == (IntPtr)0) { ADAMHandle = ADHandle; } else { ADAMHandle = new LoadLibrarySafeHandle(tempHandle); } }
private static void GetLibraryHandle() { string systemDirectory = Environment.SystemDirectory; IntPtr intPtr = UnsafeNativeMethods.LoadLibrary(string.Concat(systemDirectory, "\\ntdsapi.dll")); if (intPtr != (IntPtr)0) { DirectoryContext.ADHandle = new LoadLibrarySafeHandle(intPtr); DirectoryInfo parent = Directory.GetParent(systemDirectory); intPtr = UnsafeNativeMethods.LoadLibrary(string.Concat(parent.FullName, "\\ADAM\\ntdsapi.dll")); if (intPtr != (IntPtr)0) { DirectoryContext.ADAMHandle = new LoadLibrarySafeHandle(intPtr); return; } else { DirectoryContext.ADAMHandle = DirectoryContext.ADHandle; return; } } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } }