Article ID: 156905
Article Last Modified on 1/19/2005
Download the Progress.exe package now.
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 How to obtain Microsoft support files from online services
#define USERNAME_BUFFER_SIZE 255
#define PASSWORD_BUFFER_SIZE 255
#define ARRAY_SIZE( arr ) ( sizeof(arr)/sizeof(arr[0]) )
STDMETHODIMP CBindStatusCallback::Authenticate(
HWND *phwnd,
LPWSTR *pwszUsername,
LPWSTR *pwszPassword)
{
TCHAR pszDlgUser[USERNAME_BUFFER_SIZE];
WCHAR *wszDlgUser = NULL;
TCHAR pszDlgPassword[PASSWORD_BUFFER_SIZE];
WCHAR *wszDlgPassword = NULL;
if (!phwnd || !pwszUsername || !pwszPassword)
return E_INVALIDARG;
*phwnd = NULL;
// If dialog controls have valid user & pass, use that
HWND hWndUser = ::GetDlgItem(g_hwndDlg, IDC_USERNAME);
HWND hWndPassword = ::GetDlgItem(g_hwndDlg, IDC_PASSWORD);
// This is needed because in case the above window handles are not valid,
// the buffers will stay uninitialized
ZeroMemory(pszDlgUser, sizeof(pszDlgUser));
ZeroMemory(pszDlgPassword, sizeof(pszDlgPassword));
::GetWindowText(hWndUser, pszDlgUser, ARRAY_SIZE(pszDlgUser));
::GetWindowText(hWndPassword, pszDlgPassword, ARRAY_SIZE(pszDlgPassword));
if ( *pszDlgUser )
{
#ifndef UNICODE
wszDlgPassword = (WCHAR *)CoTaskMemAlloc( PASSWORD_BUFFER_SIZE * sizeof(WCHAR) );
wszDlgUser = (WCHAR *)CoTaskMemAlloc( USERNAME_BUFFER_SIZE * sizeof(WCHAR) );
MultiByteToWideChar(GetACP(), 0, pszDlgUser, -1, wszDlgUser, USERNAME_BUFFER_SIZE);
MultiByteToWideChar(GetACP(), 0, pszDlgPassword, -1, wszDlgPassword, PASSWORD_BUFFER_SIZE);
#else
wszDlgUser = (WCHAR*)CoTaskMemAlloc((lstrlen(pszDlgUser) + 1) * sizeof(WCHAR));
lstrcpy(wszDlgUser,pszDlgUser);
wszDlgPassword = (WCHAR*)CoTaskMemAlloc((lstrlen(pszDlgPassword) + 1) * sizeof(WCHAR));
lstrcpy(wszDlgPassword,pszDlgPassword);
#endif
*pwszUsername = wszDlgUser;
*pwszPassword = wszDlgPassword;
}
else
{
*pwszUsername = NULL;
*pwszPassword = NULL;
*phwnd = g_hwndDlg;
// Depending on your application, this may return S_OK also.
return E_ACCESSDENIED;
}
return S_OK;
}
When the URL moniker attempts to bind to the object specified in the call
to CreateURLMoniker, it determines whether or not the object is secured. If
the object is secured, the URL moniker queries the bind status callback
object for IAuthenticate. The URL moniker queries for IAuthenticate through
the IBindStatusCallback interface pointer registered with the bind context
used in the binding operation.
Additional query words: URLMON IBSC Progress
Keywords: kbinfo kbdownload kburlmon kbfile kbsample KB156905