Mega Code Archive

 
Categories / C# by API / System Runtime Interopservices
 

Marshal StringToCoTaskMemAnsi

using System; using System.Runtime.InteropServices; using LDAP32; unsafe class MainClass {   private static uint LDAP_PORT = 389;   [STAThread]   static void Main(string[] args)   {     LDAP32.LDAP* pLdap = null;     sbyte* pServer = (sbyte*)Marshal.StringToCoTaskMemAnsi("dsaddom.nttest.microsoft.com");     sbyte* pName = (sbyte*)Marshal.StringToCoTaskMemAnsi("CN=Greg MacBeth,CN=Users,DC=dsaddom,DC=nttest,DC=MICROSOFT,DC=COM");     sbyte* pPassword = (sbyte*)Marshal.StringToCoTaskMemAnsi("gregmcb");     uint Result = 0;         pLdap = Wldap32.ldap_init(pServer, LDAP_PORT);     if(pLdap != null)     {       Result = Wldap32.ldap_simple_bind_s(pLdap, pName, pPassword);     }     Wldap32.ldap_unbind(pLdap);   } }