2016-09-01 14 views
0

私はこの例をマイクロソフトによって文書化しましたが、コンソールプロジェクトの下でVisual Studio 2012で動作させることはできません。 https://msdn.microsoft.com/en-us/library/ms676877(v=vs.85).aspxActive Directory通知

私には欠けているものがありますか?正しいコンソールアプリケーションです。私が手

エラーは以下のとおりです。

Error 1 error LNK2019: unresolved external symbol __imp__ldap_openW referenced in function "int __cdecl GetChangeNotifications(wchar_t *)" ([email protected]@[email protected]) C:\projects\AD_Notifications\AD_Change_Notifications\AD_Change_Notifications\AD_Change_Notifications.obj AD_Change_Notifications 

私はちょっと明らかであるそのリンカエラーを、読んでてきたが、それはすべて1つのファイルであるので、私は私が何を理解していないものからリンクしているとしますか?

答えて

0

私はJavaで発見された最良の答えはhttps://community.oracle.com/thread/1158217

/** 
* ldapnotify.java 
* December 2004 
* Sample JNDI application that uses AD LDAP Notification Control. 
* 
**/ 

import java.util.Hashtable; 
import java.util.Enumeration; 
import javax.naming.*; 
import javax.naming.ldap.*; 
import com.sun.jndi.ldap.ctl.*; 
import javax.naming.directory.*; 

class NotifyControl implements Control { 
    public byte[] getEncodedValue() { 
      return new byte[] {}; 
    } 
     public String getID() { 
      return "1.2.840.113556.1.4.528"; 
    } 
     public boolean isCritical() { 
      return true; 
    } 
} 

class ldapnotify { 

    public static void main(String[] args) { 

      Hashtable env = new Hashtable(); 
      String adminName = "CN=Administrator,CN=Users,DC=antipodes,DC=com"; 
      String adminPassword = "XXXXXXXX"; 
      String ldapURL = "ldap://mydc.antipodes.com:389"; 
      String searchBase = "DC=antipodes,DC=com"; 

      //For persistent search can only use objectClass=* 
      String searchFilter = "(objectClass=*)"; 

       env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); 

      //set security credentials, note using simple cleartext authentication 
      env.put(Context.SECURITY_AUTHENTICATION,"simple"); 
      env.put(Context.SECURITY_PRINCIPAL,adminName); 
      env.put(Context.SECURITY_CREDENTIALS,adminPassword); 

      //connect to my domain controller 
      env.put(Context.PROVIDER_URL,ldapURL); 

      try { 
       //bind to the domain controller 
        LdapContext ctx = new InitialLdapContext(env,null); 

       // Create the search controls   
       SearchControls searchCtls = new SearchControls(); 

       //Specify the attributes to return 
       String returnedAtts[] = null; 
       searchCtls.setReturningAttributes(returnedAtts); 

       //Specify the search scope 
       searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); 

        //Specifiy the search time limit, in this case unlimited 
       searchCtls.setTimeLimit(0); 

       //Request the LDAP Persistent Search control 
        Control[] rqstCtls = new Control[]{new NotifyControl()}; 
        ctx.setRequestControls(rqstCtls); 

       //Now perform the search 
       NamingEnumeration answer = ctx.search(searchBase,searchFilter,searchCtls); 
       SearchResult sr; 
        Attributes attrs; 

       //Continue waiting for changes....forever 
       while(true) { 
        System.out.println("Waiting for changes..., press Ctrl C to exit"); 

        sr = (SearchResult)answer.next(); 
          System.out.println(">>>" + sr.getName()); 

        //Print out the modified attributes 
        //instanceType and objectGUID are always returned 
        attrs = sr.getAttributes(); 
        if (attrs != null) { 
         try { 

           for (NamingEnumeration ae = attrs.getAll();ae.hasMore();) { 
            Attribute attr = (Attribute)ae.next(); 
            System.out.println("Attribute: " + attr.getID()); 
            for (NamingEnumeration e = attr.getAll();e.hasMore();System.out.println(" " + e.next().toString())); 
           } 
         } 
         catch (NullPointerException e)  { 
           System.err.println("Problem listing attributes: " + e); 
         } 
        } 
       } 
       } 

      catch (NamingException e) { 
         System.err.println("LDAP Notifications failure. " + e); 
       } 
     } 
} 
から以下に引用されています