|
I did it by adding the virtual functions to the base class. Just seems like a clunky solution.
Thx very much.
|
|
|
|
|
i ues string class in a Win32 Console Application(build by VC++ 6),here is the code and errors, how can i fix it?
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "Psapi.h"
#include <iostream.h>
#include <string>
using namespace std;
void PrintProcessNameAndID( DWORD processID )
{
string szProcessName;
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
int len = lstrlen(szProcessName);
GetModuleBaseName( hProcess, hMod, szProcessName,
len);
}
if(lstrcmp(szProcessName, "smss.exe"))
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
}
CloseHandle( hProcess );
}
int main(int argc, char* argv[])
{
...
return 0;
}
errors:
... : error C2664: 'lstrlenA' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
... : error C2664: 'GetModuleBaseNameA' : cannot convert parameter 3 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
... : error C2664: 'lstrcmpA' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
i 've tried ,then i have no regret
|
|
|
|
|
Trying using szProcessName.c_str() instead of only "szProcessName " in the functions 'lstrlenA' , 'GetModuleBaseNameA' and 'lstrcmpA' .
|
|
|
|
|
Thank u,Naveen.I did as u told me ,but comes a new error:
...:error C2664: 'GetModuleBaseNameA' : cannot convert parameter 3 from 'const char *' to 'char *'
how to do?
i 've tried ,then i have no regret
|
|
|
|
|
oh yea.. haha i must be looking like a fool now...
i fix it
thanks for yr help
i 've tried ,then i have no regret
|
|
|
|
|
hmm..
I modified you code a little.Just changed the szProcessName to TCHAR.
void PrintProcessNameAndID( DWORD processID )
{
TCHAR szProcessName[MAX_PATH];
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
MAX_PATH);
}
if(lstrcmp(szProcessName, "smss.exe"))
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
}
CloseHandle( hProcess );
}
|
|
|
|
|
thanks for ue help nave, but yr code still have a little problem
if(lstrcmp(szProcessName, "smss.exe"))
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
that is: function lstrcmp(lpstring1, lpstring2),when lpstring1 equals lpstring2,the return value is zero.so if i need only see "smss.exe" on the screen,i should change it like this
if(!lstrcmp(szProcessName, "smss.exe"))
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
i 've tried ,then i have no regret
|
|
|
|
|
CHYGO wrote: if(!lstrcmp(szProcessName, "smss.exe"))
lstrcmp() is not a boolean function so you should refrain from treating it as such:
if (lstrcmp(szProcessName.c_str(), "smss.exe") == 0)
... Also, since szProcessName is a string variable, why not just use:
if (szProcessName != "smss.exe")
...
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
What's the best way to reliable determine if a volume is online and ready for use?
Current I am using GetVolumeInformation to do this. My assumption is that.
Should I go a step further and read the root folder?
Just wondering if GetVolumeInformation can report something present that's not ready for access?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
I need to construct Rational numbers, but they have to be in the simplest form... Here's what I have.
Rational::Rational( int Num , int Den )
{
int A = Num;
int B = Den;
int temp;
while(B)
{
temp = B;
B = A%B;
A = temp;
}
if( A != 0 )
{
Numerator_ = Num/A;
Denominator_ = Den/A;
}
}
modified on Thursday, March 5, 2009 8:52 PM
|
|
|
|
|
What's your question exactly ?
|
|
|
|
|
We're always happy to see your achievements, now what is the question?
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]
|
|
|
|
|
Your Euclidean algorithm is correct. What's your concern?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
I'm looking for much better optimzed code for adding escape sequence than the below.
void appendSlash(const string& source, string& result)
{
for(unsigned int i = 0; i < source.length(); i++)
{
switch(source[i])
{
default:
result += source[i];
break;
case '"':
result += "\\\"";
break;
}
}
}
The switch-case in the current code is to handle more scenarios that might be added for implementing later.
Thanks in advance,
Regards,
Mayur M
|
|
|
|
|
You should use the infamous find and replace
string class (rather basic_string class) has a member function called find to find the character that you specify in your switch statement. After finding the character, use the replace member function to put in the escape sequence that you wish.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
What about PathAddBackslash() , or:
if (source.substr(source.length() - 1) != "\\")
source += '\\';
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Can someone please take a look at this class and tell me what I'm doing so terribly wrong. The compiler gives me an error I search around fix it and then another one pops up.
I will post my header file and my code...And if someone has a thought about how to overload the input operator that would help because i am lost on that one
#ifndef RATIONAL_
#define RATIONAL_
using namespace std;
#include <iostream>
class Rational
{
public:
Rational( int = 0, int = 1 );
Rational( const Rational& );
Rational& operator=( const Rational& );
int GCD();
void Simplify();
bool IsValid() const;
int Numerator() const;
int Denominator() const;
friend istream& operator>>( istream&, Rational& );
friend ostream& operator<<( ostream&, const Rational& );
private:
int Numerator_;
int Denominator_;
};
bool operator==( const Rational&, const Rational& );
bool operator!=( const Rational&, const Rational& );
bool operator< ( const Rational&, const Rational& );
bool operator<=( const Rational&, const Rational& );
bool operator> ( const Rational&, const Rational& );
bool operator>=( const Rational&, const Rational& );
Rational operator+( const Rational&, const Rational& );
Rational operator-( const Rational&, const Rational& );
Rational operator*( const Rational&, const Rational& );
Rational operator/( const Rational&, const Rational& );
#endif
</iostream>
using namespace std;
#include <iostream>
#include "proj06.rational.h"
Rational::Rational( int Num, int Den )
{
Numerator_ = Num;
if (Den <= 0)
{
Denominator_ = 1;
}
else
{
Denominator_ = Den;
}
}
Rational::Rational( const Rational& C )
{
Numerator_ = C.Numerator_;
Denominator_ = C.Denominator_;
}
Rational& Rational::operator=(const Rational& C )
{
Numerator_ = C.Numerator_;
Denominator_ = C.Denominator_;
return *this;
}
int Rational::GCD()
{
int A = Numerator_;
int B = Denominator_;
int Temp;
while(B)
{
Temp = B;
B = A%B;
A = Temp;
}
return A;
}
void Rational::Simplify()
{
int GCDNumber = GCD();
if(GCDNumber != 0)
{
Numerator_ = Numerator_/GCDNumber;
Denominator_ = Denominator_/GCDNumber;
}
}
bool Rational::IsValid() const
{
return ( Denominator_ != 0 );
}
int Rational::Numerator() const
{
return Numerator_;
}
int Rational::Denominator() const
{
return Denominator_;
}
bool operator==( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator() == B.Numerator() and A.Denominator()== B.Denominator());
}
bool operator!=( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator() != B.Numerator() and A.Denominator()!= B.Denominator());
}
bool operator<( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator()*B.Denominator())<(A.Denominator()*B.Numerator());
}
bool operator<=( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator()*B.Denominator())<=(A.Denominator()*B.Numerator());
}
bool operator>( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator()*B.Denominator())>(A.Denominator()*B.Numerator());
}
bool operator>=( const Rational& A, const Rational& B )
{
A.Simplify();
B.Simplify();
return(A.Numerator()*B.Denominator())>=(A.Denominator()*B.Numerator());
}
Rational operator+( const Rational& A, const Rational B )
{
int Num;
int Den;
Num = A.Numerator()*B.Denominator()+A.Denominator()*B.Numerator();
Den = A.Denominator()*B.Denominator();
Rational C(Num, Den);
return C.Simplify();
}
Rational operator-( const Rational& A, const Rational B )
{
int Num;
int Den;
Num = A.Numerator()*B.Denominator()-A.Denominator()*B.Numerator();
Den = A.Denominator()*B.Denominator();
Rational C(Num, Den);
return C.Simplify();
}
Rational operator*( const Rational& A, const Rational B )
{
int Num;
int Den;
Num = A.Numerator()*B.Numerator();
Den = A.Denominator()*B.Denominator();
Rational C(Num, Den);
return C.Simplify();
}
Rational operator/( const Rational& A, const Rational B )
{
int Num;
int Den;
Num = A.Numerator()*B.Denominator();
Den = A.Denominator()*B.Numerator();
Rational C(Num, Den);
return C.Simplify();
}
ostream& operator<<( ostream& Out, const Rational& Item )
{
Out << Item.Numerator() << "/" << Item.Denominator();
return Out;
}
</iostream>
|
|
|
|
|
what is the error you getting?
Yusuf
|
|
|
|
|
proj06.driver.cpp: In function 'int main()':
proj06.driver.cpp:38: warning: the address of 'Rational G()', will always evaluate as 'true'
proj06.rational.cpp: In function 'bool operator==(const Rational&, const Rational&)':
proj06.rational.cpp:150: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp:151: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp: In function 'bool operator!=(const Rational&, const Rational&)':
proj06.rational.cpp:167: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp:168: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp: In function 'bool operator<(const Rational&, const Rational&)':
proj06.rational.cpp:183: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp:184: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp: In function 'bool operator<=(const Rational&, const Rational&)':
proj06.rational.cpp:199: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp:200: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp: In function 'bool operator>(const Rational&, const Rational&)':
proj06.rational.cpp:216: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp:217: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp: In function 'bool operator>=(const Rational&, const Rational&)':
proj06.rational.cpp:232: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp:233: error: passing 'const Rational' as 'this' argument of 'void Rational::Simplify()' discards qualifiers
proj06.rational.cpp: In function 'Rational operator+(const Rational&, Rational)':
proj06.rational.cpp:255: error: conversion from 'void' to non-scalar type 'Rational' requested
proj06.rational.cpp: In function 'Rational operator-(const Rational&, Rational)':
proj06.rational.cpp:276: error: conversion from 'void' to non-scalar type 'Rational' requested
proj06.rational.cpp: In function 'Rational operator*(const Rational&, Rational)':
proj06.rational.cpp:296: error: conversion from 'void' to non-scalar type 'Rational' requested
proj06.rational.cpp: In function 'Rational operator/(const Rational&, Rational)':
proj06.rational.cpp:316: error: conversion from 'void' to non-scalar type 'Rational' requested
|
|
|
|
|
you are trying to modify const object. Your overloaded operator == takes const parameter
bool operator==( const Rational& A, const Rational& B )
but then you call Simplify which it tries to change the value of your const object.
Here is something that can walk you through const declaration [^] and another one [^] yet another one[^]
Yusuf
|
|
|
|
|
Well, what are the errors the compiler give you?
I've given it to my XCode compiler (on Mac OSX) and it give me errors with some methods (operators) that receive constant objects that you try to modify with "Simplify".
IMO, for comparator operators (== !=, ... ) you do not want to modify the input, so don't call Simplify.
Also, the Simplidy() method returns void, and you "return" this in a couple of methods.
This signature was proudly tested on animals.
|
|
|
|
|
Thanks for that i knew it was some dumb thing I was doing.
Any idea how to do the input operation I'm clueless on that one...
|
|
|
|
|
Hi,
I have a MFC application(Dialog) in unmanaged code in VC6. I needed to embed a Dot net control into the MFC dialog.
The Dot Net control can be a C# window form or a WPF control.
Please help with examples or links.
Thanks
|
|
|
|
|
|
Hi everyone.
I just downloaded EC++ 4.0 and i have been trying hard to make it run on my Windows XP.
First of all it did not open because apparently "No standard SDK was found on the desktop....".
So i downloaded the Standard SDK 5.O and installed it on my pc.
This time Ec++ did open and i was able to open a project.
However when i tried compiling the program another error message was displyed...
" The application targeting a standard SDK for Windows CE.net and built for the SH4 CPU cannot be run on the Emulator device. Inorder to run this application on any CPU other than the Emulator you will have to install an SDK that is compatible with the standard SDK for Windows CE.net, the target a shadow platform pertaining to that SDK.
Please see EVC documentation for more details."
Can anyone please help me with this....
PS: The application i have been trying to compile is a remote control application written in Ec++ for a pocket PC running Windows CE 3.0.
Thanks in advance...
|
|
|
|
|