Access Violation in DsBrowseForContainer on Windows Vista

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: ,

posted @ Wednesday, September 05, 2007 1:03 PM

Print

Comments on this entry:

# re: Access Violation in DsBrowseForContainer on Windows Vista

Left by JOse at 10/3/2008 3:04 AM
Gravatar
do you have the C# code that makes the function works in vista?

it would be nice if you can post it on your blog :)

thanks .. Jose.

# re: Access Violation in DsBrowseForContainer on Windows Vista

Left by Philip Patrick at 11/5/2008 2:24 PM
Gravatar
Yep. Posted it some time ago, after your request. It is available here:
http://blog.stpworks.com/archive/2008/10/06/access-violation-in-dsbrowseforcontainer-on-windows-vista.-part-2.aspx

# re: Access Violation in DsBrowseForContainer on Windows Vista

Left by helen at 1/26/2010 1:53 PM
Gravatar
thanks

Your comment:



 (will not be displayed)


 
 
 
Please add 4 and 6 and type the answer here:
 

Live Comment Preview: