|
You should allocate one more byte for '\0' char.
TCHAR* buffer = new TCHAR[1025];
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
If your pFile->Read call reads 1024 TCHAR 's, then ret has the value 1024. The line buffer[ret] = TEXT('\0'); will then overrun the end of buffer .
Software Zen: delete this;
|
|
|
|
|
when you see the content of a variable of type HWND in Watch, you see something like this: 0x00040222 {unused=???}
what is "unused"?
is HWND a class?
|
|
|
|
|
Hello,
HWND is a handle to an object managed by the OS. This means that you have no definition of the object, nor how it is implemented. This means that the object can be anything, an instance of a class, a normal struct, string, etc..
The reason why the watch has no information about the object, is because it doesn't know what to do with the handle, it doesn't know its type (handles are void* pointers). For that reason, { unused=??? } appears in the watch.
Hope this helps.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
|
typedef void *HANDLE;
#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
DECLARE_HANDLE(HWND)
HWND it`s a Smart Pointer who points into a windows table(matrix) of HWND`s(windows) ...
NG
-- modified at 8:05 Monday 5th September, 2005
|
|
|
|
|
Dear friends,
I'm facing with a problem with templates.I'm including all my code at end.The sole purpose of my program is that to use heap algorithm which will take template parameter like this
MaxHeap<array<string> > m(10);
m.initilize(a,10,10);
where String is self created class which will work same as string class and Array class main function is to use indexing starting with 1 rather than zero. The problem is that in the following line
if((c<currentsize) &&="" (heap[c]<heap[c+1]))
="" c++;
as="" my="" knoweledge="" goes="" in="" accordance="" with="" operator="" precedence="" heap[c]="" is="" worked="" out([]="" over="" loaded="" array="" class)="" and="" as="" you="" see="" the="" code="" it="" returns="" string="" object,="" according="" to="" following="" class.as="" class="" instatiated="" array<string="">, then template must do the same.The same will happen with heap[c+1] and finally < must operate on two String classes objects and < overload operator must operate and returns the int value which is furhter evaluated. But I'm getting compilation errors like this.
T& operator[](int i)
{
return data[i-1];
}
I couldnt understand why Array<class bhadram1:string=""> is transferring while comparision because in precedence it is low.I couldnt understand what is happening and i want to clear about templates. Please help me in this aspect.
compilation errors:
:\cpppractice\sep3\heap1.h(72) : error C2039: 'getPointer' : is not a member of 'Array<class bhadram1::string="">'
d:\cpppractice\sep3\heap1.h(115) : see reference to function template instantiation 'int __cdecl bhadram1::operator <(class bhadram1::Array<class bhadram1::string=""> &,class bhadram1::Array<class bhadram1::string=""> &)' being compiled
d:\cpppractice\sep3\heap1.h(72) : error C2039: 'getPointer' : is not a member of 'Array<class bhadram1::string="">'
d:\cpppractice\sep3\heap1.h(115) : see reference to function template instantiation 'int __cdecl bhadram1::operator <(class bhadram1::Array<class bhadram1::string=""> &,class bhadram1::Array<class bhadram1::string=""> &)' being compiled
d:\cpppractice\sep3\heap1.h(65) : error C2039: 'getPointer' : is not a member of 'Array<class bhadram1::string="">'
d:\cpppractice\sep3\heap1.h(117) : see reference to function template instantiation 'int __cdecl bhadram1::operator >=(class bhadram1::Array<class bhadram1::string=""> &,class bhadram1::Array<class bhadram1::string=""> &)' being compiled
d:\cpppractice\sep3\heap1.h(65) : error C2039: 'getPointer' : is not a member of 'Array<class bhadram1::string="">'
d:\cpppractice\sep3\heap1.h(117) : see reference to function template instantiation 'int __cdecl bhadram1::operator >=(class bhadram1::Array<class bhadram1::string=""> &,class bhadram1::Array<class bhadram1::string=""> &)' being compiled
Error executing cl.exe.
heap.obj - 4 error(s), 0 warning(s)
# include <iostream>
# include <heap1.h>
# include <string1.h>
using namespace std;
using namespace bhadram1;
int main()
{
int array[10]={20,12,35,15,10,80,30,17,2,1};
String str[10]={"first","second","third","fourth","fifth","sixth","seventh","eight","nine","ten"};
Array<string> a(str,10);
MaxHeap<array<string> > m(10);
m.initilize(a,10,10);
//m.print();
return 0;
}
Heap1.h file:
# include <iostream>
using namespace std;
namespace bhadram1
{
template<class t="">
class Array
{
//friend ostream& operator<<(ostream& ostr,String& s);
protected:
int size;
T* data;
public:
Array()
{
size=1;
data=new T[1];
}
Array(int n)
{
size=n;
data=new T[size];
}
Array(T* a,int const s)
{
size=s;
data=new T[size];
for(int i=0;i<s;i++)
{
="" data[i]="a[i];
" cout<<data[i]<<endl;
="" }
="" array(array<t="">& a)
{
size=a.size;
//delete[] data;
data=new T[size];
for(int i=0;i<size;i++)
{
="" data[i]="a.data[i];
" }
="" t&="" operator[](int="" i)
="" return="" data[i-1];
="" operator="(T&" a)
="" a;
="" friend="" ostream&="" operator<<(ostream&="" ostr,t&="" a);
="" int="" operator<(t&="" a1,t&="" a2);
="">=(T& a1,T& a2);
};
template<class t="">
int operator>=(T& a1,T& a2)
{
return (strcmp(a1.getPointer(),a2.getPointer()>=0));
}
template<class t="">
int operator<(T& a1,T& a2)
{
return (strcmp(a1.getPointer(),a2.getPointer()<0));
}
template<class t="">
ostream& operator<<(ostream& ostr,T& a)
{
return ostr<<a;
}
template<class t="">
class MaxHeap
{
private:
int currentSize,maxSize;
T* heap;
public:
MaxHeap(int n)
{
currentSize=n;
heap=new T[n];
}
void initilize(T a,int size,int arraySize)
{
for(int j=1;j<=10;j++)
{
heap[j]=a[j];
cout<<heap[j];
}
="" currentsize="size;
" maxsize="arraySize;
" for(int="" i="currentSize/2;i">=1;i--)
{
T y=heap[i];
//cout<<"a "<<a[i]<<" y="" "<<y;
="" int="" c="2*(i);
" cout<<"c="" "<<c<<"="" current="" "<<currentsize<<endl;
="" while(c<="currentSize)
" {
="" cout<<"sub="" "<<c<<endl;
="" if((c<currentsize)="" &&="" (heap[c]<heap[c+1]))
="" c++;
="" if(y="">=heap[c])
break;
heap[c/2]=heap[c];
c*=2;
}
heap[c/2]=y;
}
for(i=1;i<=10;i++)
{
cout<<heap[i]<<endl;
}
=""
="" void="" print()
="" {
="" }
};
};
string1.h="" file:
using="" namespace="" std;
namespace="" bhadram1
{
class="" string
{
private:
="" char*="" _string;
="" int="" _size;
public:
="" string(int="" n="0);
" string(string&="" s);
="" string(const="" );
="" string&="" operator="(String&" ch);
="" friend="" ostream&="" operator<<(ostream&="" ostr,string&="" string="" operator+(string&);
="" operator+(char*="" operator+="(String&" operator+(const="" c,string&="" char&="" operator[](int="" n);
="" operator<(string&="">(String& s);
String& operator[](int n);
char* getPointer();
};
char* String::getPointer()
{
return _string;
}
String& String::operator =(char* ch)
{
int _size=strlen(ch);
_string=new char[_size+1];
for(int i=0;i<_size;i++)
{
_string[i]=*ch++;
}
_string[i]='\0';
return *this;
}
String& String::operator[](int n)
{
return *this;
}
int String::operator<(String& s)
{
return (strcmp(_string,s._string)<0);
}
int String::operator >(String& s)
{
return (strcmp(s._string,_string)>0);
}
/*char& String::operator [](int n)
{
return _string[n];
}*/
String operator+(const char* c,String& s)
{
String temp;
temp._size=strlen(c)+s._size;
strcpy(temp._string,c);
strcat(temp._string,s._string);
return temp;
}
String String::operator +(char* c)
{
String temp;
temp._size=_size+strlen(c);
strcpy(temp._string,_string);
strcat(temp._string,c);
return temp;
}
String& String::operator +=(String& s)
{
String temp;
temp._size=_size+s._size;
strcpy(temp._string,_string);
strcat(temp._string,s._string);
delete [] _string;
_size=temp._size;
_string=new char[temp._size+1];
strcpy(_string,temp._string);
return *this;
}
String String::operator+(String& s1)
{
String temp;
temp._size=_size+s1._size;
strcpy(temp._string,_string);
strcat(temp._string,s1._string);
return temp;
}
String& String::operator=(String& s)
{
_size=s._size;
delete [] _string;
_string=new char[_size+1];
for(int i=0;i<_size;i++)
_string[i]=s._string[i];
_string[i]='\0';
return *this;
}
String::String(int n)
{
_size=n;
_string=new char[_size+1];
for(int i=0;i<_size;i++)
_string[i]=' ';
_string[i]='\0';
}
String::String(String& s)
{
_size=s._size;
_string=new char[_size+1];
for(int i=0;i<_size;i++)
_string[i]=s._string[i];
_string[i]='\0';
}
String::String(const char* ch)
{
_size=strlen(ch);
_string=new char[_size+1];
for(int i=0;i<_size;i++)
_string[i]=*ch++;
_string[i]='\0';
}
ostream& operator<<(ostream& ostr,String& s)
{
return ostr<
|
|
|
|
|
Hey, can anybody tell me how to check whether Hotfixes are installed or not thru pgm in VC++(Win SDK) when value is specified???
thanks in advance
Supriya Tonape
|
|
|
|
|
Supriya Tonape wrote:
can anybody tell me how to check whether Hotfixes are installed or not thru pgm in VC++(Win SDK) when value is specified???
All the Installed application/hotfix can be found from this registry location :-
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Yeah Alok I knew it but U didnt get my ques. I wanted to check them thru my pgm, I might need to use "RegOpenKey()" n "RegEnumKey()" funcs.
I m trying it out. hope U got my point.bye for now.
Thanks n Regards,
Supriya Tonape
|
|
|
|
|
|
|
Thanks Alok and Ravi.
I solved my prob ))) as I told U b4 I used those functions.
Thanks for Ur help.
Regards,
Supriya Tonape
|
|
|
|
|
Ravi Bhavnani wrote:
Corrected link[^]
Thanks
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
int x;
for(i=1;i<=10;i++)
{
x=i;
cout<
|
|
|
|
|
in the second case, it may allocate memory on different places, but as it is the system which decides, x may have the same address many times...
in C/C++, a variable declared in a local scope is destroyed when the program gets out of that scope. here, it the case at each loop of the for...
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 6:11 Monday 5th September, 2005
|
|
|
|
|
Vivekuniq wrote:
int x;
for(i=1;i<=10;i++)
{
x=i;
cout<<x;
}< i="">
Here memory for variable X will allocated in Stack for entire LOOP duration
Vivekuniq wrote:
for(i=1;i<=10;i++)
{
int x;
x=i;
cout<<x;
}< i="">
Here the Memory of Variable X will allocated and deallocated in each cycle of loop!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Again both came for race greate. I like you both.
Nice talking to you.
|
|
|
|
|
G Haranadh wrote:
I like you both.
Thanks for liking Us
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
|
In the second case, variable i will still be on the stack. It's likely that it vill occupy the same memory address at every loop, since the stack doesn't change within the loop.
Or am I wrong?
|
|
|
|
|
kakan wrote:
It's likely that it vill occupy the same memory address at every loop, since the stack doesn't change within the loop.
purly depend on OS, AFAIK, Stack will be cleaned at every iteration!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Yes, the stack variables will be cleaned, that's true. But the variable i will be recreated for every iteration of the loop.
That's why i beleive that the variable i will occupy the same memory address of the stack for every iteration.
It's the compilers task to handle the stack, depending on calling convention etc., not the OS.
BTW, the stack isn't cleaned or allocated (except when the process/thread starts and exits). So i think 'cleaned' isn't very appropriate. Referenced/dereferenced is better, in my opinion.
Pls do correct me if I'm wrong.
|
|
|
|
|
kakan wrote:
Yes, the stack variables will be cleaned, that's true. But the variable i will be recreated for every iteration of the loop.
That's Whats I am saying...
kakan wrote:
It's the compilers task to handle the stack, depending on calling convention etc., not the OS.
yeah I know but Compiler doesn't allocate address to the stack. That the Work of OS, you can correct if i am wrong..
kakan wrote:
the stack isn't cleaned or allocated (except when the process/thread starts and exits).
But PUSH and POP happens, i.e. variable is push and pop into/from Stack.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
It could happen both situations ... It also depends on the memory usage of others threads.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|