Archive
CComPtr vs _com_ptr_t
Recently a user asked this question in forums, I was quite able to answer his query. So thought this might be useful to you guys too. 🙂
So the basic difference is that CComPtr is an ATL class is used with using ATL COM implementations while _com_ptr_t is one of the few COM support classes to support non ATL COM development. The definitions of these COM support classes go along with the tlb files and probably that’s why they are called as COM support classes. Also their definition can be found in comdef.h too. The other classes similar to _com_ptr_t are …
- _bstr_t
- _com_error
- _com_ptr_t
- _variant_t
So what are COM support classes? These are special lightweight classes that wraps basic useful COM functionality so that ideas like COM smart pointer typedefs over raw COM inteface classes works just by using tlb file. An example on how _com_ptr_t is used…
_COM_SMARTPTR_TYPEDEF(IMyInterface, __uuidof(IMyInterface));
This above line declares _com_ptr_t specialization IMyInterfacePtr.
The library to link to for using COM support classes is comsuppw.lib.
Is a user account locked?
Every network has a security policy, for e.g. lock user account if he enters wrong password five times.
So is it possible to find out whether a user’s account is locked? Yes use active directory services interface pointer IADsUser.
So here is a function which returns true if account is locked…
#pragma comment(lib, “ActiveDS.lib”) // For ADsGetObject
#pragma comment(lib, “Adsiid.lib” ) // For IID_IADs and IID_IADsUser
#include
bool IsAccountLocked( LPCWSTR DomainName, LPCWSTR UserName )
{
std::wstring uPath= L”WinNT://”;
uPath += DomainName;
uPath += L”/”;
uPath += UserName;
uPath += L”,user”;
CComPtr pUser = 0;;
HRESULT hr = ADsGetObject( uPath.c_str(), IID_IADsUser, (void**)&pUser );
if( FAILED( hr ))
{
ASSERT( FALSE );
return false;
}
VARIANT_BOOL AccountLocked = VARIANT_FALSE;
hr = pUser->get_IsAccountLocked( &AccountLocked );
if( FAILED( hr ))
{
ASSERT( FALSE );
return false;
}
return ( AccountLocked != VARIANT_FALSE );
}
int main()
{
CoInitialize( NULL );
std::wstring DomainName = L”Domain”;
std::wstring UserName = L”UserName”;
std::wcout << L"User account of "<< UserName << L" locked? " << std::boolalpha << IsAccountLocked( DomainName.c_str(), UserName.c_str() ) << std::endl; CoUninitialize(); return 0; }[/sourcecode]
Rate this:
Like this: