|
Hi,
I have created a toolbar button. I want to give a short cut key to it. Can any body help me.
thanks all of them who open it
|
|
|
|
|
See about accelerators[^]
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SYSTRAYDEMO));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage (&msg);
}
}
You need to add resourecs :: accelelators there u need to mention shortcut key and resource id
|
|
|
|
|
Hi
I am using Visual Studio 2008 with VC++ settings
While i try to add a C++ class the application header include in not comming is it problem or we need to set any properties.
I any one know please help me
Thanks in advance
----------------------------
KRISHNA KUMAR T M
|
|
|
|
|
How do you add the class...
The include has to be added manually since the software does not know where do you want to use the class being added....
Is there a problem in adding the header manually?
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Can I use InvalidateRect() in place of CWnd::Invalidate().
|
|
|
|
|
You can, this is what Invalidate looks like from MFC headers:
_AFXWIN_INLINE void CWnd::Invalidate(BOOL bErase)
{ ASSERT(::IsWindow(m_hWnd)); ::InvalidateRect(m_hWnd, NULL, bErase); }
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Hi,
I have an application which opens .doc file and saves it with .prt extention. I would like to know how can we provide icon new custom to these newly generated files.
Suhas
SNI
|
|
|
|
|
Look for "file associations", there are plenty of articles and useful hints around the net. It's basicly nothing more than modifying the registry afaik.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Hi All,
I want to write(append) word(data) into a file(CFile). I'm using
CFile to do the same..
CFile cf;
cf.SeekToEnd() is called before every
cf.Write()
But i need to write every data in a new line of text file.
In CFile how could i achieve this?
Thanks & Regards,
Anitha
|
|
|
|
|
void WriteFile(CString sFilename, CString sText)
{
CFileException CFE;
CStdioFile outFile;
if (outFile.Open(sFilename, CFile::modeCreate | CFile::modeNoTruncate |
CFile::modeWrite | CFile::typeText, &CFE))
{
// Seek to the end
outFile.SeekToEnd();
// Start outputting to the new file
outFile.WriteString(sText);
outFile.WriteString("\n");
// Cleanup
outFile.Close();
}
you can use above function to do this..i hope this will help
SNI
|
|
|
|
|
Do you know files can be open in append mode?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi,
I want to change the FileName Extension with FileName Edit Box when we change the extension in Combobox, i am handling the CDN_TYPECHANGE NOTIFY Event with my hook procedure.
Thanks for any help or suggestion.
|
|
|
|
|
How do i implement a marquee in my dialog based application? any leads will be of great help
|
|
|
|
|
What about CodeProject's article searh engine [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The idea sounds good
|
|
|
|
|
Hi all,
First of all props to Randor for helping me and giving me a base code now I modified his code and this is it:
#include <iostream>
#include <tchar.h>
#include <windows.h>
#include <Wincrypt.h>
#include <Xenroll.h>
#include <atlenc.h>
#include <atlcrypt.h>
#pragma comment(lib, "crypt32.lib")//n7M41mbWvrA=
BYTE* Base64Decode2(LPCTSTR lpData, DWORD dwSize, DWORD *dwBufSize)
{
DWORD dwResult = 0;
if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult,NULL,NULL))
{
BYTE * decodedStr;
decodedStr = new BYTE;
LPTSTR lpszBase64Decoded = new TCHAR[dwResult+(sizeof(TCHAR) * 2)];
memset(decodedStr,0,dwResult);
if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64,decodedStr, &dwResult,NULL,NULL))
{
*dwBufSize = dwResult;
return decodedStr;
}
}
return NULL;
}
LPTSTR Base64Encode2(BYTE* lpData, DWORD dwSize, BOOL bStripCRLF, DWORD *dwbufSize)
{
DWORD dwResult = 0;
if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult))
{
LPTSTR lpszBase64 = new TCHAR[dwResult];
if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, lpszBase64, &dwResult))
{
TCHAR pByteLF = *(LPWORD)(lpszBase64 + dwResult -1);
TCHAR pByteCR = *(LPWORD)(lpszBase64 + dwResult -2);
if(pByteCR == 0x0D && pByteLF == 0x0A)
{
*(LPWORD)(lpszBase64 + dwResult -2) = 0;
}
*dwbufSize = dwResult;
return lpszBase64;
}
}
return NULL;
}
DWORD TripleDESdecrypt2(TCHAR *cyphertext,DWORD ctlen,TCHAR *passwd,DWORD pwlen,BYTE *plaintext,DWORD *ptlen)
{
HCRYPTPROV hProv;
HCRYPTHASH hHash;
HCRYPTKEY hKey;
DWORD dwSizeNeeded =0;
CryptAcquireContext(&hProv,NULL,MS_STRONG_PROV,PROV_RSA_FULL,0);
CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
CryptHashData(hHash,(BYTE *)passwd,pwlen,0);
CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
DWORD dMode = CRYPT_MODE_ECB;
CryptSetKeyParam(hKey, PKCS5_PADDING, reinterpret_cast<const BYTE *>(&dMode), 0);
if(*ptlen >= ctlen)
{
memcpy(plaintext,cyphertext,*ptlen);
BOOL result = CryptDecrypt(hKey,NULL,1,0,plaintext,&ctlen);
*ptlen=ctlen;
}
else
{
dwSizeNeeded = ctlen * sizeof(TCHAR);
}
CryptDestroyKey(hKey);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv,0);
return dwSizeNeeded;
}
int main()
{
BYTE* decodedStr;
HCRYPTPROV hCryptProv;
HCRYPTHASH hHash = 0;
HCRYPTKEY hKey = 0;
TCHAR szKey[] = _T("h3bmull3r");
TCHAR szUnencrypted[MAX_PATH * sizeof(TCHAR)] = _T("n7M41mbWvrA=");
TCHAR * pszEncrypted = NULL;
TCHAR * pszBase64 = NULL;
TCHAR * pszBase64Decoded = NULL;
TCHAR * psz3DESDecoded = NULL;
DWORD dwSizeNeeded;
DWORD BufSize;
DWORD dwUnEncryptedSize;
TCHAR * KeyBase64 = NULL;
decodedStr = Base64Decode2(szUnencrypted,_tcslen(szUnencrypted) * sizeof(TCHAR), &BufSize);
dwUnEncryptedSize = NULL;
TCHAR *decoded = reinterpret_cast<TCHAR*>(decodedStr);
dwSizeNeeded = TripleDESdecrypt2(decoded,MAX_PATH * sizeof(TCHAR),szKey,_tcslen(szKey),decodedStr,&dwUnEncryptedSize);
psz3DESDecoded = new TCHAR[dwSizeNeeded];
TripleDESdecrypt2(decoded,dwSizeNeeded,szKey,_tcslen(szKey),decodedStr,&dwSizeNeeded);
pszBase64 = Base64Encode2(decodedStr,BufSize,FALSE, &BufSize);
delete [] pszBase64;
delete [] pszBase64Decoded;
delete [] pszEncrypted;
return 0;
}
Now this is a long version of the decryption method of this:
public static string Decrypt(string cipherString, bool useHashing)
{
byte[] keyArray;
byte[] toEncryptArray = Convert.FromBase64String(cipherString);
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
if (useHashing)
{
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();
}
else
keyArray = UTF8Encoding.UTF8.GetBytes(key);
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
tdes.Clear();
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
Now I am able to encode a string to base 64 and get its original string bace by using Base64Encode2 and Base64Decode2. My goal now is to decrypt this string "n7M41mbWvrA=" into the string "test". Thing is CryptDecrypt fails and gives me a bad data. What could be possibly wrong with me.
Thanks,
Jayjay
|
|
|
|
|
Why do you never check API functions' return values?
You should always check for failures (and then call GetLastError to get the reason of).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Why do you never check API functions' return values?
Please dont shoot next time.
|
|
|
|
|
Ooops yep I did and I get a bad data error i forgot the number, i did put getlasterror i wasnt able to paste it here.
|
|
|
|
|
Please post:
(1) the name of the failing function.
(2) the return value of GetLastError().
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
JayJay,
The code I posted yesterday [^]works in both Unicode and ANSI builds. The only thing I did not give you is UTF8 conversion[^] because I do not know what codepage[^] your C# application is using. The Base64 string "n7M41mbWvrA=" does not appear to be standard Unicode or ANSI when converted from Base64 so you cannot convert it into a readable string until you match the codepage[^].
Best Wishes,
-David Delaune
|
|
|
|
|
Hi David ,
This is the whole solution of the c# application used for the encryption: Link[^] Yup I have tested it and kinda reversed engineered it to imitate the c# conversion, I just revised it a bit that both byte[] toEncryptArray = Convert.FromBase64String(toEncrypt); and return Convert.ToBase64String(resultArray, 0, resultArray.Length); are used instead of using the UTF8 conversion although it is still being used when converting the key.
Please enlighten me
Thanks,
Jayjay
|
|
|
|
|
Hello JayJay,
Now that I have looked at the C# project I think I know what the problem is. The C# code is using ECB (Electronic Code Book) and PKCS-7. They are using entirely different 3DES modes and padding. Its getting late here, I will look at it again tomorrow.
If you want to experiment you can start with changing modes in the code I gave you:
BYTE nMode = CRYPT_MODE_ECB;
CryptSetKeyParam(hKey,KP_MODE,&nMode,0);
You may also need to generate a temporary BLOBHEADER of type PLAINTEXTKEYBLOB for this mode. I'm not really sure.
Good Luck,
-David Delaune
|
|
|
|
|
Hi David,
Thanks I have also tried that as you can see at the code I posted, where will I use the blobheader? Is it just a container of the modes and 3des algorithm?
Thanks for the continuous help,
Jayjay
|
|
|
|
|