I'll ask the obligatory "why can't you use the objects in the System.DirectoryServices namespace?" here. Now that we've gotten that out of the way...
Passing structures that contain pointers to structures or arrays of structures between managed and unmanaged code generally requires either a custom marshaler (easier on the person using the interop library, but the interop library is harder to write) or manual management of unmanaged memory by the person calling the code (easier for the person writing the interop library, but there WILL be memory management problems when it's used). -Andy Hopper ----- Original Message ----- From: "Simon Hewitt" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, October 23, 2002 5:25 AM Subject: [ADVANCED-DOTNET] Complex (for me anyway) Marshalling > I've been working on an LDAP library and I've managed to work out how to > read info from Active Directory. > I'm now trying to write information back (or delete) and I can't work out > the signatures/struct to use or whether I need to allocate unmanaged memory > and pass that instead. > > The LDAP API stuff and my managed definitions are:- > > WINLDAPAPI ULONG LDAPAPI ldap_modifyW( LDAP *ld, PWCHAR dn, LDAPModW *mods > [] ); > > [DllImport("wldap32.dll", CharSet=CharSet.Auto)] > public static extern int ldap_modify_s(HandleRef pLDAPSession, /* PCHAR */ > [In] string dn, /* LDAPMod* */ [In, Out] LDAP.LDAPMod[] mods); > > (I'm pretty sure that the first two parameters and the return value are > correct since I've used their values in other LDAP functions successfully) > > > and > > > typedef struct ldapmodW { > ULONG mod_op; > PWCHAR mod_type; > union { > PWCHAR *modv_strvals; > struct berval **modv_bvals; > } mod_vals; > } LDAPModW, *PLDAPModW; > > > [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] > public class LDAPMod { > public int ModOp; > [MarshalAs(UnmanagedType.LPStr)] > public string ModType; > public object[] Values; > > } > > (Values will be set to a String[] for the purposes of this test - I'll work > on the binary stuff later) > > > The code I am using to delete an existing attribute is:- > > LDAP.LDAPMod[] modifications = new LDAP.LDAPMod[modificationList.Count + 1]; > modificationList.CopyTo(modifications); > modifications[modificationList.Count] = null; > int result = LDAP.API.ldap_modify_s(_session._LDAPSession, DN, > modifications); > > modifications[0] is {0x02, "description", null} (0x02 is LDAP_MOD_REPLACE > and the null should delete all existing values) > modifications[1] is null (required to serve as the list terminator > > I get error 0x59 which is LDAP_PARAM_ERROR > > > I will be grateful for any help or pointers. > > Cheers > Simon > > You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.