I have used the example from SDK for browsing Active Directory (can be found here) and in Vista the method DsBrowseForContainer throws AccessViolationException in .NET.
While testing, I have created a new MFC (C++) project and added a code for calling to DsBrowseForContainerW (similar to above). That worked perfectly, which means the problem is not in Vista, rather in .NET or marshalling in .NET. Checking the structure returned from the function call, I have found that previously NULL "pszRoot" member is now filled in! Means DsBrowseForContainerW has allocated a memory for it and passed back to me. Looks like marshaller has problem with this.
What I did in C# later, is changed "pszRoot" member to IntPtr (leaving it null) and used Marshal.PtrToStringAuto method to get its value afterwards. This works just fine on Vista, XP and 2003. Now have to figure out if I should free the returned string in pszRoot and how to do that (which method to use I mean)
Related MSDN forums link: AccessViolation error when use DsBrowseContainer in Vista
Update Oct. 6, 2008: I have posted code and example for this issue
here.
Technorati Tags:
.NET,
Vista