On Nov 30, 12:24 pm, "dan artuso" <dart...@NOSPAMpagepearls.com>
wrote:
> Well, it seems COM was the problem.
>
> At least it started working okay when I got rid of this code in one of our
> classes:
>
> Private Function AccountType(ByVal strSid As String) As String 'As
> SID_NAME_USE
>
> 'this function returns the type of account:
>
> 'Computer, User, Group, Domain, Alias, well known
>
> Dim ret As Boolean
>
> Dim ptrSid As IntPtr
>
> Dim cbSid As Integer
>
> Dim refDomainName As New System.Text.StringBuilder
>
> Dim rDomainName As String
>
> Dim cbRefDomainName As Integer
>
> Dim peUse As SID_NAME_USE
>
> 'First get the buffer sizes
>
> ret = Win32.LookupAccountName(Nothing, strSid, Nothing, cbSid,
> Nothing, cbRefDomainName, peUse)
>
> 'Adjust the buffers to the needed size
>
> ptrSid = Marshal.AllocHGlobal(cbSid)
>
> rDomainName = refDomainName.EnsureCapacity(cbRefDomainName)
>
> 'Get the data again, now with the changed buffers
>
> ret = Win32.LookupAccountName(Nothing, strSid, ptrSid, cbSid,
> rDomainName, cbRefDomainName, peUse)
>
> If ret Then
>
> 'If return doesn't fail return the type)
>
> Return peUse
>
> End If
>
> Marshal.FreeHGlobal(ptrSid)
>
> End Function
>
> Dan
>
I see the LookupAccountName Win32 API, but I'm not seeing any COM
objects.
You shouldn't need to allocate memory from the unmanaged heap to use
that API. Let the interop marshaller do it for you. Check out
http://www.pinvoke.net for an alternate method of declaring and using
LookupAccountName.
Also, you have a *major* memory leak here. It looks like FreeHGlobal
is only called when the function fails. You should use a Try-Finally
block to work around that issue. I'm wondering if this is part of
your problem.