|
Hi,
can anyone tell me how to avoid the stacking effect that occurs when I load toolbars at application startup? I want them to be aligned horizontally. Is this possible?
Also, when I programatically nuke a CControlBar when I close a document the background appears to remain. I've tried calling DestroyWindow() on the control bar before I delete it, but this does not work. What's the correct way to tidy things up?
Any help appreciated
thanks
matthew
|
|
|
|
|
I've noticed that sometime upon exiting my program, it errors out with a "memory could not be read". While debugging I see that my string buffers are not reseting themselves. How can I go about clearing my buffers out so that I do not get this error. Or am I looking in the wrong place. I still am curious as to how I go about resetting my buffers each time........
Please be patient with me as I am a cobol programmer (but I understand C++) and in cobol you must initialize your buffers so that left over data does not stay put.
Thanks again
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
every sting that you allocate (or in fact any data type) in this way....
CString *pString = new CString;
char *pChar = new char[n];
must be deallocated when you're finished with it:
delete pString;
delete pChar;
But, if you create vars like this:
CString myString="hello";
char myChar[]="hello";
then you dont delete them; it's done for you when they go out of scope.
Jon
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
A relatively major correction...
If you allocate with:
char *pChar = new char[n];
you must deallocate with:
delete [] pChar;
otherwise you end up with leaks.
J
|
|
|
|
|
Jamie Hale wrote:
otherwise you end up with leaks.
No, you don't. delete[] differs from delete because it calls destructors for all the objects in an array. For "built-in" type, you have no destructors and it does not make a difference.
However, it is still a good programming practice to use delete[] for all arrays allocated with new[]
I vote pro drink
|
|
|
|
|
No, you don't. delete[] differs from delete because it calls destructors for all the objects in an array. For "built-in" type, you have no destructors and it does not make a difference.
IMHO it does make a difference. When allocating an array with new[] , the compiler must reserve an extra bit to recall how many elements there are in the array. Typically, this extra info is allocated at the beginning of the block, and the remaining portion is what's returned to the user. When delete[] is called, the compiler subtracts some bytes to the pointer passed by the user to access the size information. So, if delete is called instead, the compiler will request the underlying memory system to free a pointer that is off its original position by some bytes! Needles to say, this can make the app crash.
(Other schemes for storing the array size information exist, that do no suffer from this inconvenience; but generally speaking, calling delete on an array allocated by new[] is undefined behavior.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
OK. Try this:
int main()
{
while (true)
{
int* a = new int[50000000];
a[2] = 2;
delete a;
}
}
I've found no memory leaks, and certanly no crashes.
However, as I already pointed out, delete[] is the way to go in all the cases we use new[] .
I vote pro drink
|
|
|
|
|
WRONG!!!!
You MUST call delete [] when a buffer was allocated with new [].
Check 5.3.5.1, 5.3.5.2 (which specifically states that using delete on an array is undefined.), and 5.3.4.8.
Also 5.3.5.6 specifically states that the destructor will be called for non-array and array deletes. It is just the case with built-in types such as int, there are no destructors to be called.
It works out of luck. In earlier versions of VC, it would work in debug mode but not release.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Urgh!!!
Did you read my post?
Of course delete[] should be used after new[]. However, it WORKS (with VC 6.0 both debug and release) even without [], out of luck or not. It does not mean you should ever do this, but it works, and that's all I wanted to say.
I vote pro drink
|
|
|
|
|
You are right.
Check my message. It makes a HUGE difference since invoking 'delete' on an array is undefined. I have seen it crash in release builds many times.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Interesting. I was all ready to post wondering what the heck you were talking about, "calls destructors for all the objects in an array"... sounds like Java to me. But I double-checked and found you are indeed correct.
However, according to my copy of C++PL, "The effect of deleting an array with the plain delete syntax is undefined, as is deleting an individual object with the delete[] syntax." So it sounds like Microsoft just decided to do it their own way.
J
|
|
|
|
|
It works with MS out of luck. I have had many programs crash due to this error by the programmer, with VC when in release mode.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Jamie Hale wrote:
Interesting. I was all ready to post wondering what the heck you were talking about, "calls destructors for all the objects in an array"... sounds like Java to me. But I double-checked and found you are indeed correct.
However, according to my copy of C++PL, "The effect of deleting an array with the plain delete syntax is undefined, as is deleting an individual object with the delete[] syntax." So it sounds like Microsoft just decided to do it their own way.
Exactly. Maybe there are too many programmers who forget []
I vote pro drink
|
|
|
|
|
First, clean up your lack of deallocations as others have stated. However, the bad news is that there is little chance doing that will fix the problem.
But, maybe by freeing up the memory, those strings will be forced to trash values while in debug mode and it might help you find the problem.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
So I guess the question is. Why would I want to bother setting and deleting a pointer to an address space, which is storing characters, when I could let the operating system do this for me by just setting the my char variables like this
char StringBuf[32400];
I mean basically if I look at the class for CString.......won't I see that it is setting my StringBuf to a char array with a variable size?
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
for ( numOfLines =0; numOfLines < 15; numOfLines ++)
{
cin>>tempCN>>tempST>>tempMT>>tempTM>>tempIV>>tempNS;
(*tempStock).setCompanyName(tempCN);
(*tempStock).setStockTicker(tempST);
(*tempStock).setMarketTraded(tempMT);
(*tempStock).setTypeOfManufactr(tempTM);
(*tempStock).setInitialValue(tempIV);
(*tempStock).setNumOfOutShares(tempNS);
cout<< (*tempStock).getCompanyName()<<" "<< (*tempStock).getStockTicker()<<" " <<(*tempStock).getMarketTraded()<<" " <<(*tempStock).getTypeOfManufactr()<<" "<< (*tempStock).getInitialValue()<<" "<<(*tempStock).getNumOfOutShares()<< endl;
this piece of code prints all those elements but the 4th one,
any ideas why
thank you
|
|
|
|
|
Step 1. Do not mail me directly with a request, post it here. Thats just rude. What if I was on the toilet or something.
Step 2. Lose the (*tempStock). thing. if tempStock is a class pointer, then get to its members by referencing them like this: tempStock->setCompanyName .
Step 3. Use the debugger. I would think that either one of your set* functions or one of your get* functions is screwed. trace through, step by step, and see where the data goes missing.
Step 4. If, and only if, you are still stuck, having tried tracing through with the debugger, then provide enough information for people to help you. To me, "4th Element" is one before a crap film. Which element? is it tempTM & setTypeOfManufactr???? if it is, say so. Also, it'd probably be useful to actually post the code for the set and get functions in question.
Remember to post your code inside of <PRE> ... </PRE> tags, so that formatting is preserved.
Jon
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
How do you do this sort of thing?
I have two projects in mind.
1) write a better xfer program for my MP3 player than the one supplied with it
2) talk to devices of my own design via the USB
What I would like to know is how does one go about chatting to a device on the USB port.
Are there any utilities that can monitor the data that is transferred on the USB?
I want to know what the xfer program sends and recieves from the MP3 player.
Paresh Solanki
One Tequila Two Tequila Three Tequila Floor
five Tequila, six Tequila seven Tequila more
|
|
|
|
|
This would be advanced stuff. The USB driver itself is a kernel mode driver.
To monitor operations you would probably have to write an upper level filter driver on top of the functional driver supplied for your MP3. This may exist somewhere, dunno.
Just thought I'd share my own frustration with the whole API with someone
|
|
|
|
|
Hi,
I have a problem using msmask32.ocx and msflxgrid.ocx.
I'm using it in an application under VC++ 6, which has an editbox using mask. But to get or set the text of the edit, an error occurs.
If someone can help, please.
Thanks.
Otávio
otavio.romao@inatel.br
|
|
|
|
|
Hi,
When I try to connect to a remote computer with WMI between WinXP German edition and WinXP English it always returns "access is denied", between two english WinXP or two German WinXP computers it connects without problems. Does anyone know what's the problem ?, is it a bug in WinXP/WMI ? or I am doing something wrong?
Thanks!
Best Regards,
Mario M.
|
|
|
|
|
Can someone show me how to encrypt and decrypt with MD5??
I don't understand the classes!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
MD5 is for producing a hash (or checksum). It does not do encryption/decryption.
Joel Lucsy (jjlucsy@ameritech.net)
|
|
|
|
|
See the Crypt* functions from the CryptoAPI in Windows
|
|
|
|
|
Hi all, I'm hoping that someone knows how to specify a frame that is always active in an mdi app? I want it so that even if a child window is activated, the other frame (linked to different document type) is not deactivated (so that the title bar does not change colour from dark blue to light blue)? Any ideas would be well appreciated. At the moment I create my frames indirectly through a document template if that helps.
Many Thanks,
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|