Article View: borland.public.cppbuilder.nativeapi
Article #14971Re: new instead of GlobalAlloc
From: Maurice Anderson
Date: Thu, 24 Jul 2003 07:53
Date: Thu, 24 Jul 2003 07:53
37 lines
2194 bytes
2194 bytes
It is in a function to allocate enough memory for a buffer in a call to
RegQueryValueEx. I am asking for a way to allocate a buffer of type *void
from the heap. I know I can use either keyword "new" or the GlobalAlloc
function. But I don't know how to do it using "new". Later I cast pBuffer
to char = (char*)pBuffer.
Here is more code for context:
unsigned long dwSize = 0;
void *pBuffer = NULL;
if( RegQueryValueEx(CurrentKey, Ident.c_str(),
NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS )
{
pBuffer = GlobalAlloc(GPTR, dwSize);
if( pBuffer ){
//Do stuff
}
}
Thanks -M-
"Vladimir Afanasyev" <avv@systema.kiev.ua> wrote in message
news:3f1f8a82$1@newsgroups.borland.com...
>
> Hi,
>
> "Maurice Anderson" <mauriceanderson@hotmail.com> wrote:
> >How would I write the equivalent code using new for the code below?
> >
> >unsigned long dwLength = 0;
> >void *pBuffer = GlobalAlloc(GPTR, dwLength);
>
> Your question is not clear.
> Why you can't put this code in constructor?
> Vladimir.
>
Technical Details
Message-ID:
<3f1f8fc5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f1f7ed4@newsgroups.borland.com> <3f1f8a82$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,cb38ee1db20489cf X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-24 01:17:20 PST From: "Maurice Anderson" <mauriceanderson@hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f1f7ed4@newsgroups.borland.com> <3f1f8a82$1@newsgroups.borland.com> Subject: Re: new instead of GlobalAlloc Date: Thu, 24 Jul 2003 00:53:18 -0700 Lines: 39 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 64.30.203.223 Message-ID: <3f1f8fc5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059033029 64.30.203.223 (24 Jul 2003 00:50:29 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail