|
1dayprogrammer wrote: ...but i can only produce 4 errors which i dont know how to resolve.
They have been fixed. Please try again.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
1dayprogrammer wrote: for (x=>0; x=<255; y=>0; y=<127)
Should probably be:
for (x = 0, y = 0; x <= 255 && y <= 127; )
... If not, you'll have to explain what you are doing, but with a bit less ambiguity.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
for ( initialization ; condition_to_stop ; increment_expressions ) { }
Maxwell Chen
|
|
|
|
|
Hi Experts,
I am creating a Shell Context menu application. When I right click on any folder or file, I display the path of file/folder.
But If I click on file shortcut(.lnk) file it display the target path of file, although .lnk itself also a file.
I want to retrive shortcut (.lnk) file path.
How can I do this?
I will be very thankful to you.
|
|
|
|
|
I am able to open powerpoint slide showusing MFC.I am using power point type library and i am doing this from the msdn help automating powerpoint application using MFC.
The problem is this is opening powerpoint separately.
I want to create an activex control which itself holds the powerpoint slides.Basically my activex should behave like other container activex like web browser control
Please help me to do this.
|
|
|
|
|
If you want to create a control container the best way is probably to take a look at the "ActiveX Control Test Container" that shipped with VC6. The source code for it is availbale if you hunt around on Google and it contains a very thorough and pretty readable implementation of every single ActiveX container interface. I used this when I was writing a Powerpoint style app some years ago and my app was able to succesfully host actual Powerpoint shows in its douments as well as form controls, grids, its own controls and support scripting them all like a browser as well. It wasn't a small or an easy project but it would have been pretty much impossible without a rock solid working example of a general container.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
HI
i have a application to run my program in Service as SINGLE INSTANCE application .
i have done upto single instance sucessfully. when i move to run this application in service ,it fails to run.
can u tell how to create common GUI id in my application...
i have written SINGLE INSTANCE program in .cpp file
thanks in advance
k.guru moorthy
|
|
|
|
|
guru moorthy.k wrote: can u tell how to create common GUI id in my application...
if u r looking to get a unique id, Create GUID[^] may be useful.
guru moorthy.k wrote: i have done upto single instance sucessfully. when i move to run this application in service ,it fails to run.
not clear, does ur service works without the single instance code? did u try debugging?
|
|
|
|
|
Hi,
I have written a class as follows:
class A
{
char str[2];
public:
A (LPSTR Astr)
{
strcpy(str, Astr);
}
A& operator = (LPSTR Astr)
{
strcpy(str, Astr);
return *this;
}
};
I have created a variable of the class and trying to assign it some values using following code
A a1("aa");
and returning this variable from a function.
This is failing with the following error message
"Run_Time Check Failure#2 - Stack around the variable 'a1' was corrupted" when I do this in a MFC application. This is right since I am not leaving any space for the null character.
However when I am doing the same thing in the DLL, it is running perfectly. I am not getting why it is running in DLL and failing in direct Application?
Can anybody please explain?
|
|
|
|
|
Well, basically why bother if obviously broken code apparently works?
Anyway probably you have such information because MFC (at least in debug build) puts additional code to check memory corruption.
Your code is, BTW, dangerous in both the environments.
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
|
|
|
|
|
abhijitr wrote: char str[2];
This member variable does not have enough room for two characters PLUS the terminating \0 character.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Also, the assignment operator fails to insure there will be no buffer overwrite. Simple assignments such as,
A Astring;
Astring = "too long";
will cause errors. Changing the size of the buffer won't be enough.
The arguments to the assignment operator should be constant; unless you intend to allow it to change its argument?!?
A& operator = (LPCSTR Astr)
{
::memset(str, 0, sizeof(str));
if (!Astr)
return *this;
int len = ::strlen(Astr);
if (len <= sizeof(str)) {
::strcpy(str, Astr);
} else if (sizeof(str) < len) {
::strncpy(str, Astr, sizeof(str) - 1 );
str[1] = '\0';
}
return *this;
}
Should probably check for the degenerate case of an empty string as well.
|
|
|
|
|
This should be between you and the OP.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Your code example may confuse the OP... Your second if() test checks the length of the passed string against the length of the str buffer, instead of "length of the str buffer - 1", so the strcpy(...) executed if the if() passes will overwrite one past the end of the str buffer when it writes a terminating NUL character.
The final else if() test copies the source string correctly, but the line after that places the terminating NUL is using a hardcoded index of 1 , so if str is longer than 2 characters, you will copy a truncated version of the source string and then truncate it further to one character.
Use of sizeof() to determine the character length of the buffer only works for (1) arrays that are part of the object, or automatically/locally allocated as arrays (i.e. if str is actually a pointer to an array and not a real array, it will not work as expected); and (2) only in ANSI builds - for UNICODE, the calculations will be off.
The copying of the source string can be further simplified to:
dwStrBufferLen =
::strncpy( str, Astr, dwStrBufferLen );
str[ dwStrBufferLen - 1 ] = '\0'; This will work regardless of the length of the target string, truncating it if necessary, and will ensure that a terminating NUL is always there.
Since ::strncpy(...) will not go past the length specified, it is one less place to be concerned with doing a correct off-by-one offset. If it runs out of space before the end of the source string, the following line will write the terminating NUL .
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Good catch!
Yes, I missed a few things here. Sorry.
|
|
|
|
|
Maybe because you are running the application in debug mode, and the dll in release mode!?
Either way you are corrupting memory.
AliR.
Visual C++ MVP
|
|
|
|
|
When I add a virtual destructor to this class it is not giving any error.
It runs smoothly.
However if I add simple destructor it fails.
|
|
|
|
|
Hi Guys,
I have finally solved the problem.
If you check the size of class A it comes to be 8 (with virtual destructor) which we were expecting it to be 06 as we have used 2 bytes for ‘stre’ and 4 bytes for virtual pointer
(as we have declared virtual destructor in class A).
On investigation I found that size is 8 due to word alignment of structure and union members which is used to increase the performance.
Due to this we are getting room for extra two characters which accommodates our null character and saves us from crashing.
Thanks for your cooperation.
|
|
|
|
|
I don't understand why you are not increasing the size of the buffer to 3 so that you can have 2 chars and a null, and use strncpy instead of strcpy.
Why are you insisting on overwriting past your buffer?
AliR.
Visual C++ MVP
|
|
|
|
|
I have already implemented this class in my application and changing the string length will require me to make changes to various places which is very error prone at this stage.
|
|
|
|
|
Hi codeprojecters...
i have query abt how to understand polymorphism ..any body plz explain..
Thanks to your Answers....
*****THANKS N ADVANCE****
Mathen.K
(I WILL TRY MY LEVEL BEST )
|
|
|
|
|
I give you a simple example:
Teacher object calls the LearnPolymorphism() method on two instances of Pupil . The first one one, say cleverPupil , that is really an instance of CleverPupil , calls readBook(goodOOPBook) to fulfill task. On the other hand, the second Pupil instance, say lazyPupil , instance of LazyPupil , implements the method in his own way, with a call to startAsking(hereAndThere) ...
Both CleverPupil and LazyPupil inherit from Pupil hence Teacher is able to call virtual Pupil method LearnPolymorphism() on them. But, due to Polymorphism , Teacher obtains two quite distinct results from them.
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
modified on Thursday, February 21, 2008 11:06 AM
|
|
|
|
|
clever innovation, 3 stars for u,
I don't think he will understand it, instead completes the homework with these classes example.
|
|
|
|
|
yes u r right mr.rajkumar
*****THANKS N ADVANCE****
Mathen.K
(I WILL TRY MY LEVEL BEST )
|
|
|
|