|
Hello,
I've posted a question on code project, but didn't get a good reply.
Why does the following code isn't working:
// the input params are
szOperation = "diff.exe"
szParams = " "C:\1.txt" "C:\WINDOWS\FileSafe\0017CF85-0029-0000-B9ED-DF4AD816684A\olvf.fs"
szCompareResFile ="C:\WINDOWS\FileSafe\0017CF85-0029-0000-B9ED-DF4AD816684A\cfv.fs.cr.1"
The called function to operate the GNU "Diff.exe" (which is based on the RGDiff application taken from code project) is :
int CFSMgr::OperateGNUDiff(CString szOperation,CString szParams,CString szCompareResFile)
{
int iOperationLen = szOperation.GetLength();
int iParamsLen = szParams.GetLength();
CString szCmdLine(szOperation);
szCmdLine += _T(" ");
szCmdLine += szParams;
TCHAR szCmd[CMD_LINE_BUFF_LEN];
_tcsncpy(szCmd,(LPTSTR)(LPCTSTR)szCmdLine,iOperationLen + iParamsLen + 2);
CString szEcnrypted(szCompareResFile);
szEcnrypted += _T(".enc");
CString szErrFile(szCompareResFile);
szErrFile += _T(".err");
CCrypt c;
DWORD dwExitCode(0);
int iLen = szEcnrypted.GetLength();
TCHAR szKey[] = _T("FS@CORE@");
TCHAR* lpszEncrypted = NULL;
BOOL bSucc(FALSE);
try
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = 0;
sa.bInheritHandle = 1;
HANDLE hOutput = CreateFile(szCompareResFile,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
&sa,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
HANDLE hErr = CreateFile(szErrFile,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
&sa,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
::ZeroMemory(&siStartupInfo, sizeof(siStartupInfo));
::ZeroMemory(&piProcessInfo, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
siStartupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
siStartupInfo.wShowWindow = SW_HIDE;
siStartupInfo.hStdOutput = hOutput;
siStartupInfo.hStdError = hErr;
bSucc = CreateProcess(0,
szCmd,
0,
0,
FALSE,
0,
0,
0,
&siStartupInfo,
&piProcessInfo);
while (TRUE)
{
bSucc = GetExitCodeProcess(piProcessInfo.hProcess, &dwExitCode);
if (dwExitCode != STILL_ACTIVE)
break;
else
Sleep(50);
}
CloseHandle(piProcessInfo.hProcess);
CloseHandle(hOutput);
CloseHandle(hErr);
switch (dwExitCode)
{
case 0:
bSucc = DeleteFile(szCompareResFile);
return 0;
case 1:
lpszEncrypted = new TCHAR[iLen];
_tcscpy(lpszEncrypted,szEcnrypted);
c.EncryptFile((LPTSTR)(LPCTSTR)szCompareResFile,lpszEncrypted,szKey);
if (lpszEncrypted)
SAFE_DELETE(lpszEncrypted);
bSucc = MoveFile(szEcnrypted,szCompareResFile);
_ONERR(bSucc, return -1);
return 1;
case 2:
ATLASSERT(FALSE);
return 2;
default:
ATLASSERT(FALSE);
return -1;
}
return 0;
}
catch(...)
{
ATLASSERT(FALSE);
return -1;
}
}
CreateProcess returns TRUE (succeeded!) but the GetExitCodeProcess method puts 2 for dwExitCode which indicates a diff.exe failure!
I can't figure out what's wrong????
Can any1 help ?
Thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
This means that the diff.exe process ran, and returned an exit code of 2. Taking a guess, this might mean that the two files you passed to it did not compare (they didn't have the same contents).
If you've got the documentation, see what diff.exe returns for files that are identical and those that are not. You might also want to try this from the command line or a batch file, where you can test exit codes using IF ERRORLEVEL .
Software Zen: delete this;
|
|
|
|
|
thanks for the quick response.
i have based my code uppon the article "RGDiff - Visual Diff Tool" by Rob Groves, you can find it here : http://www.codeproject.com/tools/rgdiff.asp[^]
the documentation says that 2 means an error occured whilst doing the diff and the err output file which i have placed (siStartupInfo.hStdError) should write the error that occured. unfortunately the error file that was created was empty....?
I still need some guidens here...you've mentioned a batch file and testing an error code, can u give an example code?
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Testing with a batch file is useful when you don't have documentation for the diff.exe program.
Given that you are constructing the command line dynamically, I would first verify that the command line you are building is correct. Set a breakpoint right before the call to CreateProcess and examine the contents of the command line. If that looks correct, I would try running diff.exe from the command line with the exact text you saw in the debugger, and see what message diff.exe is displaying. In this case, it should simply output the message to the screen.
Software Zen: delete this;
|
|
|
|
|
thanks for the reply.
I already did that, and running it from command line using the input params give 100% result! that is why i am so annoying. it works with a command line but it doesn't work using CreateProcess code....
help!?
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
YaronNir wrote:
szParams = " "C:\1.txt" "C:\WINDOWS\FileSafe\0017CF85-0029-0000-B9ED-DF4AD816684A\olvf.fs"
szCompareResFile ="C:\WINDOWS\FileSafe\0017CF85-0029-0000-B9ED-DF4AD816684A\cfv.fs.cr.1"
You must use double backslashes for string literals. Also, the szParams= statement has an odd number of quotation marks.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
whilst using the code i did use double back slash.
the odd number of quatation marks is wrong, in my code it is even
I've manage to get this code to work. aparantly i needed some more stuff to be initialized.....
thanks again for all the help
cheers
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Hello ,
I am rohit,and I am working on a project where we are receiving sms from mobile phone to our vc++ window, but the problem is that we dont know how to flush output buffers .
The result comes correct for first time but for the next time it is wrong.
After reastarting the computer and executing the program again the answer is correct ..
I also need help on some functions like -GetInputLen()
-GetInput() etc.
So plz help me its very urgent..
|
|
|
|
|
You need to provide a little more information. Which output buffers are you trying to flush? Are the functions GetInputLen() and GetInput part of some SMS-related API?
Software Zen: delete this;
|
|
|
|
|
Thanks Gary,
Well I have connected a mobile phone to serial port 'com1' and am communicating with that mobile phone using 'AT' commands.When I send any AT command to that port using ToCommPort()
functio the mobile should respond with O.K. The problem is that since the buffer is not cleared ,I have to restart the P.C in order to get the correct output i.e. O.K.
The functions GetInput() and GetInputLen() are related to the serial port comm1..
regards
Rohit Deshpande-
atotalgeek@gmail.com
|
|
|
|
|
Thanks Gary,
Well I have connected a mobile phone to serial port 'com1' and am communicating with that mobile phone using 'AT' commands.When I send any AT command to that port using ToCommPort()
functio the mobile should respond with O.K. The problem is that since the buffer is not cleared ,I have to restart the P.C in order to get the correct output i.e. O.K.
The functions GetInput() and GetInputLen() are related to the serial port comm1..
regards
Rohit Deshpande-
atotalgeek@gmail.com
Rohit Deshpande-
atotalgeek@gmail.com
|
|
|
|
|
I want to develop a bot plugin to Windows Messenger (not MSN Messenger!). Where do I find more info on how to go about this? Anyone know of a open source or a free tool w/source for a Messenger plugin? TIA.
|
|
|
|
|
Hello Friends,
Can any tell what is the difference between "Virutal Inheritance and Multiple Inheritance" in C++. And what are the situation in which the virutal inheritance and multiple inheritance used in c++ programs.
Hoping for a reply.
Best Regards,
Phijo
|
|
|
|
|
virtual inheritance is tricky.
consider class A to be a parent class. also consider A has a member int i;
then class B and class C inherites class A.
then class D inherties both B and C (multiple inheritance)
now if you create an object from D, C and B will be created in memory causing class A to be created in memory twice!!!???? (1 for B and 1 for C)
to avoid that we use the virtual inheritance.
multiple inheritance simply allow us to inherite from several classes....
hope that helped you...
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
|
(thumps forehead; forgot the look-in-the-faq thing again)
Software Zen: delete this;
|
|
|
|
|
'Multiple inheritance' means that a class is derived from more than one base class. For example, you could have the following:
class Boy {
public:
virtual void Walk();
void Speak();
int Age;
};
class Girl {
public:
virtual void Walk();
void Speak();
int Age;
};
class Infant {
virtual void Walk();
void Speak();
};
class MaleChild : public Boy, Infant {
public:
virtual void Walk();
void Speak();
}; The MaleChild class has two base classes, Boy and Infant . This means that an object of the MaleChild class is both a Boy and an Infant .
In simple terms, the 'virtual' mechanism lets you refer to an object through a base class pointer and actually call derived class methods. Using the classes in my earlier example, suppose we have the following:
MaleChild mc1;
Boy *boy1 = &mc1;
boy1->Walk();
boy1->Speak(); The statement boy1->Walk(); calls the Walk() function implemented by the MaleChild class through virtual inheritance. Walk() functions in the derived class 'override' those in the base class.
The statement boy1->Speak(); , on the other hand, calls the Speak() function directly in the Boy class.
This lets you define a behavior in a base class, and then alter that behavior in a derived class. For example, we could have the following implementation of the above classes:
void Boy::Walk()
{
cout << "I am a boy; "
}
void MaleChild::Walk()
{
Boy::Walk();
if (Age < 1) cout << "I can not walk; I am too young.";
else cout << "I am walking.";
} Assume the Age member is set to 0. If you call Walk() as follows:
MaleChild mc1;
Boy *boy1 = &mc1;
boy1->Walk(); you will see "I am a boy; I can not walk; I am too young." displayed. The boy1->Walk(); actually calls the MaleChild::Walk function through the virtual mechanism. The implementation of the MaleChild::Walk function calls the base class implementation to get the 'default' behavior (displaying "I am a boy; "), and then alters that behavior by displaying a message based on the value of the Age member.
Multiple inheritance is useful when you want to combine the behaviors of two types of objects. In our example, we are combining the behaviors of the Boy class and the Infant class to create a MaleChild class. Virtual inheritance is useful when you want to customize the behavior of a class.
Software Zen: delete this;
|
|
|
|
|
Hi,
I've noticed that the dialog-box programs I write using Visual C++ studio exit when the escape key is pressed. Does anyone know how I can stop this.
Thanks - Gary.
|
|
|
|
|
You need to override the OnCancel function, and remove the call to CDialog::OnCancel.
|
|
|
|
|
Thanks alot! That's worked! - Gary.
|
|
|
|
|
|
Hi All,
I have an arbitrarily large block of binary data (a sequence of bytes). I want to write a function:
int FindBit(BYTE* fisrtByte, int numBytes)
that can be passed a pointer to the start of the data (firstByte), and the number of bytes of data (numBytes), and find the first occurrence of a "1" bit. e.g., if I pass a pointer to the following 3 bytes of binary data:
00001101 10110101 10110101
I need the function to return 5 - because the first non-zero bit is in position 5.
Has anyone ever done something similar?
Is there an efficient way to do this ?
Thanks,
Neil Humphreys.
|
|
|
|
|
Hi,
This would work.
int FindBit(BYTE* firstByte, int numBytes){
int pos = 0;
int index = 0;
BYTE current_bit = 1 << 8;
while(index != numBytes){
if((firstByte[index] & current_bit) != 0)
break;
pos++;
current_bit = current_bit >> 1;
if(current_bit == 0){
current_bit = 1 << 8;
index++;
}
}
return pos;
}
NOTE: With your example, 00001101 10110101 10110101, this function would return a 4, because the count starts from zero. So if you want the count to start at 1, you'd have to add a 1 to the return value.
|
|
|
|
|
Sorry, I've corrected some things.
int FindBit(BYTE* firstByte, int numBytes){
int pos = 0;
int index = 0;
BYTE current_bit = 1 << 7;
while(index != numBytes){
if((firstByte[index] & current_bit) != 0)
break;
pos++;
current_bit = current_bit >> 1;
if(current_bit == 0){
current_bit = 1 << 7;
index++;
}
}
return pos;
}
NOTE: With your example, 00001101 10110101 10110101, this function would return a 4, because the count starts from zero. So if you want the count to start at 1, you'd have to add a 1 to the return value.
|
|
|
|
|
Hmmm. Just for fun, here's a slightly different approach:
int FindBit(BYTE *firstByte,int numBytes)
{
int result = -1;
int index = 0;
while ((index < numBytes) &&
(firstByte[index] == 0)) {
index++;
}
if (index < numBytes) {
result = index * 8;
BYTE mask = 0x01;
while ((firstByte[index] & mask) == 0) {
mask <<= 1;
result++;
}
}
return result;
} My version of FindBit returns -1 in case there are no 1 bits. Also note that I'm assuming 'Intel' byte/bit ordering.
Software Zen: delete this;
|
|
|
|