|
What text ?
Displayed where ? How ?
Windows Application ?
Unix Application ?
Mac Application ?
Console Application ?
Say More and Answers will follow !!!
Max.
|
|
|
|
|
I have an object say myObject of some class. I do stuff with it after doing
MyObject myObject
Then after I'm done I say
myObject = NULL;
Now if I want to use myObject after this point, do I do all over again:
MyObject myObject
or can I just go ahead and do:
myOBject.Something(); without redeclaring it?
Appreciate your help,
ns
|
|
|
|
|
First this do look like CSharp, but the capital letters on NULL indicates c++.
If indeed it is c++, then you cannot assign NULL to myObject, since it is not a pointer (On the stack);
You cannot redeclare the object. If the compiler doesn't complain, then it is because there is another stack-frame.
If you want a new object, this is how you do.
first declare myObject as a pointer:
MYObject* pMyObject = NULL;
then create an instance of it:
pMyObject = new MyObject();
then delete it:
delete pMyObject;
change all the dots to reference operator:
{.} to {->}
|
|
|
|
|
You can have as many new, and delete pairs as you like.
and yes, you need to have all the calls to the object in between these operators.
GOOD LUCK!
|
|
|
|
|
no!
ns wrote:
MyObject myObject
is not a pointer ! it's on the stack. memory will be release when the declaration gets out of scope.
ns wrote:
myObject = NULL;
Should give you a compilation error/warning.
If the object is declared on the stack ( like you did ), it will be constructed when it's declared, and deconstructed when it's going out of scope. you don't have to explicitly delete it.
If the object is on the heap :
MyObject* myObject = NULL;
myObject = new MyObject;
you can delete it :
delete myObject;
myObject = NULL;
if you want to re-use it, you will need to re-new it.
Max.
|
|
|
|
|
Okay. Very good explanation. I was mistaken that I thought I saw an object being set to NULL. It had to have been a pointer like you said. Many thanks for clarifying this...
Appreciate your help,
ns
|
|
|
|
|
You may have seen a smart pointer which made you think this. A smart pointer is a class which wraps and controls a pointer, and often setting a smart pointer to NULL internally deletes the pointer and therefore does what you were after.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Precisely. This was happening with things like _RecordsetPtr which didnt have the * associated with pointers so I mistakenly thought they were actual objects, which they actually are, except they are pointer-objects.....something like that. Anyways that was exactly where I was swimming in confusion...you hit it right on the head!
Appreciate your help,
ns
|
|
|
|
|
I want to get the keyboard message from my application My application include some dialogs and forms
Thanks!
|
|
|
|
|
What sort of application is it, does it use MFC ? You ultimately want to catch WM_KEYDOWN, WM_KEYUP or WM_CHAR. You don't need MFC for this, but the class wizard will do it for you for free if you're using MFC.
You catch the message per window, not for the whole app.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Thanks!
Yes,My application use MFC.
I am coding for a class,I want to get the keyboard message if every application include this class.
Maybe I will try Keyboard Input API?
|
|
|
|
|
No, it does not work that way. Each MFC class that represents a window ( like CMainFrame, CDialog, CView ) has a message map, and you need to catch the message in those. Ctrl-W will bring up the class wizard, you can choose a class and a message from there and it will plumb it all in for you.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
I used the hook dll in my application,but it get all ketboard messages(include other application's messages).Can I only get the messages from my application use the hook dll?
Thx!
|
|
|
|
|
Why would you want to do that when I've provided a far easier solution ?
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Our application has so much dialogs and forms ,it's difficult to monitor the message in every dialog,and my boss need a common class or dll to monitor our application and other applications.
|
|
|
|
|
I'm not sure how the messages bubble, but you should be able to get all dialogs to send the message to their parent, and then handle them all in the one spot. It's a lot nicer than a global hook, that's just a hack.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Hi,
I am using MSVC 6.0. I activated the /3GB switch in Windows XP Professional and also used a linker flag /LARGEADDRESSAWARE in the application in order to enable the application to address more than 2GB of memory.
The GlobalMemoryStatus reported dwTotalVirtual = 3221094400 and dwAvailVirtual = 3203072000. It seems that the above configuration works.
However, when I do a VirtualAlloc(NULL, 2*1024*1024*1024, MEM_COMMIT, PAGE_READWRITE) to allocate 2GB of memory, I always get a "ERROR_NOT_ENOUGH_MEMORY"?
How can I allocate those available virtual memory?
Thank you.
|
|
|
|
|
I am not sure you are making the right use of this "feature".
There's a difference between be able to allocate a TOTAL of more than 2GB, and be able to allocate a single block of more than 2GB.
The use of the VirtualAlloc API is subordonated to the use of the /PAE flag, not /3GB. There is no special API to use along with /3GB, since it just orders the system to leave under 1GB instead of 2.
The book "windows 2000 programming" explains how to use it. I guess that if you are doing this in a real world case, then you certainly can have more direct MS support for that topic.
Besides that, have you more than 2GB free disk space available (configured disk swapping) ?
How low can you go ? (MS retrofuck)
|
|
|
|
|
Thank you for replying.
I also suspect that VirtualAlloc API might not be able to allocate a single block of more than 2GB. Can we play around with /PAE flag to make it allocate more memory?
Do you mean that the book "Windows 2000 Programming" gives some method on how we can allocate a block of more than 2GB? Who is the author of the book? I need the memory for a Finite Element Analysis software.
I do have more than 2GB free disk space available.
|
|
|
|
|
tsk wrote:
I also suspect that VirtualAlloc API might not be able to allocate a single block of more than 2GB
That's what I have told you. You can allocate the amount of memory you want per process (with a limit of 3GB with /3GB and up to 64GB with /PAE) by chunks, not by a single call.
How this works is explained in the book mentioned. It's from MSPRESS[^].
Never forget Windows is a 32-bit OS, thus cannot address pointers more than 4GB large. And because the kernel takes 2GB of these addresses (without /3GB), that's why you have at most 2GB per process. A lot of problems here because the most significant bit of pointers is 1 and becomes negative (comparisons may fail).
To break the 4GB barrier, Windows, through VirtualAlloc and the /PAE allows you to use pages of memory (with is an old technique). Of course, this constraints the whole design of your program.
tsk wrote:
how we can allocate a block of more than 2GB?
Although that's unlikely, you'll need a horsepower OS, such like MS datacenter (with 4GB or 16GB of physical memory on-board) : again, if you are in a real world case, your company should by this time already be in contact with MS reps.
How low can you go ? (enculage MS)
|
|
|
|
|
Thanks Stephane Rodriguez. I might need to use other alternative such as divide and conquer to solve the equations.
Contact MS reps for what?
|
|
|
|
|
Hi,
I'm running Ms Word Automated... meanwhile I do a lengthy
operation I show an "Please Wait" window..., but the user can click on word and mess up the document ( ).
What I'm thinking... what happens if I set the parent of my "Please Wait" window as the window handle of the WinWord instance ?, Is that possible ? Could block the message pump of Ms Word ?
Thanks in advance, greetings
Braulio
|
|
|
|
|
I'd try to disable main MS Word window using Word's automation model. I don't have the reference at hand, but I believe there should be some property or method for that.
Tomasz Sowinski -- http://www.shooltz.com
*** Purgamentum init, exit purgamentum ***
|
|
|
|
|
There are two alternatives: IIRC, Word automation has an option for hiding the interface.
The other works only in WinNT/2k/XP but serves to any program, is using CreateDesktop to create a second, hidden desktop and opening the program there.
Q261186 - Computer Randomly Plays Classical Music
|
|
|
|
|
Application.Visible = True/False
How low can you go ? (MS retrofuck)
|
|
|
|