Advertisement

03.08.2003 at 04:15AM PST, ID: 20543317
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

GlobalAlloc - Type definition - memory problem?

Asked by _Mark_ in Miscellaneous Programming

Tags: , ,

Hi,

I want to add functionality to an owner-drawn listbox. I seem to run into a memory related problem. Since I just became a member, I have only 80 points available, which I offer for an answer.

Here is some code (not complete, just to outline my problem):

A User-Datatype is used to store additional information for each listbox item. Note bDontShowIcon as Boolean. This is the variable that I need to add to the Type definition.

Type ICONLISTBOXITEMINFO    
    lItemData As Long          
    lExtraData As Long          
    lIconIndex As Long          
    lIndentSize As Long        
    lItemHeight As Long        
    lForeColour As OLE_COLOR    
    lBackColour As OLE_COLOR  
    bUnderLineItem As Boolean  
    bOverLineItem As Boolean    
    dFontSize As Single        
    tLF As LOGFONT              
    lTextAlignX As Long        
    lTextAlignY As Long        


    bDontShowIcon As Boolean   '<==


End Type


....


'Itemdata is written into a block of memory and attached to the listbox-item
'len(tLI)=105 without bDontShowIcon
'len(tLI)=107 with bDontShowIcon


Dim tLI as ICONLISTBOXITEMINFO  

' Allocate the global memory to store the extended
' properties for this item:
hMem = GlobalAlloc(GPTR, Len(tLI))

tLI.lBackColour = lBackColour
tLI.lForeColour = lForeColour
tLI.lIndentSize = lIndent
tLI.lIconIndex = lIconIndex
tLI.lItemData = lItemData

tLI.bDontShowIcon = True          '<==

....


' Store the item properties in memory
LPtr = GlobalLock(hMem)
' Copy the memory into tLI
CopyMemory ByVal lPtr, tLI, Len(tLI)
' Lock the memory again:
GlobalUnlock hMem


' Attach the block of memory to the listbox-item
wMsg = LB_SETITEMDATA
m_lR = SendMessageByLong(m_hWnd, wMsg, m_lNewItem, hMem)

-----------

Whenever I later access tLI.bDontShowIcon it is set to False. However, if I put "bDontShowIcon As Boolean" in first position in the Type definition
it later provides the correct value (that makes me wonder what this means for "lTextAlignY as Long", which will then be the last item in the Type definition). Also, if I keep "bDontShowIcon" where it is in the Type definition but add another *pseudo* variable after it, let's say: "lTest As Long", then subsequently tLI.bDontShowIcon works as expected everywhere in the code. Am I encountering a memory allocating problem here?

I am new to memory management functions, so I might be overlooking some simple mechanism here. Thanks for any help.Start Free Trial
 
Loading Advertisement...
 
[+][-]03.08.2003 at 08:21AM PST, ID: 8094127

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Miscellaneous Programming
Tags: globalalloc, iconlistboxiteminfo, problem
Sign Up Now!
Solution Provided By: KillerApp
Participating Experts: 3
Solution Grade: A
 
 
[+][-]03.08.2003 at 08:44AM PST, ID: 8094237

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 08:58AM PST, ID: 8094268

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 08:59AM PST, ID: 8094274

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 09:05AM PST, ID: 8094291

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 10:23AM PST, ID: 8094566

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 10:44AM PST, ID: 8094652

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 10:57AM PST, ID: 8094712

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 11:02AM PST, ID: 8094720

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 11:28AM PST, ID: 8094815

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 12:53PM PST, ID: 8095128

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.08.2003 at 12:57PM PST, ID: 8095141

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.09.2003 at 10:07AM PST, ID: 8098282

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.28.2003 at 02:43PM PDT, ID: 9447270

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32