Solved

ListView_InsertColumn returning -1

Posted on 1998-04-23
9
630 Views
Last Modified: 2013-12-03
What can possibly be the cause of that? Note that it only happens on some computers, on most of them it works no problem. Here's the code:

void CreateListView(HWND hWnd)
{
      LV_COLUMN item;
      int i;
      char *cpitem[] = {"Date", "To", "Subject", "Address", "From"};
      
      InitCommonControls();

      if ((list = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
            WS_VISIBLE | WS_CHILD | LVS_ALIGNLEFT | LVS_REPORT,
            0, 0, 0, 0, hWnd, (HMENU)55, hInst,
            NULL)) == NULL)
            return;
      
      item.mask      = LVCF_TEXT | LVCF_FMT | LVCF_WIDTH;
      item.fmt      = LVCFMT_LEFT;
      item.cx            = WIDTH / ((sizeof cpitem / sizeof cpitem[0]) + 1);
      for (i = 0; i < sizeof cpitem / sizeof cpitem[0]; ++i)
      {
            item.pszText = cpitem[i];
            item.cchTextMax = strlen(cpitem[i]);
            if (ListView_InsertColumn(list, 0, &item) == -1)
                  MessageBox(hWnd, "Failed to create column", appname, MB_OK);
      }
}
0
Comment
Question by:_Zaphod
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1396992
Could you sent a piece od code
0
 
LVL 1

Author Comment

by:_Zaphod
ID: 1396993
Edited text of question
0
 
LVL 23

Expert Comment

by:chensu
ID: 1396994
It seems that ListView_InsertColumn(list, 0, &item) should be ListView_InsertColumn(list, i, &item);
0
 
LVL 1

Author Comment

by:_Zaphod
ID: 1396995
That's not true, I want the columns to be in the opposite order than that in which I wrote the char*[]. The reason for that is that I was stupid first and lazy later :)
And besides, that's no reason for it to fail (I always thought).
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Expert Comment

by:RLM
ID: 1396996
Try including LVCF_SUBITEM in item.mask and set item.iSubItem to 0 before calling.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1396997
1) Reset all members of the item before the call:
  LV_COLUMN item = { 0 };

2) Use GetLastError() for a possible explanation.

0
 
LVL 1

Author Comment

by:_Zaphod
ID: 1396998
*shrug* Didn't work.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1396999
What did GetLastError() return?  (see WINERR.H for a translation of the error codes).

This way:

    if (ListView_InsertColumn(list, 0, &item) == -1)
    {
        int err = GetLastError();
        // ...
    }
0
 

Accepted Solution

by:
RLM earned 50 total points
ID: 1397000
Take 45 from dresser. Load. Point at computer. Pull trigger.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now