Stefan,
The marshaling layer doesn't really support structures that have
pointers in them well. You will want to define your structures like this:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct LDAPMod
{
public int mod_op;
public string mod_type;
public IntPtr mod_vals;
}
[StructLayout(LayoutKind.Sequential)]
public struct berval
{
public int bv_len;
IntPtr bv_val;
}
You need the CharSet set to Unicode on the first structure because
mod_type is defined as PWCHAR, which is a wide character. Also, if this
structure is being populated on return, you might have to change the
declaration to IntPtr, since you will be responsibile for freeing that
memory allocated (and the runtime does not know how to do it).
The mod_vals field you will have to marshal on your own. The mod_vals
field contains a pointer to an array of berval structures, all of which you
will have to marshal on your own (as well as marshal the data pointed to by
bv_val).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Stefan Buchman" <st************@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Hi,
I'm trying to use ldap_modify_s and it requires use of the LDAPMod
structure. Anyone have any idea how toadapt this for .NET. I keep
getting an error 53 (Unwilling to perform) when using the structure.
Here is what I have:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto )]
public struct LDAPMod
{
public int mod_op;
public string mod_type;
public struc_mod_vals[] mod_vals;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto )]
public struct struc_mod_vals
{
public string[] modv_strvals;
public object modv_bvals;
}
Thanks!