ATL中的可以单独使用的工具类
作者:Carfield 转载:http://blog.joycode.com/peon/ ATL7中除了制作COM和windows组件的大量的工具,还提供了大量的工具类,可以让我们在C++编程方面事半功倍。 void TestMd5Hash() { const char* szPassword = "real9video.rm ts=2003-12-23-16-23-9"; CCryptProv prov; HRESULT hr = prov.Initialize(); if( hr == 0x8009016L ) prov.Initialize( PROV_RSA_FULL,NULL,MS_DEF_PROV,CRYPT_NEWKEYSET ); //这个其实和下面的代码差不多 //CCryptKeyedHash hash; //hash.Initialize(prov, CALG_MD5, CCryptKey::EmptyKey, 0); CCryptMD5Hash hash; hash.Initialize( prov ); hash.AddString( szPassword ); BYTE buf[1024]; DWORD outLen; hash.GetValue( buf , &outLen ); printHex( buf , outLen );//这个大家自己实现,打印byte数组的内容 //应该是 BC CB 76 69 78 CF AB 4B 8 D E9 42 32 B0 88 9C }4.编码装换,下面是Base64和UTF8的转换,要包含atlenc.h void Base64() { CString sSource = "some string"; int nDestLen = Base64EncodeGetRequiredLength(sSource.GetLength()); CString str64; Base64Encode((const BYTE*)(LPCSTR)sSource, sSource.GetLength(), str64.GetBuffer(nDestLen), &nDestLen); str64.ReleaseBuffer(nDestLen); cout<<(LPCSTR)str64; int nDecLen = Base64DecodeGetRequiredLength(nDestLen); CString strOrig; Base64Decode(str64, str64.GetLength(), (BYTE*)strOrig.GetBuffer(nDecLen), &nDecLen); strOrig.ReleaseBuffer(nDecLen); cout<<(LPCSTR)strOrig; } void UTF8Convert() { char buf[128]; memset( buf , 0 , 128 ); int n = AtlUnicodeToUTF8( L"复件" , 2 , buf , 128 ); printHex( (BYTE*)buf ,n ); }5. CATLRegExp 正则表达式工具,msdn中有例子,这里也贴一下 CAtlRegExp<> regexp; CAtlREMatchContext<> mc; // match any line that starts with any number of digits, // has a dash, and ends with any number of digits if(regexp.Parse("^//d+-//d+$") == REPARSE_ERROR_OK) { const char* szNumDashNum="5663-4662"; if(regexp.Match(szNumDashNum, &mc)) { ATLTRACE("Matched"); } } |
ATL中的可以单独使用的工具类
最新推荐文章于 2019-04-03 10:32:51 发布