I don't remember where I got a MD5 encryption class, because of the reason for development to use MD5 encryption in WTL, but this class is not directly used in the WTL (in the MFC it was a easy job), so I modified, and write this article, To facilitate the use of MD5 encryption in WTL later. However, the level of the younger brother is limited, there are mistakes and omissions places, I hope you forgive me.
The running interface of the program is as follows:
All: Configure WTL in your VC compiler (Copy section first:-))
First install WTL AppWizard, now the highest version should be WTL7.0, directly run the setup script file on it, here to everyone a few download addresses:
1) http://www.vckbase.com/tools/listtools.asp?tclsid=111
2) http://www.microsoft.com/downloads/details.aspx?familyid=128e26ee-2112-4cf7-b28e-7727d9a1f288& displaylang=en
3) http://www.copathway.com/vchelp/zsrc/wtlm.asp?type_id=70&class_id=1&cata_id=3&article_id=374
This way, when you start VC6.0, file/new, you can see the addition of a ATL/WTL AppWizard on the project Properties page. You can copy WTL's library files (a total of 16. h files) to the VC installation directory Vc98/include, or you can put them in your Engineering folder.
And: Modify the appropriate WTL MD5 encryption algorithm class
This class has 3 files, md5checksum.h,md5checksumdefines.h,md5checksum.cpp. Do not know this class library is not dedicated in MFC, but I can be very direct in MFC to use it, but, in the WTL, it can not be used directly. We must make a small change to it. First of all, if we want to use it in WTL, we should add the #include<atlmisc.h> to the MD5Checksum.h file, so that it can support WTL CString. Again, to put the class library assert (not to be changed to Atlassert Bar), AfxIsValidAddress, and other WTL unsupported statements take out, you can rest assured that these are debugging use of the statement (maybe, removed also does not matter, and later proved to be so Then, there are two functions in this class library, to use the CFile (if you have to use the file, it is recommended to use standard C + + to encapsulate a cfile), you must also remove. They are static CString GetMD5 (cfile& File), static CString GetMD5 (const cstring& strFilePath);
And: You can use the MD5 encryption method
Here's what I do:
En_change event to handle edit:COMMAND_HANDLER(IDC_EDIT1, EN_CHANGE, OnChangeEdit1)
LRESULT OnChangeEdit1(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
CString str_ReourceText;
//get resource text
HWND hWndResourceText = GetDlgItem(IDC_EDIT1);
int int_ReourceText=::GetWindowTextLength(hWndResourceText);
int_ReourceText++;
LPTSTR lpStr = str_ReourceText.GetBufferSetLength(int_ReourceText);
::GetWindowText(hWndResourceText, lpStr, int_ReourceText);
str_ReourceText.ReleaseBuffer();
str_ReourceText =CMD5Checksum::GetMD5((BYTE*)(const char*)str_ReourceText.GetBuffer(0),str_ReourceText.GetLength());
//set the result text
SetDlgItemText(IDC_STATIC_RESUAL,str_ReourceText);
return 0;
}
Well, the said almost all said, do not understand, do not understand, do not understand, look at the source code it! Thank you for watching ~ ~
This article supporting source code