Hi all
I have an Unhanled Exception when using ldap_search_s :
1. I used VC++ 2008 , winldap.h , Wldap32.lib
2. My code :
PCHAR hostName = Settings::LdapHost;
LDAP* pLdapConnection = NULL;
ULONG version = LDAP_VERSION3;
ULONG numReturns = 10;
ULONG lRtn = 0;
pLdapConnection = ldap_init (hostName, Settings::LdapPort);
if (pLdapConnection == NULL)
{
ldap_unbind(pLdapConnection);
return -1;
}
lRtn = ldap_set_option (
pLdapConnection, // Session handle
LDAP_OPT_PROTOCOL_VERSION, // Option
(void*) &version); // Option value
if(lRtn != LDAP_SUCCESS)
{
ldap_unbind(pLdapConnection);
return -1;
}
lRtn = ldap_connect (pLdapConnection, NULL);
if(lRtn != LDAP_SUCCESS)
{
ldap_unbind(pLdapConnection);
return -1;
}
lRtn = ldap_simple_bind_s (pLdapConnection, pUserName, pPassword);
if(lRtn != LDAP_SUCCESS)
{
printf("ldap_bind_s failed with 0x%lx.\n",lRtn);
ldap_unbind(pLdapConnection);
return -1;
}
ULONG errorCode = LDAP_SUCCESS;
LDAPMessage* pSearchResult = 0;
PCHAR pMyFilter = "(&(objectClass=*))";
PCHAR pMyAttributes[2];
pMyAttributes[0] = "cn";
pMyAttributes[1] = "uid";
errorCode = ldap_search_s (
pLdapConnection, // Session handle
"ou=manager,dc=com,dc=vn", // DN to start search pMyDN
LDAP_SCOPE_SUBTREE, // Scope
pMyFilter, // Filter
pMyAttributes, // Retrieve list of attributes
0, // Get both attributes and values
&pSearchResult); // [out] Search results
I got the Exception "Unhandled exception at 0x77148705 in LdapTest.exe: 0xC0000005: Access violation reading location 0xcccccccc " at line errorCode = ldap_search_s . Even I passed correct userName & Password, and I ran this test succesfully in C# with DirectoryEntry & DirectorySearcher
Anyone who have experience, please help me. Many thanks!