Article View: borland.public.cppbuilder.nativeapi
Article #112Re: LoadImage() fails
From: Bob Gonder
Date: Thu, 05 Jun 2008 15:03
Date: Thu, 05 Jun 2008 15:03
62 lines
2944 bytes
2944 bytes
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:
<s7uf44518nadtjc1g41dp996vb2na00ker@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!npeer02.iad!npeer01.iad!news.highwinds-media.com!newsfeed2.telusplanet.net!newsfeed.telus.net!indigo.octanews.net!news-out.octanews.net!mauve.octanews.net!news-out.readnews.com!transit3.readnews.com!207.99.111.53.MISMATCH!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4847dc08$1@newsgroups.borland.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 From: Bob Gonder <none@nowhere.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: LoadImage() fails Date: Thu, 05 Jun 2008 08:03:50 -0700 Message-ID: <s7uf44518nadtjc1g41dp996vb2na00ker@4ax.com> References: <4847dc08$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.77.144.232 X-Trace: newsgroups.borland.com 1212678227 67.77.144.232 (5 Jun 2008 08:03:47 -0700) Lines: 65 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!npeer02.iad!npeer01.iad!news.highwinds-media.com!newsfeed2.telusplanet.net!newsfeed.telus.net!indigo.octanews.net!news-out.octanews.net!mauve.octanews.net!news-out.readnews.com!transit3.readnews.com!207.99.111.53.MISMATCH!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail