|
In my program, I have the following code.
struct Stru_A{
char Name[30];
int Age;
}
struct Stru_A * pA1 = new Stru_A();
struct Stru_A * pA2 = new Stru_A();
strcpy(pA1->Name, pA2->Name);
'BoundsChecker' reports the following error,
You have passed an invalid memory address as a pointer to a Windows API function.
However, the program can compile and run successfully ignoring the above BoundsChecker error.
I cannot understand why BoundsChecker report the error.I wonder if ignoring of the error is a correct way.
|
|
|
|
|
As long as you've initialized the Name member of struct Stru_A then there is no problem
in the code you've posted.
If Name is uninitialized then there's a problem
|
|
|
|
|
Thanks,
Yes, I did not initialze 'Name'.
One further question is if uninitialization of 'Name' may cause the following error:
************************
Microsoft Visual C++ Runtime Library
---------------------------
Runtime Error!
Program: C:\PatternDecompose_1_061220\Debug\testing.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
************************
Currently, my program can run successfully with small-scale dataset. However, when it run with a slightly large dataset, the above message will pop up and the program terminates. To solve this problem, I use BoundChecker to test my program and found the error about
<br />
strcpy(pA1->Name, pA2->Name);<br />
|
|
|
|
|
That error usually happens when you're just out of memory (which seems likely, as you mention using a large data set)
You'll probably need to optimise your workflow, so that you don't need to keep so much in memory.
If you don't seem to have a high memory usage when it dies, the other option is extreme memory fragmentation, which can be a much trickier beast to solve (you'd probably want to implement some sort of memory pooling)
|
|
|
|
|
Sorry , I forgot a line in the illustration
struct Stru_A{
char Name[30];
int Age;
}
struct Stru_A * pA1 = new Stru_A();
struct Stru_A * pA2 = new Stru_A();
strcpy(pA2->Name, "123");//<====== omitted line
strcpy(pA1->Name, pA2->Name);
Does it make sense with the originaly omitted line added?
|
|
|
|
|
Which version of IDE you are using ?
|
|
|
|
|
Thanks,
The IDE i am using is Visual C++ 6.0 SP6.Enterprise Edition
|
|
|
|
|
The error you are getting, "You have passed an invalid memory address as a pointer to a Windows API function", is not really correct. Presuming that both pA1 and pA2 allocated correctly, the memory referenced by the Name arrays will be correct, so you did pass valid addresses to the strcpy(...) function.
However, if you do not initialize the data in the memory for the Name arrays, then the strcpy(...) function will start to copy memory from the start of the two array locations, which is correct, but it may continue past the valid memory for the arrays until it encounters a NUL character.
Peace!
-=- James 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! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Sorry , I forgot a line in the illustration
struct Stru_A{
char Name[30];
int Age;
}
struct Stru_A * pA1 = new Stru_A();
struct Stru_A * pA2 = new Stru_A();
strcpy(pA2->Name, "123");//<====== omitted line
strcpy(pA1->Name, pA2->Name);
Does it make sense with the originaly omitted line added?
|
|
|
|
|
Yes that's fine with the line added. You've initialized pA2->Name before using strcpy to
copy it to pA1->Name.
Like James R Twine stated, without doing this, strcpy will continually copy chars until a
0 is found in the source string.
Mark
|
|
|
|
|
Hi,
Can anyone tell me whether it is possible to draw vertical text. using the CDC class. I want to output vertical text to show the lables of the X axis of my bargraph control.
thanks.
|
|
|
|
|
|
Sorry, I want to drae Vertical text not horizontal text .
That method doesn't work. I want to draw a string from bottom to top, letters rotated 90 degrees left?
|
|
|
|
|
You need to play around with the LOGFONT structures members. I think it was the escapement member that you need to alter. Another method would be to draw to an offscreen bitmap, and rotate the whole thing. The latter method would probably be the best solution since modifying the font will yield an ugly output.
|
|
|
|
|
oh;P I think you want to draw a vertical text I think you get your answer of WalderMort reply
|
|
|
|
|
Type something like this:
CPaintDC dc(this);
LOGFONT lf;
lf.lfHeight = -MulDiv(10, GetDeviceCaps(dc, LOGPIXELSY), 72);
lf.lfWidth = 0;
lf.lfEscapement = 900;
lf.lfOrientation = lf.lfEscapement;
lf.lfWeight = FW_DONTCARE;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
_tcscpy(lf.lfFaceName, _T("Arial"));
CFont fnt;
fnt.CreateFontIndirect(&lf);
CFont *pOldFont = dc.SelectObject(&fnt);
dc.TextOut(50, 50, _T("Vertical text"));
dc.SelectObject(pOldFont);
Steve
|
|
|
|
|
Hi, May i know how to solve this problem?
I'm using a dialog based MFC application. I have a custom control to display a square. I need it to display the square only after i click on a button. However i notice that, after inserting a button in the dialog, and using the wizard to add the member variable "m_button" and adding the message "OnClickButton" the program dun execute. May i know the reason for this. What should i do to ensure that it is able to execute? Thanks for any help.
|
|
|
|
|
What is "dun execute"? Do you mean "done execute"? Does that happen when you click the button or do you do something else to cause that?
|
|
|
|
|
sorry, typo error. My meaning is the program don't execute when i click on the execute icon. No dialog was generated although no compilation error. Did i miss in writing any function or messages?
|
|
|
|
|
You need to debug the program. Put a breakpoint at the beginning of the InitInstance. There is probably a problem with the dialog.
Or before using the breakpoint, just execute the program using the debugger and then look at the debug messages after the program finishes. There probably is a message indicating a problem.
|
|
|
|
|
|
Nope, no error in compilation. Only problem is the dialog can't even be generated when i click on execute icon("!").
|
|
|
|
|
Can you show your code that has this problem
|
|
|
|
|
Can you show code ?
By any chance you are using rich edit control, on your dialog ?
|
|
|
|
|
Ok what is the most efficient way in c++ to set the bit of data A to the bit of data B. Ex:
a.7 = b.6;
right away i realized i have to check up to four conditions, and this is what i got:
if( b & ( 1 << 6 ) > 0 && a & ( 1 << 7 ) == 0 ) a |= ( 1 << 7 );
if( b & ( 1 << 6 ) == 0 && a & ( 1 << 7 ) > 0 ) a -= 128; // i.e. a = 1xxxxxxx - 10000000
any1 knows a better way?
|
|
|
|