VC++ 6.0 SetupDiGetClassImageList query
-
Hi.Does anyone know how to cast an SP_CLASSIMAGELIST_DATA structure to CImageList class? Is it possible? I'm guessing it should be but can't seem to be able to do it. Actually I've retrieved an imagelist of all devices using SetupDiGetClassImageList function into a SP_CLASSIMAGELIST_DATA structure. I'm now trying to set it to be the imageList of my Tree Control that lists the devices. However due to these casting issues I get a runtime assertion error and my application crashes. Any ideas? I've tried the following methods but have failed with the same runtime error. Method 1: <i>PSP_CLASSIMAGELIST_DATA imageList; SetupDiGetClassImageList(imageList); <b>m_Tree.SetImageList((CImageList *)imageList->ImageList,TVSIL_NORMAL);</b></i> Method 2: <i>PSP_CLASSIMAGELIST_DATA imageList; CImageList imList; SetupDiGetClassImageList(imageList); <b>imList.Attach(imageList->ImageList); m_Tree.SetImageList(imList,TVSIL_NORMAL);</b></i> I have bolded the lines that are causing the crash.
-
Hi.Does anyone know how to cast an SP_CLASSIMAGELIST_DATA structure to CImageList class? Is it possible? I'm guessing it should be but can't seem to be able to do it. Actually I've retrieved an imagelist of all devices using SetupDiGetClassImageList function into a SP_CLASSIMAGELIST_DATA structure. I'm now trying to set it to be the imageList of my Tree Control that lists the devices. However due to these casting issues I get a runtime assertion error and my application crashes. Any ideas? I've tried the following methods but have failed with the same runtime error. Method 1: <i>PSP_CLASSIMAGELIST_DATA imageList; SetupDiGetClassImageList(imageList); <b>m_Tree.SetImageList((CImageList *)imageList->ImageList,TVSIL_NORMAL);</b></i> Method 2: <i>PSP_CLASSIMAGELIST_DATA imageList; CImageList imList; SetupDiGetClassImageList(imageList); <b>imList.Attach(imageList->ImageList); m_Tree.SetImageList(imList,TVSIL_NORMAL);</b></i> I have bolded the lines that are causing the crash.
-
Hey, I've added all the code relevant to retreival of ImageList below. There is nothing other than this in my code. Please have a look and let me know what modifications it would require. Thanks!:) Code: PSP_CLASSIMAGELIST_DATA imageList={0};int imIndex; CImageList imList; imageList->cbSize=sizeof(SP_CLASSIMAGELIST_DATA); SetupDiGetClassImageList(imageList); imList.Attach(imageList->ImageList); m_Tree.SetImageList(&imList,TVSIL_NORMAL); /*devInfo is a valid SP_DEVINFO_DATA structure.I know this because the tree control shows the correct output(without any images though)*/ SetupDiGetClassImageIndex(imageList,&devInfo.ClassGuid,&imIndex); I later use imIndex to set the iImage property of TVITEM structure. This is node that is later inserted into the tree.
-
Hey, I've added all the code relevant to retreival of ImageList below. There is nothing other than this in my code. Please have a look and let me know what modifications it would require. Thanks!:) Code: PSP_CLASSIMAGELIST_DATA imageList={0};int imIndex; CImageList imList; imageList->cbSize=sizeof(SP_CLASSIMAGELIST_DATA); SetupDiGetClassImageList(imageList); imList.Attach(imageList->ImageList); m_Tree.SetImageList(&imList,TVSIL_NORMAL); /*devInfo is a valid SP_DEVINFO_DATA structure.I know this because the tree control shows the correct output(without any images though)*/ SetupDiGetClassImageIndex(imageList,&devInfo.ClassGuid,&imIndex); I later use imIndex to set the iImage property of TVITEM structure. This is node that is later inserted into the tree.
-
So,
m_Tree.SetImageList(&imList,TVSIL_NORMAL);
caused a runtime error, you said? What kind of error you had at this time? If you had application error like 0xc0000005, some pointer maybe invalid. Other error, I cannot imagine the situation at this time.Yes it is an application error where it refers to some address claiming the memory could not be "read". However, if that statement is commented out all seems to run fine. So all I can conclude from this is that the problem lies in these 2 code statements of Attach and SetImageList functions. I really can't figure out what could possibly be causing this and am really close to giving up on the idea of adding images! Please Help!:confused: Exactly the error is as follows: The instruction at "0x00405652" referenced memory at "0x00000004".The memory could not be "read".
modified on Friday, June 19, 2009 2:27 AM
-
Yes it is an application error where it refers to some address claiming the memory could not be "read". However, if that statement is commented out all seems to run fine. So all I can conclude from this is that the problem lies in these 2 code statements of Attach and SetImageList functions. I really can't figure out what could possibly be causing this and am really close to giving up on the idea of adding images! Please Help!:confused: Exactly the error is as follows: The instruction at "0x00405652" referenced memory at "0x00000004".The memory could not be "read".
modified on Friday, June 19, 2009 2:27 AM
> referenced memory at "0x00000004". This usually means that offset 4 of pointer which points null is not accessible. So you can check the member whether null or not of imList. If you use visual studio IDE, you can step into codes and can check any data is null or not.
-
Hey, I've added all the code relevant to retreival of ImageList below. There is nothing other than this in my code. Please have a look and let me know what modifications it would require. Thanks!:) Code: PSP_CLASSIMAGELIST_DATA imageList={0};int imIndex; CImageList imList; imageList->cbSize=sizeof(SP_CLASSIMAGELIST_DATA); SetupDiGetClassImageList(imageList); imList.Attach(imageList->ImageList); m_Tree.SetImageList(&imList,TVSIL_NORMAL); /*devInfo is a valid SP_DEVINFO_DATA structure.I know this because the tree control shows the correct output(without any images though)*/ SetupDiGetClassImageIndex(imageList,&devInfo.ClassGuid,&imIndex); I later use imIndex to set the iImage property of TVITEM structure. This is node that is later inserted into the tree.
Hey, I think that I've found a problem in your code. Please see the modified code below,
SP_CLASSIMAGELIST_DATA imageList = {0}; int imIndex; CImageList imList; imageList.cbSize=sizeof(SP_CLASSIMAGELIST_DATA); SetupDiGetClassImageList(&imageList); imList.Attach(imageList.ImageList); m_Tree.SetImageList(&imList,TVSIL_NORMAL);
Hope it helps.. :)