Re: CListCtrl, custom item data and allocation policy

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



This is a good example of where to use inheritance. You can have
CMyListCtrl use DWORDs and then inherit from CMyListCtrl and have it use
pointers.

The overriding of the Delete methods is all up to you and it depends on how
you will be using the class. If your CListCtrl class does all the memory
allocation and ItemData setting independent of the outside then yes you
should override any method that deletes an item so that you can delete the
structure that your class created, and don't forget to catch the destroy
message and traverse the remaining items and delete their data before the
control gets destroyed.

If on the other hand the ItemData is being assigned from outside of the list
control class, then I would say no, let the class that creates the data
handle the deleting of the data.

AliR.



"Mosfet" <anonymous@xxxxxxx> wrote in message
news:478e6385$0$2739$426a74cc@xxxxxxxxxxxxxxx
Hi,

When using a CListCtrl you can associate some custom data via the
SetItemData method.
The problem is it takes a DWORD argumentr that can reference a value or a
pointer to an allocated structure.
When destroying this CListCtrl is there any ways of determining if it
needs to be deallocated.

For instance, let's say I have a CMyListCtrl inheriting from CListCtrl
used in two different dialogs.
In one dialog I call SetItemData passing a DWORD value representing a
numeric value and in the second one I pass a pointer to an allocated chunk
of memory.

In the destructor how doI know if I need to call delete ?






.



Relevant Pages

  • Re: "Portability" contructs like UINT32 etc.
    ... All those WORDS, DWORDS, LPCSTR, HPARAMS, LPARAMS etc. ... I have a real problem with "WORD" and "DWORD" which is used in Windows programs a lot: "WORD" is defined as a 16 bit type and DWORD as a 32 bit type, which means that on your average Pentium or Athlon processor a WORD is a halfword and a DWORD is a word, whereas on a 64 bit processor a WORD is a quarterword and a DWORD is a ... And LPCSTR - "Long Pointer to C String". ... You see, char* is typedef'ed to PCCHAR (yes, ...
    (comp.lang.c)
  • Help Converting To C#
    ... DWORD IBT_DeviceDiscovery; ... pbtDev is a pointer to an allocated array of IBTDEVICE structures. ... This function creates an SDP record and registers a Bluetooth service within ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Which assembler can handle the BIG stuff ?
    ... >>> Instructtions for finaly pointing to the Pointer, ... >> What's a checksum table, ... then a rep cmpsd (dword compare) could be pretty fast indeed. ... This kind of Hash Table is ...
    (alt.lang.asm)
  • Re: Threads on class,
    ... DWORD ThreadFuncAdaptor ... > structure that force the compiler to use a pointer ... > resolves that issue and I can't just post that code, ... > wanted was the threading library it probably would be cheaper to do it ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Threads on class,
    ... DWORD ThreadFuncAdaptor ... > structure that force the compiler to use a pointer ... > resolves that issue and I can't just post that code, ... > wanted was the threading library it probably would be cheaper to do it ...
    (microsoft.public.vc.language)