Article View: borland.public.cppbuilder.nativeapi
Article #14978Re: new instead of GlobalAlloc
From: Jonathan Arnold
Date: Thu, 24 Jul 2003 14:09
Date: Thu, 24 Jul 2003 14:09
41 lines
2647 bytes
2647 bytes
Moshe Shahar wrote:
> Try this...
> unsigned long dwSize = 0;
> void *pBuffer = NULL;
> if( RegQueryValueEx(CurrentKey, Ident.c_str(),
> NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS )
> {
> pBuffer = new char[dwSize];
> if( pBuffer ){
> //Do stuff
> }
> }
Just be aware that the latest incarnation of new will not just
return a NULL pointer, but rather will throw an exception. So
it should be:
try
{
char* pBuffer = new char[dwSize];
}
catch (...)
{
}
Also, don't forget to free the memory when you are done.
> "Maurice Anderson" <mauriceanderson@hotmail.com> wrote in message
>>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
You might try asking this in the .language.cpp group. Lots of C++ gurus
hang out there and can tell you how to use a "safe" new.
--
Jonathan Arnold C/C++/CBuilder Keen Advice:
http://www.keen.com/categories/categorylist_expand.asp?sid=5156620
Comprehensive C++Builder link site:
http://www.buddydog.org/C++Builder/c++builder.html
Technical Details
Message-ID:
<3f1fe87f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!logbridge.uoregon.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f1f7ed4@newsgroups.borland.com> <3f1f8a82$1@newsgroups.borland.com> <3f1f8fc5$1@newsgroups.borland.com> <3f1f924b@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 07:12:05 PST Date: Thu, 24 Jul 2003 10:09:03 -0400 From: Jonathan Arnold <jdarnold@buddydog.org> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en, ja MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: new instead of GlobalAlloc References: <3f1f7ed4@newsgroups.borland.com> <3f1f8a82$1@newsgroups.borland.com> <3f1f8fc5$1@newsgroups.borland.com> <3f1f924b@newsgroups.borland.com> In-Reply-To: <3f1f924b@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 66.92.76.225 Message-ID: <3f1fe87f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059055743 66.92.76.225 (24 Jul 2003 07:09:03 -0700) Lines: 42 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!logbridge.uoregon.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail