【发布时间】:2011-07-29 12:48:09
【问题描述】:
我正在编写一个名为 ADAuthenticate 的 DLL 函数,它将根据 Active Directory 对用户进行身份验证,并检查用户的某个属性(如果他/她存在)。如果管理员正在验证,我不想让函数进行 ldap 搜索,所以我在下面有以下 if 语句:
if (_tcsicmp(username, TEXT("administrator")) != 0 && _tcscmp(attrs[0], TEXT("")) != 0)
{
// Search for specific attributes
ldap_response = ldap_search_s(ldap, domain, LDAP_SCOPE_SUBTREE, search, attrs, 0, &ldap_msg);
if (ldap_response != LDAP_SUCCESS)
MessageBox(h_wnd, ldap_err2string(ldap_response), TEXT("ERROR - ldap_search_s"), MB_OK);
else if ((new_ldap_msg = ldap_first_entry(ldap, ldap_msg)) != NULL)
{
do
{
// Append a pipe character if more than one attribute is requested
if (count > 0)
_tcscpy(ret_val, TEXT("|"));
_tcscpy(ret_val, *(ldap_get_values(ldap, new_ldap_msg, attrs[count++])));
} while ((new_ldap_msg = ldap_next_entry(ldap, ldap_msg)) != NULL);
}
}
在 if 语句中,如果我删除了字符串比较操作之一(任何一个),它都可以正常工作。一旦我将两者放在一起,甚至在嵌套的 if 语句中,我调用此函数的整个程序都会崩溃。有人知道这可能是什么原因吗?
以下是我的函数标题:
extern "C" __declspec(dllexport) LPCTSTR ADAuthenticate(TCHAR * username, TCHAR * password, TCHAR * server,
TCHAR * backup_server, TCHAR * domain, HWND h_wnd,
TCHAR ** attrs)
这就是我导入 DLL 函数的方式:
[DllImport("WM_LDAP.dll")]
public static extern IntPtr ADAuthenticate(string username, string password, string server,
string backup_server, string domain, IntPtr hWnd, string [] attrs);
【问题讨论】:
标签: c# windows-mobile dllimport