|
Hi All
im getting this error when i execute the following piece of code
Run-Time Check Failure #2 - Stack around the variable name 'pbuff' was corrupted.
does ne1 know whats wrong with my code, im pulling my hair out here
thanks
si
CString vChr;
TCHAR pbuff[32];
CString Out;
int num=0;
int nOffset=0;
int nRead;
//read in the 1st 32 bytes
do
{
for (int f=0; f<=32; f++)
pbuff[f]=NULL;
sName="";
nOffset+=32;
nRead = SimMem.Read(pbuff,32);
int nLen=0;
int a = (int)pbuff[11]+128;
TCHAR ch = (char)a;
for (f=0; f<10; f++){
sName += pbuff[f];
}
}
|
|
|
|
|
si_69 wrote:
for (int f=0; f<=32; f++)
You are running a loop from 0 to 32. Thats 33 times, but you only alocated space for 32 chars.
You need to alocate enough space (and dont forget the trailing zero for a string!).
Hope this helps
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
jhwurmbach wrote:
a loop from 0 to 32
for (int f=0; f<=32; f++)
You missed the <= 32 so it stops at 31, although it would be better writte as < 32
It is amazing what you can accomplish if you do not care who gets the credit. - Harry S Truman
|
|
|
|
|
Get into the habit of using sizeof() eg.
<br />
CString vChr;<br />
TCHAR pbuff[32];<br />
CString Out;<br />
<br />
int num=0;<br />
int nOffset=0;<br />
int nRead;<br />
<br />
do<br />
{<br />
for (int f=0; f<sizeof(pbuff); f++)<br />
pbuff[f]=NULL;<br />
<br />
sName="";<br />
nOffset+=sizeof(pbuff); <br />
nRead = SimMem.Read(pbuff,sizeof(pbuff));<br />
<br />
int nLen=0;<br />
<br />
<br />
int a = (int)pbuff[11]+128;<br />
TCHAR ch = (char)a;<br />
<br />
for (f=0; f<10; f++){<br />
sName += pbuff[f];<br />
}<br />
It will stop you hitting annoying bugs like this...
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
hi,
i am facing strange problem with IDM_PRINT.
i am using the brochure machine sample of microsoft and my own custom print template.it is working fine with the IDM_PRINTPREVIEW and i am able to see the desired result.when i try to use IDM_PRINT to print it directly,it justs does nothing.neither it invokes the print dialog nor prints .if i pass the printtemplate path as null the print dilaog comes up and prints.this seems to be very strange .would you please suggest me how you dealt with this problem.
thanks a lot
GVS
==============================================================================
CComPtr<iolecontainer> spContainer;
CComPtr<iserviceprovider> spSP;
CComPtr<iwebbrowser2> spWB;
CComPtr<idispatch> spDisp;
CComPtr<ihtmldocument2> spDoc;
CComPtr<iolecommandtarget> spCT;
CComVariant vPTPath = "res://BrochureMachine.dll/PT.htm";
m_spClientSite->GetContainer(&spContainer);
spContainer->QueryInterface(IID_IServiceProvider, (void**)&spSP);
spSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser, (void**)spWB);
spWB->get_Document(&spDisp);
spDisp->QueryInterface(IID_IHTMLDocument2, (void**)&spDoc);
spDoc->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);
spCT->Exec(&CGID_MSHTML, IDM_PRINT, NULL, &vPTPath, NULL);
gvs
|
|
|
|
|
I am seeing the same issue described above.
Did you ever come to a resolution / workaround ?
Thanks,
Kyle
|
|
|
|
|
Hi All, I'm using malloc, realloc and free to maintain variable length memory blocks, which I intend to use for a container template class. What I would like to know is how to initialise parts of the block by calling the constructor of my object of type T? I use malloc if the block is null and realloc if it isn't so initialisation is quite important (otherwise realloc will get called on a duff address == crash ). Trouble is I can't use calloc to initialise the block bytes to 0 cos it'll only initialise the container the first time round (realloc is used thereafter), and secondly I have objects of x bytes that have _vfptr's which should not be NULL. So is there anyway I can initialise a new object when I allocate enough space for it? I can't use placement new because I need the allocation to grow or shrink. Aside from creating an object on the stack and memcpying it, I was hoping to be able to allocate the space and then call the objects constructor using that allocated space for its containment, anybody got any ideas? Thanks all for reading this far.
Alan.
|
|
|
|
|
AFAIK malloc is a 'C' function.
The operator new in C++ also calls that constructor. If you go with the C++ way of doing things - if you're using templates you have to be using C++, you can allocate a contiguous block of memory, then use placement new to construct the objects. Thats how the STL allocators work.
Don't forget mixing new and malloc is just asking for trouble...
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
I would have a think about what you are trying to do, and see if there's an easier way of doing it. I know that may sound obvious, but using malloc and realloc to maintain a dynamic chunk of memory and then mapping C++ objects into it is going to be difficult (if possible), and asking for trouble. Realloc is not always some wonder-function that avoids memory copying, and often will just allocate a bigger chunk of memory and do the copying for you - it's very much a 'C' way of thinking.
You may be better off looking at something like the STL's vector (or list or whatever is most appropriate), and seeing if you can make use of its automatic ability to dynamically extend memory. It'll be a lot easier and save you many headaches. Object pools may also be something to think about, with you overriding the new and delete operators.
|
|
|
|
|
I am basically trying to create my own vector template container class, not so much for reinventing the wheel purposes, but to learn deeper memory management techniques. I know that new/delete calls the ctor for the objects it creates, but I am needing to dynamically grow/shrink the memory block. Realloc is nice in that it tries to extend the memory (or move the contents into a new block so it can extend it), I don't have to worry about copying the contents over every time the array grows one notch. Is placement new still a viable solution?
|
|
|
|
|
Hi
i search for a function which can do this:
double value = 4,6793
value = round(value,2) //after that value should be 4,68
in which library can i find this function???
|
|
|
|
|
do you mean round to 4,6800? or truncate to 467.93 and round to 468? I don't really get how you can get 4,68? You'll need to make you own round routine though if you want to do anything really weird with numbers
|
|
|
|
|
Hi i mean this:
round(y,x) y = value to round for example 4,6793233
x = position after ',' to round
round should look after y at position x+1
if y at positon x is > 5 then 4,68 forget the rest of
numbers!
|
|
|
|
|
OK, I'm not aware of any function in the standard libs that'll do what you want. Also, if the number you specify is a double where does this comma come from? I mean the double number 46793233 would be 46,793,233. So I'm assuming the comma is always after the first digit? Either way, iterating through figures is a bit of a nightmare, and i'm not really sure of the best way to go about it, sorry.
|
|
|
|
|
In some countries they use the ',' intead of the '.'.
Example:
In America 4.67
In Italy 4,67
|
|
|
|
|
Interesting...why is that? The '.' is a decimal point to indicate decimal figures in a number, so why use a ','? Cheers for pointing that out to me though, I would never have guessed
|
|
|
|
|
A decimal point is an English notation. Most other countries use decimal commas, and the thousand separator is a period.
|
|
|
|
|
Dangleberry wrote:
Interesting...why is that? The '.' is a decimal point to indicate decimal figures in a number, so why use a ','?
Because it's the other way around in a lot of countries.
It can throw you at first, but it's something to keep in mind while on international forums.
|
|
|
|
|
This should work for you:
double a = 4.6793;<br />
a = a + 0.005;
int b = a * 100.0;
double c = b / 100.0;
|
|
|
|
|
Now I know what I'm doing, I'd do it like this :
//could make it a variable parameter so you don't have to keep supplying
//it with a param when you just want a standard round.
double rounddouble(double val, int fig=0)
{
//Avoid division by zero by checking fig for zero
if(fig != 0)
{
//get the multiply divide factor
double sigfig = pow(10, (double)fig);
//multiply the figure by 10pow to get the pos to chop the end off
val *= sigfig;
//add 0.5 before rounding so we round up or down
val += 0.5;
//adding 0.5 affects round down value in effect, rounding up or down.
val = floor(val);
//return the decimal to original value with chopped off rounded crap
val /= sigfig;
}
else
{
//just round the figure without an offset
val += 0.5;
val = floor(val);
}
//finally return the value
return val;
}
Hope this helps. This will return the correct rounded double value based on however many significant fig's you specify.
Alan.;P
|
|
|
|
|
I think this short scribble should work:
<br />
double round(double x, int digits)<br />
{<br />
double _int = (double)((int)x);<br />
double _pow = pow(10, digits);<br />
double _fract = (x - _int) * _pow;<br />
<br />
return _int + (_fract / _pow);<br />
}<br />
|
|
|
|
|
Very (more that too much) important thing in DCOM-
is to create transparent or easily incorporated
branch to Internet compatible -transports-
for real cases - most DCOM solutions is not workable
due to default firewall security and uneebility to work in
this comditions with not predefined client IE Browser.
That is many methods is possible:
DCOM -SOAP - DCOM
DCOM -SOAP - ELSE STUB like .NET,
due to method proxy-stab is same
(!- in methodology)
but realisation is different.
Just need to connect realisations.
Can you say -
Does such transport proxy stabs exists ?
|
|
|
|
|
I've set CEdit control property as Numeric, but its not accepting decimail.
Any suggesstions , it should accept numbers with decimal.
Warm Regards,
KKRam
|
|
|
|
|
No, it cannot! You'll have to make your own CEdit control. I made one, if you want I can send you the files. Just give me an e-mail adress.
|
|
|
|
|
hi moonen
Thanks for u r reply, u can send it to kamesh.kln@sify.com
Warm Regards,
KKR
|
|
|
|