|
I'm working on a fatal error which make our application crash! I can not reproduce it in my environment, so I tried to get the Dr.Watson's dump log and it indicate such error:
380861d0 da742430 fidiv dword ptr [esp+0x30] ss:00c0977f=a0b900c1
FAULT ->380861d4 d95e58 fstp dword ptr [esi+0x58] ds:00c0983a=c1eed825
I have found the code corresponding to the asm instruction:
i = float (m_rect.Width()) / float(m_rect.Height());
Just two floats' division!
I'm sure denominator is not Zero! I can not understand why the fstp give such a fatal message:
Exception code: c0000090 (FLT_INVALID_OPERATION)
Who can give me advices? Thanks a lot, a lot...
|
|
|
|
|
Are you using VC7.1 or VC8 release canditate. As far as I remember, this is a bug on those IDEs.
--
=====
Arman
|
|
|
|
|
Im tryin to write a VC++ application to encrypt any file the user selects.
I have done it for a binary file. But have no idea about how to do it if its a video or picture file.
What do i do?
Jesus Loves Us Just the way we are! Invite Him into your life today!
|
|
|
|
|
No difference. Those files are binary too.
--
=====
Arman
|
|
|
|
|
But then wat about loading the contents of the file to encrypt and stuff...
do i do it the same way??
cuz i tried using the same method and the encrypted stuff is not the same as the source...
Jesus Loves Us Just the way we are! Invite Him into your life today!
|
|
|
|
|
Then what's the purpose of your encryption? What encryption method are you using?
--
=====
Arman
|
|
|
|
|
This is the code snippet for the original binary file encryption program.
I just need to convert this so that it can accept any file. Im using the RIjnael class for the encryption and decryption.
The purpose is to encrypt and decrypt any file using the same key.
<br />
void CFileEnDecryptionDlg::Char2Hex(const unsigned char ch, char *szHex)<br />
{<br />
unsigned char byte[2];<br />
byte[0] = ch/16;<br />
byte[1] = ch%16;<br />
for(int i=0; i<2; i++)<br />
{<br />
if(byte[i] >= 0 && byte[i] <= 9)<br />
szHex[i] = '0' + byte[i];<br />
else<br />
szHex[i] = 'A' + byte[i] - 10;<br />
}<br />
szHex[2] = 0;<br />
}<br />
<br />
void CFileEnDecryptionDlg::Hex2Char(const char *szHex, unsigned char &rch)<br />
{<br />
rch = 0;<br />
for(int i=0; i<2; i++)<br />
{<br />
if(*(szHex + i) >='0' && *(szHex + i) <= '9')<br />
rch = (rch << 4) + (*(szHex + i) - '0');<br />
else if(*(szHex + i) >='A' && *(szHex + i) <= 'F')<br />
rch = (rch << 4) + (*(szHex + i) - 'A' + 10);<br />
else<br />
break;<br />
}<br />
}<br />
<br />
<br />
<br />
void CFileEnDecryptionDlg::CharStr2HexStr(const char *pucCharStr, char *pszHexStr, int iSize)<br />
{<br />
int i;<br />
char szHex[3];<br />
pszHexStr[0] = 0;<br />
for(i=0; i<iSize; i++)<br />
{<br />
Char2Hex(pucCharStr[i], szHex);<br />
strcat(pszHexStr, szHex);<br />
}<br />
}<br />
<br />
void CFileEnDecryptionDlg::HexStr2CharStr(const char *pszHexStr, char *pucCharStr, int iSize)<br />
{<br />
int i;<br />
unsigned char ch;<br />
for(i=0; i<iSize; i++)<br />
{<br />
Hex2Char(pszHexStr+2*i, ch);<br />
pucCharStr[i] = ch;<br />
}<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnEncryptBtn() <br />
{<br />
<br />
h = 0;<br />
<br />
tag:<br />
<br />
CWnd *input, *output, *result; <br />
CWnd *msgbox;<br />
CString key,text, message;<br />
char buf[300],hex[600]; <br />
<br />
memset(buf,0,300);<br />
memset(hex,0,600);<br />
<br />
<br />
input = GetDlgItem(IDC_SOURCE_FILE_CONTENTS);<br />
output = GetDlgItem(IDC_KEY);<br />
msgbox = GetDlgItem(IDC_MSGBOX);<br />
result = GetDlgItem(IDC_RESULT);<br />
<br />
result->SetWindowText("");<br />
<br />
output->GetWindowText(key);<br />
input->GetWindowText(text);<br />
<br />
int flag = 0;<br />
if(key.GetLength()==0)<br />
{<br />
output->SetWindowText("1234567890123456");<br />
msgbox->SetWindowText("Default Value of key used");<br />
<br />
}<br />
<br />
if(text.GetLength() == 0){<br />
input->SetWindowText("Scolis Technologies Pvt. Ltd.");<br />
<br />
output->GetWindowText(key);<br />
input->GetWindowText(text);<br />
flag = 1;<br />
}<br />
<br />
<br />
<br />
rijndael.MakeKey ((LPCTSTR)key);<br />
<br />
int length = text.GetLength();<br />
<br />
<br />
if((text.GetLength() % 16) != 0)<br />
{<br />
<br />
while((text.GetLength() % 16) != 0)<br />
{<br />
text.Insert(length,'0');<br />
length++;<br />
}<br />
if (flag == 0)<br />
msgbox->SetWindowText("Zeroes have been padded to make the length of string divisible by 16 ");<br />
else<br />
<br />
msgbox->SetWindowText("I'm taking default values since you provided none. Note: Zeroes have been padded to make the length of string divisible by 16");<br />
} <br />
<br />
rijndael.Encrypt((LPCTSTR)text, buf, text.GetLength());<br />
<br />
CharStr2HexStr(buf, hex, strlen(buf));<br />
result->SetWindowText(hex);<br />
<br />
if (h == 0)<br />
{ <br />
h=1; <br />
goto tag;<br />
}<br />
<br />
<br />
CFile OFile;<br />
OFile.Open(m_DestinationFileName, CFile::modeWrite | CFile :: modeCreate);<br />
<br />
CArchive ar(&OFile, CArchive::store);<br />
ar << (CString)hex;<br />
ar.Close();<br />
<br />
memset(buf,0,300);<br />
memset(hex,0,600);<br />
<br />
<br />
OFile.Close();<br />
msgbox -> SetWindowText("Encrypted Content has been Written to file!");<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnDecryptBtn() <br />
{<br />
CWnd *key,*cipher,*result, *msgbox;<br />
CString key_text, cipher_text;<br />
char buf[300],buf1[300];<br />
<br />
key_text = '\0';<br />
cipher_text = '\0';<br />
key = NULL;<br />
<br />
memset(buf,0,300);<br />
memset(buf1,0,300);<br />
<br />
<br />
<br />
key = GetDlgItem(IDC_KEY);<br />
cipher = GetDlgItem(IDC_SOURCE_FILE_CONTENTS);<br />
result= GetDlgItem(IDC_RESULT);<br />
msgbox = GetDlgItem(IDC_MSGBOX);<br />
<br />
<br />
key->GetWindowText(key_text);<br />
cipher->GetWindowText(cipher_text);<br />
<br />
if( cipher_text.GetLength()==0){<br />
cipher->SetWindowText("C9377FD2C4D57AA3BD84B247EF0995264CB4378A4E0EA21DA98B7016F64B121C");<br />
cipher->GetWindowText(cipher_text);<br />
}<br />
<br />
<br />
if(key_text.GetLength() == 0 ){<br />
msgbox->SetWindowText("Ciphertext or Key, decrypting using default values");<br />
key->SetWindowText("1234567890123456");<br />
key->GetWindowText(key_text);<br />
<br />
}<br />
<br />
<br />
<br />
rijndael.MakeKey ((LPCTSTR)key_text);<br />
<br />
HexStr2CharStr((LPCTSTR)cipher_text, buf1, cipher_text.GetLength ());<br />
<br />
rijndael.Decrypt((LPCTSTR)buf1, buf, strlen(buf1));<br />
<br />
result->SetWindowText(buf);<br />
<br />
CFile OFile;<br />
OFile.Open(m_DestinationFileName, CFile::modeWrite | CFile :: modeCreate);<br />
<br />
CArchive ar(&OFile, CArchive::store);<br />
ar << (CString)buf;<br />
ar.Close();<br />
<br />
memset(buf,0,300);<br />
memset(buf1,0,300);<br />
<br />
OFile.Close();<br />
msgbox -> SetWindowText("Decrypted Content has been Written to file!");<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnDefaultBtn() <br />
{<br />
m_SourceFileContents="Scolis Technologies Pvt. Ltd.";<br />
<br />
m_Key= "1234567890123456";<br />
CWnd *result, *msgbox;<br />
<br />
result= GetDlgItem(IDC_RESULT);<br />
msgbox = GetDlgItem(IDC_MSGBOX);<br />
<br />
result->SetWindowText("");<br />
<br />
UpdateData(FALSE);<br />
msgbox->SetWindowText("Default Contents Entered");<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnInBrowse() <br />
{<br />
CFile TextFile;<br />
<br />
char strFilter[]={ "Binary Files (*.bin)|*.bin||" };<br />
<br />
CFileDialog FileDlg( TRUE, "*.bin", NULL, 0, strFilter);
<br />
if( FileDlg.DoModal() == IDOK)<br />
{<br />
if( TextFile.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE )<br />
{<br />
return;<br />
}<br />
<br />
CArchive ar( &TextFile, CArchive::load);
ar >> m_SourceFileContents;
ar.Close();<br />
}<br />
else<br />
{<br />
return;<br />
}<br />
<br />
TextFile.Close();<br />
<br />
this -> UpdateData(FALSE);<br />
<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnOutBrowse() <br />
{<br />
CWnd *name;<br />
<br />
name = GetDlgItem(IDC_DESTINATION_FILE_NAME);<br />
<br />
CFile TextFile;<br />
<br />
char strFilter[]={ "Binary Files (*.bin)|*.bin||" };<br />
<br />
CFileDialog FileDlg( TRUE, "*.bin", NULL, 0, strFilter);
<br />
if( FileDlg.DoModal() == IDOK)<br />
{<br />
if( TextFile.Open(FileDlg.GetFileName(), CFile::modeWrite | CFile::modeCreate) == FALSE )<br />
{<br />
return;<br />
}<br />
m_DestinationFileName = FileDlg.GetPathName();<br />
<br />
}<br />
else<br />
{<br />
return;<br />
}<br />
<br />
TextFile.Close();<br />
<br />
this -> UpdateData(FALSE);<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnCancel() <br />
{<br />
exit(0);<br />
<br />
CDialog::OnCancel();<br />
}
Jesus Loves Us Just the way we are! Invite Him into your life today!
|
|
|
|
|
Ok, if your purpose is solely encrypt/decrypt, then this code will do. Only do open the file in binary mode, read bytes from there and pass them to your enryption algorythm. If after encryption and a corresponding decryption you cannot get what you had before, than your algorythms are wrong; no matter you have used video, image or other types of files.
--
=====
Arman
|
|
|
|
|
hey thanks duude
it worked
Jesus Loves Us Just the way we are! Invite Him into your life today!
|
|
|
|
|
Hi All,
Currently I'm developing a tool, for that purpose i have to know all other processes running on the computer and achieve the handle of specified process.There are some functions in VB and but i need to write in MFC only... How can get it?
bye
kamalesh
kamalesh
|
|
|
|
|
See the APIs Process32First, Process32Next from include header <tlhelp32.h>
--
=====
Arman
|
|
|
|
|
|
Does EnumProcesses helpful?
|
|
|
|
|
Pls Find answer to your code....
I dont know how i can attach a file to code project message. there fore please copy from the message...
/* Header File for the Class /*
#include "stdafx.h"
#include "psapi.h"
#pragma pack(16)
#define FOUND_WJRU 0
#define WJRU_NOTFOUND 1
class CProcessMonitor
{
private:
DWORD mAvailableProcesses[1024], cbNeeded, cProcesses;
public:
UINT getTotalAvailableProcesses();
UINT getProcessTimes();
BOOL FindProcessandMemoryDetails(DWORD processID,CString Processname,PROCESS_MEMORY_COUNTERS& psmemCounters);
BOOL IsProcessMatchingNameAndID( DWORD processID, UINT index );
HANDLE GetProcessHandle(DWORD processID, CString Processname);
HANDLE GetHandleToProcess(CString Processname);
void GetJRUStatus(int&nStatus, PROCESS_MEMORY_COUNTERS& psMemInfo);
};
#pragma pack()
/// CPLUSS PLUS FILE....
#include "stdafx.h"
#include "psapi.h"
#include "EnumProcess.h"
BOOL CProcessMonitor::IsProcessMatchingNameAndID( DWORD processID, UINT index )
{
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH] = "Wjru.exe";
PROCESS_MEMORY_COUNTERS psmemCounters;
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
if(strcmp(szProcessName,szTargetProcessName) ==0)
{
GetProcessMemoryInfo(hProcess,&psmemCounters,sizeof(PROCESS_MEMORY_COUNTERS));
return TRUE;
}
else
{
return FALSE;
}
}
}
return FALSE;
}
BOOL CProcessMonitor::FindProcessandMemoryDetails(DWORD processID, CString Processname,PROCESS_MEMORY_COUNTERS& psmemCounters)
{
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];
strcpy(szTargetProcessName,Processname.GetBuffer(50));
Processname.ReleaseBuffer();
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
if(strcmp(szProcessName,szTargetProcessName) ==0)
{
GetProcessMemoryInfo(hProcess,&psmemCounters,sizeof(PROCESS_MEMORY_COUNTERS));
return TRUE;
}
else
{
return FALSE;
}
}
}
return FALSE;
}
void CProcessMonitor::GetJRUStatus(int& nStatus, PROCESS_MEMORY_COUNTERS& psMemInfo)
{
ULONG lCpuusage = 0;
UINT index;
//Find Total Number of Processes;
if (!EnumProcesses( mAvailableProcesses, sizeof(mAvailableProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
if(cProcesses > 1000)
{
AfxMessageBox("There are Too Many applications Running on PC.");
}
PROCESS_MEMORY_COUNTERS psTempMemInfo;
for ( index = 0; index < cProcesses; index++ )
{
if(FindProcessandMemoryDetails(mAvailableProcesses[index],"Wjru.exe",psTempMemInfo)== TRUE)
{
nStatus = FOUND_WJRU;
psMemInfo = psTempMemInfo;
return;
}
}
nStatus = WJRU_NOTFOUND;
}
HANDLE CProcessMonitor::GetProcessHandle(DWORD processID, CString Processname)
{
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];
strcpy(szTargetProcessName,Processname.GetBuffer(50));
Processname.ReleaseBuffer();
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
if(strcmp(szProcessName,szTargetProcessName) ==0)
{
return hProcess;
}
else
{
return NULL;
}
}
}
return NULL;
}
HANDLE CProcessMonitor::GetHandleToProcess(CString ProcessName)
{
HANDLE hProcess;
hProcess = NULL;
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];
strcpy(szTargetProcessName,ProcessName.GetBuffer(50));
ProcessName.ReleaseBuffer();
ULONG lCpuusage = 0;
UINT index;
//Find Total Number of Processes;
if (!EnumProcesses( mAvailableProcesses, sizeof(mAvailableProcesses), &cbNeeded ) )
return hProcess;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
if(cProcesses > 1000)
{
AfxMessageBox("There are Too Many applications Running on PC.");
}
for ( index = 0; index < cProcesses; index++ )
{
hProcess= GetProcessHandle(mAvailableProcesses[index],szTargetProcessName);
if(hProcess != NULL)
{
return hProcess;
}
}
return hProcess;
}
Haribabu....
|
|
|
|
|
kasturi_haribabu wrote: I dont know how i can attach a file to code project message
Not yet,but you can use of pre when post a code.;)
|
|
|
|
|
Thanks for this nice and beutiful code. Thanks to all....All are helpfuls. Thanks again.
kamalesh
|
|
|
|
|
Hi all,
I have made a list control which is of report style, what i want is when a particular condition is met the whole row colour should change to red. and if more than 1 row satisfy that condition all row's colour should change to red.
can anybody help me in this
thanks in advance
|
|
|
|
|
|
Hi,
Try here[^] and/or here[^]
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
hi all,
i am having a class and i want to impliment 2 overloaded constructors as:
in .h file:
Document(const char* filename=NULL);
Document(const wchar_t* filename=NULL);
in .cpp file
Document::Document( const char* filespec )
{
m_pdoc = NULL;
load( filespec );
}
Document::Document( const wchar_t* filespec )
{
m_pdoc = NULL;
load( filespec );
}
the load function is also overloaded.
but it gives me warning saying:
warning C4520: 'Document' : multiple default constructors specified
and error saying:
error C2668: 'Document::Document' : ambiguous call to overloaded function
where i am going wrong?
|
|
|
|
|
Guess what happen if you don't pass anything to your constructor ? How will your compiler be able to select one of the two constructor ?
Remove the default parameter so that the compiler isn't confused in the case where you don't pass any argument.
|
|
|
|
|
|
in .h file:
Document(const char* filename=NULL);
Document(const wchar_t* filename=NULL);
The reason is here. You specified two default ctors because both of them are supposed to be called when no arhuments are passed to a ctor. So remove the default parameter value (=NULL) from one of ctors [or both of them].
--
=====
Arman
|
|
|
|
|
sandeepkavade wrote: Document(const char* filename=NULL);
Document(const wchar_t* filename=NULL);
Why not replace them with:
Document( const TCHAR *filename = NULL );
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have to transfer file via UDP. Please send me any sample codes or links or suggestions regarding this.
S.Yamini
|
|
|
|
|