🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #116

Re: LoadImage() fails

#116
From: Renald Yazmir
Date: Thu, 05 Jun 2008 20:33
76 lines
3316 bytes
Thank you

Using DestroyIcon() instead DeleteObject (hicon) helped.


"Bob Gonder" <none@nowhere.invalid> wrote in message 
news:s7uf44518nadtjc1g41dp996vb2na00ker@4ax.com...
> Renald Yazmir wrote:
>>Hello
>
> Please edit your posts.
> You have way too much whitespace, making it difficult
> to see enough code on one screen to understand it.
>
>>The function LoadImage() fails when it is called multiple times(around 
>>3325
>>times).
>>
>>void test(void)
>>{
>>    int i = 0;
>>    HIMAGELIST image_list = NULL;
>>    HICON hicon;
>>    int ret = 0;
>>    // Create the imagelist.
>>    image_list = ImageList_Create( 14, 14, ILC_COLOR32 | ILC_MASK, 0, 0);
>>
>>    if (image_list == NULL)
>>                        return;
>>    for (i = 0; i < 10000; i++)
>>    {
>>        hicon = (HICON)LoadImage(
>>                     npw_hInstance,
>>                     MAKEINTRESOURCE(PICT_TEXT),
>>                     IMAGE_ICON,
>>                     0,
>>                     0,
>>                     LR_CREATEDIBSECTION | LR_LOADTRANSPARENT);
>>         if (hicon == NULL)
>>         {
>
> Check the reason for failure:
> http://msdn.microsoft.com/en-us/library/ms648045(VS.85).aspx
> "If the function fails, the return value is NULL. To get
> extended error information, call GetLastError."
>
>>               return;
>>         }else{
>>               DeleteObject (hicon);
> You should be using DestroyIcon() instead.
>>         }
>>         ret = ImageList_AddIcon(image_list, hicon);
>>         if (ret < -1)
> You are not checking that failure properly: if( ret == -1 )
>>         {
>>             return;
>>         }
>>     }
>>      ImageList_Destroy(image_list);
>>}
>>
>>In the code above LoadImage() fails (hicon is NULL) when "i" equals to 
>>3325.
>
> It really should fail at i==0 as you are passing
> an invalid handle to ImageList_AddIcon.
>
> Help:
> "The DeleteObject function deletes a logical pen, brush, font, bitmap, 
> region, or palette,
> freeing all system resources associated with the object. After the object 
> is deleted, the
> specified handle is no longer valid. "
>
>
> 
Technical Details
Message-ID: <48483f9e@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news1.google.com!npeer03.iad!npeer01.iad!news.highwinds-media.com!newsfeed2.telusplanet.net!newsfeed.telus.net!xmission!ucberkeley!news-hog.berkeley.edu!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4847dc08$1@newsgroups.borland.com> <s7uf44518nadtjc1g41dp996vb2na00ker@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,23b9287586994cbf
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Renald Yazmir" <renald@partmaker.com>
From: "Renald Yazmir" <renald@partmaker.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4847dc08$1@newsgroups.borland.com> <s7uf44518nadtjc1g41dp996vb2na00ker@4ax.com>
Subject: Re: LoadImage() fails
Date: Thu, 5 Jun 2008 15:33:48 -0500
Lines: 78
Organization: IMCS Inc
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
NNTP-Posting-Host: 66.106.28.123
Message-ID: <48483f9e@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1212694430 66.106.28.123 (5 Jun 2008 12:33:50 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news1.google.com!npeer03.iad!npeer01.iad!news.highwinds-media.com!newsfeed2.telusplanet.net!newsfeed.telus.net!xmission!ucberkeley!news-hog.berkeley.edu!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail