|
Try removing the #ifdef _UNICODE .... #endif block
-Prakash
|
|
|
|
|
Brilliant! That did it.... Thanks
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
We use a combination of malloc() and the new operator in our VC++ programs. How can we get a summary of either or both items total memory allocation? The heap walker stuff doesn't seem to do anything unless you use those dinosaur LocalAlloc() / GlobalAlloc() calls which are not portable to Unix.
thanks for any help
|
|
|
|
|
|
Another method would be to use "Performance Counters" on that process. I believe there may be a few other APIs that get various information as well.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Thanks Toby! There's still too much instrumentation for our simple needs. Here is what made the boss happy:
C:\Temp>printmemorystats.exe
total used 5054, free 760
OK - end of heap
total used 10174, free 3816
OK - end of heap
total used 12222, free 1760
OK - end of heap
total used 16318, free 5848
OK - end of heap
total used 24510, free 9936
OK - end of heap
total used 40894, free 14024
OK - end of heap
total used 73662, free 22128
OK - end of heap
total used 139198, free 26216
OK - end of heap
total used 270270, free 30304
OK - end of heap
total used 532414, free 34392
OK - end of heap
<code>#include <malloc.h>
#include <stdio.h>
static void PrintMemoryStats();
int main()
{
int sizemem=1024;
int ii;
char *foo;
for (ii=0; ii<10; ii++) {
PrintMemoryStats();
foo = malloc(sizemem);
sizemem *= 2;
}
}
static void PrintMemoryStats()
{
_HEAPINFO hinfo;
int heapstatus;
long totalUsed = 0, totalFree = 0;
hinfo._pentry = NULL;
while( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK )
{
if (hinfo._useflag == _USEDENTRY)
totalUsed += hinfo._size;
else if (hinfo._useflag == _FREEENTRY)
totalFree += hinfo._size;
}
printf ("total used %ld, free %ld\n", totalUsed, totalFree);
switch( heapstatus )
{
case _HEAPEMPTY:
printf( "OK - empty heap\n" );
break;
case _HEAPEND:
printf( "OK - end of heap\n" );
break;
case _HEAPBADPTR:
printf( "ERROR - bad pointer to heap\n" );
break;
case _HEAPBADBEGIN:
printf( "ERROR - bad start of heap\n" );
break;
case _HEAPBADNODE:
printf( "ERROR - bad node in heap\n" );
break;
}
}
</code>
-- modified at 15:25 Friday 27th January, 2006</code>
|
|
|
|
|
See if this helps.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
I need to make a combobox by which user can choose color they want. what kind of method can I use?
thanks.
|
|
|
|
|
|
Although it's not a combobox, there's also MFC's CColorDialog class.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Help!
Does anybody know the code on the web page, mentioned below? It should make working with ListControls much easier.
I added the code to my project, and made the changements in the code as described. I am using a dialog-based application. To make it work, do I have to create a dialog, which is equal to the one, which is shown in the example? Or should it work for every dialog using a ListBox?
Thanks!
-- modified at 10:49 Friday 27th January, 2006
|
|
|
|
|
Try posting your questions on the message board for that article - you'll probably get better help there (as the article author will get your question emailed to him)
--
Help me! I'm turning into a grapefruit!
Buzzwords!
|
|
|
|
|
class A
{
public :
virtual void foo() { } ;
};
class B : public virtual A
{
public :
virtual void foo() { } ;
};
class C : public virtual A
{
public :
virtual void foo() { } ;
};
class D : public B , public C
{
public :
} ;
say somewhere in code
D *ptr ;
..
....
ptr->Foo()
whose copy of Foo() will i call ? Will it be B's copy as it is the first inherited class during declaration from left to right ?
|
|
|
|
|
act_x wrote: whose copy of Foo() will i call ?
Why not just try it and see?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
I don't know, and I always try not to do that kind of multiple inheritance; and having a common base class worsen it.
I think that the
the way ( i think ) to resolve ambiguity, is to explicitly call the method :
ptr->B::food();
ptr->C::food();
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
act_x wrote: whose copy of Foo() will i call ?
None. The code will not even compile.
And adding virtual keyword to B and C classes does not have a sense in this case as the existance of class A.
Try compiling next code, it will not compile also :
#include "stdafx.h"
#include <iostream>
using namespace std;
class B
{
public :
virtual void foo() { } ;
};
class C
{
public :
virtual void foo() { } ;
};
class D : public B , public C
{
public :
} ;
int _tmain(int argc, _TCHAR* argv[])
{
D *ptr = new D ;
ptr->foo();
delete ptr;
return 0;
}
Adding virtual keyword assures that D will inherit just one copy of members of A.
Consider we have next code :
#include "stdafx.h"
#include <iostream>
using namespace std;
class A
{
public :
virtual void GetX() { cout<<X; } ;
int X;
};
class B : public virtual A
{
public :
void setXB() {X = 20;}
};
class C : public virtual A
{
public :
void setXC() {X = 30;}
};
class D : public B , public C
{
public :
} ;
int _tmain(int argc, _TCHAR* argv[])
{
D *p = new D();
p->setXC();
p->setXB();
p->GetX();
delete p;
return 0;
}
PS. By adding virtual keyword to B and C classes we are sure that B and C " share same instance of class A ".
Therefore output will be 20.
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
-- modified at 14:06 Friday 27th January, 2006
|
|
|
|
|
I have a 2 dimensional array created with the new operater,
int (*treeinbunch)[1000][20];
treeinbunch = new int [1000][1000][20];
that works fine throughout the program. When I try to pass it to a function to retrieve values from it, it doesn't work.
The function call uses this: function(int piece[1000][20]) and compiles fine, but
the values of piece in the function are garbage. If I replace piece in the function with *treeinbunch[index][index] it works fine. Why isn't piece initialized with the values of treeinbunch? How do I pass the array treeinbunch without losing its values?
Fleetmanager gone wrong
-- modified at 11:11 Friday 27th January, 2006
|
|
|
|
|
fleetmanager wrote: If I replace piece in the function with *treeinbunch[index][index] it works fine...How do I pass the array treeinbunch without losing its values?
Aren't these two contradictory? Are you still losing values with the modified function signature?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
m_bAutoMenuEnable is member of CFrameWnd.
how to Auto Enable Menu for dialog similar to CFrameWnd?
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
|
|
|
|
|
as far as I know, in dialogs, there is no ON_UPDATE_COMMAND_UI equivalent, you need to handle all of them manually.
( but I might be wrong ).
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
If 2 users use the smae software (liencense count = 1) at same time, so it is illegal.
my question is:
How to monitor users who are illegal.
E.g. one idea may be:
when user installs my software, my software sends user info(i.e. computer name) to me, I record it.
so second user can not install again.
when user uninstalls, I remove the record, so second user can install.
but how to record user info? because my site uses mysql database, which requires pre-allowed ip address, so my software can not access mysql database from user's computer.
any comments for this idea, or any other comments?
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
|
|
|
|
|
includeh10 wrote: E.g. one idea may be:
when user installs my software, my software sends user info(i.e. computer name) to me, I record it.
This makes the big assumption that the computer has Internet or e-mail.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
personally, I would be pissed if I cannot install a software if someone else already installed it.
running it is another matter.
There is no way to prevent malicious users to run and install multiple copies of a software on more than one machine; either with licensing servers, hardware keys, passwords, registration, ... It just makes it harder, but not impossible.
one software I use has the following scheme, it ships with a serial number, the serial is used to register on their site, once it's done, they send back a full ( and bigger ) license key that will be used to unlock the software; the company allows the SW to be run ( as full versions ) on 2 different computers, and will check when you submit a second time ( or more ) the serial key; and will not send back the full key if the 2 hardware are used. The company also let you "unregister" hardware, but it's more complicated, you have to contact them personally ( i think, I never did it )
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
#include <stdafx.h>
#include <stdlib.h> //contains random number generator rand()
#include <iostream.h>
#include <process.h> //contains system() and exit syntax
#include <time.h> //contains time seed for random generation
//==========================================================================================
// Function Prototype and global variables
void StartPage(); //Introduction of the game.
bool Playgame(int option); //Ask player to play game or not.
void Reset(char* &p_table); //Reset and generate the puzzle.
void Random(int& holeidx); //Random the puzzle.
void Drawtable(char *p_table); //Draw and display the puzzle.
void Move(int& holeidx,int move); //Moving the hole.
int Correct(int a); //Checking and comparing the puzzle with the answer
int size=0; //The size of the puzzle.
char Answer[26]; //The Answer array.
char* pAns = Answer; //The pointer of the Answer array.
char Temp[26]; //The temporary array to store the playing puzzle
char* pTemp = Temp; //The pointer of the temporary array
int holeidx; //The index number of the "hole" in the array
//==========================================================================================
//Main Program.
void main(){
StartPage(); //Display the instruction to player
Playgame(1); //For 1, ask the player to start game or not
do{ //Control the main flow of this game.
int input; //The input of player movement
int count=0; //The counter of number of moves.
do{ //Restrict the player to select the puzzle size between 2-5
cout << "\nPlese enter the puzzle size! (2-5):\t";
cin >> size;
if(size<2)
cout << "How can you play without any puzzle? Please re-enter";
if(size>5)
cout << "Sorry! It is too large to play! Please re-enter";
}while(size<2 || size >5);
Reset(pAns); //Generate the Answer array with selected size
Reset(pTemp); //Generate the temporary array of playing puzzle with selected size
Random(holeidx); //Generate the temporary array in random order
system ("cls");
do{ //Display the main screen of the game and movement.
system("cls");
cout << "Selected puzzle sizes: " << size;
cout << "\n\nThe target answer is:\n\n\n";
Drawtable(pAns); //Draw and display the Answer puzzle
cout << "\n\nPlease rearrange the following puzzle into correct order!\n\n\n";
Drawtable(pTemp); //Draw and display the playing puzzle
cout << "\n\n" << count++ << " moves so far.\n"; //After each movement, the do while loop will run once.
//Thus we can use count++ to count the number of moves.
Correct(1); //Check how many correct puzzle
cout << " correct puzzles so far <";
Correct(0); //Check and display the corrected letters.
cout << " >\n";
cout << "Which direction to move? (1-9) Press \"q\" to quit: ";
if(Correct(2)!=1){ //If the player still not win the game,
cin.ignore(255,'\n'); //ask and input the way to move the hole.
input = cin.get(); //else if the player win the game, end game
Move(holeidx,input);
}
else{
cout << "\n\nCongratulation! You WIN the game in " << count-1 << " moves.\n\n\a";
break;
}
}while(input!=113);
}while(Playgame(2)!=false); //For 2, Ask to play the game again or not.
}
//==========================================================================================
// StartPage Function:
void StartPage(){
//Show the instructions here
}
//==========================================================================================
//Play Game Function
bool Playgame(int option){
int reply;
return reply;
}
//==========================================================================================
// Reset and generate the puzzle.
void Reset(char* &p_table){
for(int i=0;i<(size*size);i++){
*(p_table + i) = 65 +i; //Generate the array by using ACSII code with selected size
*(p_table +(size*size)-1)=32; //Replace the last element with the hole by using the Space (with ACSII code 32)
}
}
//=========================================================================================
//Ramdom the puzzle
void Random(int& holeidx){
srand(time(0));
int index=0; //The array index random by rand()
char temp; //A temporary variable for swapping
for(int x=0; x<(size*size); x++){ //Randomly pick up an index number of the Temp array.
index = rand()% (size*size); //When x =0, swap the random element with the first element
temp = *(pTemp + x); //When x =1, swap the random element with the second element
*(pTemp + x) = *(pTemp+index); //....etc.
*(pTemp+index) = temp;
}
for(int y=0;y<(size*size);y++){
if(*(pTemp+y)==32) //Locate the index number of the hole.
holeidx=y;
}
}
//=========================================================================================
//Draw and display the Table
void Drawtable(char *p_table){
int r=0; //r = row of the table
int c=0; //c = column of the table
for(r=0;r< size;r++){
for(c=0;c< size;c++)
cout << " | " << *(p_table +(r*size+c)); //Calculate the location of the
cout << " | " << "\n"; //element in a size*size table
}
}
//=========================================================================================
//Moving the hole.
void Move(int& holeidx,int move){
int tar_row; //The row of the target element
int tar_col; //The column of the target element
int hrow; //The row of the hole
int hcol; //The column of the hole
int temp=0; //A temporary variable for swapping
int number; //The index number of the target element
hrow = holeidx / size; //Calculate the row number of the hole
hcol = holeidx % size; //Calculate the column number of the hole
switch(move){
case 49: //(Press 1)
break;
case 50: //(Press 2)
break;
case 51: //(Press 3)
break;
case 52: //(Press 4)
break;
case 53: //(Press 5)
break;
case 54: //(Press 6)
break;
case 55: //(Press 7)
break;
case 56: //(Press 8)
break;
case 57: //(Press 9)
break;
case 113: //(Press q)
case 81: //(Press Q)
exit(1); //If Press Q to quit, exit the game directly.
break;
default:
break;
}
//Check if moving the hole outside the puzzle or not.
//If not, calculate the index of the target element.
//Swapping the hole and the target element.
//If moving outside the puzzle,
//display warning
}
//=========================================================================================
//Checking and comparing the puzzle with the answer
int Correct(int a){
int count=0; //count the number of correct letters
int target=0; //check if the player win the game or not.
return target;
}
|
|
|
|
|
What's all this code for? Are you expecting someone to wade through it all?
Joe Friday: "Just the facts, ma'am."
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|