|
I posted a couple of questions yesterday about a BYTE array created on the heap. After creating it I use SafeArrayAccessData() and SafeArrayUnAccessData() after puttin the info in the array. This is the exact same method I've seen used in countless examples when I googled this stuff. However, I was getting a memory leak because I didn't call 'delete' on the pointer. When I tried to call delete on the pointer, my program ASSERTed in _CrtIsValidHeapPointer(). I never wrote to the array after that and can't figure out why it's doing that, so here's what I did:
UINT nAddress = 0;
BYTE* pBuf = NULL;
pBuf = new BYTE[nLength];
nAddress = (UINT)pBuf;
if(nAddress)
{
pBuf = (BYTE*)nAddress;
delete [] pBuf;
pBuf = NULL;
}
It's been working so far, and not MEMORY LEAKS, but...
Is this okay?
[insert witty comment here]
bdiamond
|
|
|
|
|
I would tend to ensure that the pBuf pointer is never moved from the start of the array and always delete it.
BYTE* pBuf = NULL;
pBuf = new BYTE[nLength];
BYTE* pTemp = pBuf;
delete [] pBuf;
pBuf = NULL;
Hope I have not misunderstood your intensions.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
actually, it's already doing that in the code I omitted. There's another variable called pBytes that I use, but I was still getting that ASSERT.
[insert witty comment here]
bdiamond
|
|
|
|
|
Um strange. If pBuf doesn't become corrupted then you should not have an ASSERT.
I would tend to alter the code back to how you had it and step through with the debugger watching the value of pBuf.
I guess you are masking a bigger problem here!
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Antony M Kancidrowski wrote:
I guess you are masking a bigger problem here!
Agreed.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Okay I put the code back how it was (good thing I'm using SourceSafe). When stepping through the code, this is what happened. After stepping through the line where the pointer is allocated (see line 1) the value in the watch window is
0x01970190 "ÍÍÍÍÍÍÍÍÍÍÍ" unsigned char *
after stepping through line 2 the value is:
0x0018f760 "ÐÏࡱá" unsigned char *
here are the lines:
Line 1: pBuf = new BYTE[nLength];
Line 2: SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
Also, I see the type is listed as 'unsigned char*' in both, and pBuf is declared like this:
BYTE* pBuf;
[insert witty comment here]
bdiamond
|
|
|
|
|
When using SafeArrayAccessData() , there is no need to allocate memory for the second parameter.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
As always you're exactly right. I removed the 'new' allocation from my code and it works just fine, and no memory leaks!! Thanks for the millionth time.
[insert witty comment here]
bdiamond
|
|
|
|
|
bdiamond wrote:
...my program ASSERTed in _CrtIsValidHeapPointer().
What line of what file?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
when i tried to 'delete pBuf ' it asserted in "dbgheap.c" in the above-mentioned function. Now when I trie to recreate it using 'delete [] pBuf ', it crashes in "compip.h" on line 303 in this code:
~_com_ptr_t() throw()
{
_Release();
}
[insert witty comment here]
bdiamond
|
|
|
|
|
I want to merge cell of the word by VC and my codes as follow:
for(int i=3,j=0;j{
c1.ReleaseDispatch();
c2.ReleaseDispatch();
c1=pTable->Cell(i,1);
c2=pTable->Cell(i+DayCount,1);
c1.Merge(c2);
}
the first time this section codes work well, but the second time bug happened.
and if I merge the first row in the seconde time and don't merge the first column it works well too.and continuiously merge the first column buf happned too,why?
|
|
|
|
|
Hi,
how do I detect users's default language in something like 'en' or 'de' or 'en-us'? There is GetUserDefaultUILanguage() but i don't know how to convert into a RFC3066 style text representation. Also I am having difficulties to detect if user has per default 12 or 24 hours format selected.
Thanks for help.
|
|
|
|
|
Have you tried GetLocaleInfo() .
Call the function with LCTYPE set to:
LOCALE_ILANGUAGE - IIRC gets the language identifier.
LOCALE_ITIME - Will get 12 / 24 hr format
to get the appropriate information.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
ah lots of good stuff there, I'll try that.
Thanks!
|
|
|
|
|
I'm really struggling to find anything that would enable me to do this. It's driving me crazy, as i know everything about the title bar now, except this.
I'm looking for the kind of options got in NT Display>Appearance tab where the title bar Item has the option to set a variety of properties, including font, colour, etc.
I get the size of it, and the size of the icon, but the one thing I can't do is the size / font / color of the text.
Anyone got any ideas?
Cheers
Cata
|
|
|
|
|
SystemParamtersInfo (SPI_GETNONCLIENTMETRICS);
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Interesting. This method is completely undocumented in MSDN.
Can you tell me which DLL it's in? And where I can find a list of related Enums + structs?
Cheers
Cata
|
|
|
|
|
The Catalyst wrote:
This method is completely undocumented in MSDN.
It is?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Ooops... pasted with paranthesis...
*sheepish grin*
|
|
|
|
|
MSDN is a great resource, but finding the precise thing you're looking for can be a bear.
Software Zen: delete this;
|
|
|
|
|
I have a ClistCtrl derived class which is ownerdrawn and virtual.
I have been using it quit some time now without any problems.
But when I tried to use this class in a application with manifest included, the darn thing doesn't work proper.
I'm having a lot of paint problems.
Every mousemove over an item causes this item to be redraw.
Does anyone have an idea what is causing these problems.
|
|
|
|
|
Can someone tell me how an irregular dialog box can be displyed using MFC?Thanks in advance.
Dipeka.A.J
|
|
|
|
|
|
Here is an example.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I am developing a project using C instead of visual c++, and when I call for example CreateSurface I must use following syntax:
IDirectDraw_CreateSurface(pdd,&ddsd,&pdds,NULL)
or
pdd->lpVtbl->CreateSurface(&ddsd,&pdds,NULL)
Otherwise I get an error like CreateSurface missing method...
Someone told me that :
All the COM functions are in the virtual method table of the
object. c++ handles that, but in c you have to do it manually.
use the macros defined in ddraw.h.
This seems strange to me is there any simplier way to do this?
And when I use:
DirectDrawCreate(NULL, &p->lpDD, NULL )
I get a compiler error:
error LNK2001: unresolved external symbol _DirectDrawCreate
So how should I call DirectDrawCreate....
Is there any "smart" compiler settings that I can use to let the compiler to treat the Direct draw functions as they where in Visual c++ ???
I have included ddraw.h and linked to ddraw.lib if you wonder...
Please help, cheers Dani
|
|
|
|