Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TVINSERTSTRUCT Undefined symbol 'item'

25 views
Skip to first unread message

Michael

unread,
Apr 15, 2004, 3:23:36 AM4/15/04
to

G'Day

I have just started using Borland's compiler, their free command line release, version 5.5 (Borland C++ 5.5.1 for Win32)

I am trying to compile code to use a tree view control, however the compiler insists that the structure TVINSERTSTURCT does not have a member called item,
Here is a code fragment:

<Snip>
TVITEM newTreeItem;
TVINSERTSTRUCT newTreeItemStruct;

/* Fill out structure info */
newTreeItemStruct.item = newTreeItem;
newTreeItemStruct.hInsertAfter = TVI_LAST;
newTreeItemStruct.hParent = TVI_ROOT;

</snip>

The compiler gives this error:
Error E2451 tvtest.c 37: Undefined symbol 'item' in function WinMain

Looking at MSDN, the TVINSERTSTRUCT does indeed have the member "item", and the commctrl.h header file appears to implement this correctly, furthermore the code compiles correctly under the lcc-win32 C compiler

As per MSDN recommendation I have tried defining the NONAMELESSUNION token before including the commctrl.h, but this did not solve the problem,
I have also tried using the .itemex member (with a TVITEMEX structure) however the same problem arises, namely it reports the member does not exist.

Any help would be appreciated, thank you for your time
-- Michael

Remy Lebeau (TeamB)

unread,
Apr 15, 2004, 4:28:18 AM4/15/04
to

"Andrue Cope" <no....@spammy.com> wrote in message
news:82vbfgt1rm70$.glguvsls482q.dlg@40tude.net...

> Could it be a new addition to the structure?

No. The 'item' member has always been available, all the way to at least
BCB3 if not earlier.


Gambit


Remy Lebeau (TeamB)

unread,
Apr 15, 2004, 4:28:54 AM4/15/04
to

"Michael" <ml...@mail.com> wrote in message
news:407e3878$1...@newsgroups.borland.com...

> The compiler gives this error:
> Error E2451 tvtest.c 37: Undefined symbol 'item' in function WinMain

Please show a more complete code snippet, and please quote the EXACT error
message word-for-word.


Gambit


Andrue Cope

unread,
Apr 15, 2004, 4:11:28 AM4/15/04
to
On 15 Apr 2004 00:23:36 -0700, Michael wrote:

> Any help would be appreciated, thank you for your time

Could it be a new addition to the structure? The free command line compiler
is several years old. I don't think they ever upgraded it so it'll still be
the BCB5 compiler. BCB5 was superceded by BCB6 a couple of years ago and
BCB6 has itself been superceded now.

You might find that just replacing the 'free' headers with those from
lcc-win32 compiler will work. As long as the headers are portable between
the two compilers (which is highly likely) it should work fine.
--
Andrue Cope
[Bicester UK]

Michael

unread,
Apr 15, 2004, 4:55:18 AM4/15/04
to

Thankyou for your reply,

I tried your suggestion of replacing the headers with those from lcc-win32,
however it appears they are not compatable, as the compiler just displays
a whole host of new errors with the lcc-win32 headers

I was unaware that the command line compiler was such an old version,
so I tried #defining an old windows version number before including the
headers, and it fixed the problem with the TVINSERTSTRUCT,
It appears the compiler does not like the union that the structure
has embedded in it.

Thus I have found a solution, but the only problem with this is it means
I will be unable to use and of the new features of the API, thus I will have to look for
a different compiler for my project.

Thanx for the help

Cheers
-- Michael

Michael

unread,
Apr 15, 2004, 5:06:24 AM4/15/04
to
The complete code to reproduce the error is:
<CODE>
#include <windows.h>
/* #define NONAMELESSUNION <-- HAD NO EFFECT */
#include <commctrl.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {

TVITEM newTreeItem;
TVINSERTSTRUCT newTreeItemStruct;

INITCOMMONCONTROLSEX commonControls = {
sizeof (INITCOMMONCONTROLSEX),
ICC_BAR_CLASSES | ICC_TREEVIEW_CLASSES | ICC_LISTVIEW_CLASSES};

/* Initilize Common Controls (for status bar etc) */
InitCommonControlsEx(&commonControls);

newTreeItem.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;

/* Set the text of the item. */
newTreeItem.pszText = "Item Name";
newTreeItem.cchTextMax = sizeof(newTreeItem.pszText)/sizeof(newTreeItem.pszText[0]);

/* Save the heading level in the item's application-defined data area. */
newTreeItem.lParam = (LPARAM) 0;

/* Fill out structure info */

newTreeItemStruct.hInsertAfter = TVI_LAST;
newTreeItemStruct.hParent = TVI_ROOT;

newTreeItemStruct.item = newTreeItem;

return TRUE;
}
</CODE>

The compiler output is:
bcc32 -tW tvtest.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
tvtest.c:


Error E2451 tvtest.c 37: Undefined symbol 'item' in function WinMain

Warning W8057 tvtest.c 43: Parameter 'hInstance' is never used in function WinMain
Warning W8057 tvtest.c 43: Parameter 'hPrevInstance' is never used in function WinMain
Warning W8057 tvtest.c 43: Parameter 'lpCmdLine' is never used in function WinMain
Warning W8057 tvtest.c 43: Parameter 'nCmdShow' is never used in function WinMain
*** 1 errors in Compile ***

Note: Line 37 is this line newTreeItemStruct.item = newTreeItem;

The fix, as I just posted before seeing this message was to add the following #define's before the includes
#define _WIN32_WINNT 0x0300
#define _WIN32_IE 0x0300
or any _WIN32_IE value below 0x0400

Looking at the commctrl.h file, it appears the compiler does not like the
union definition that is in the structure:
<snip from commctrl.h>
typedef struct tagTVINSERTSTRUCTA {
HTREEITEM hParent;
HTREEITEM hInsertAfter;
#if (_WIN32_IE >= 0x0400)
union
{
TVITEMEXA itemex;
TV_ITEMA item;
} DUMMYUNIONNAME;
#else
TV_ITEMA item;
#endif
} TVINSERTSTRUCTA, FAR *LPTVINSERTSTRUCTA;
</snip>

I hope this is enough information, it does seem unusual for a compiler
to come with header files that it cannot work with

Thanx for the reply

Cheers
-- Michael

Andrue Cope

unread,
Apr 15, 2004, 7:35:27 AM4/15/04
to
On 15 Apr 2004 01:55:18 -0700, Michael wrote:

> Thus I have found a solution, but the only problem with this is it means
> I will be unable to use and of the new features of the API, thus I will have to look for
> a different compiler for my project.

Try the Borland product CBX. It is very cross platform and compiler
agnostic.

Ed Mulroy [TeamB]

unread,
Apr 15, 2004, 10:18:53 AM4/15/04
to
I tried that code on my machine and it did not generate the error.

Try putting this in after all includes. If you look in commctrl.h
you'll see how this might relate. After you see what it does when you
compile, tune it to your tastes.

#if _WIN32_IE >= 0x0501
#pragma message __WIN32_IE .ge. 0x0501
#endif

#if _WIN32_IE < 0x0501
#pragma message __WIN32_IE .lt. 0x0501
#endif

#if _WIN32_IE < 0x0401
#pragma message __WIN32_IE .lt. 0x0401
#endif

And for gosh sakes put a #pragma argsused on the line before the
declaration of WinMain to get rid of all the noise-region warnings
about unused calling args.

. Ed

> Michael wrote in message
news:407e...@newsgroups.borland.com...


Bob Gonder

unread,
Apr 15, 2004, 11:01:28 AM4/15/04
to
Michael wrote:

Do what Remy and Ed have suggested, then you could also always do this
too...

> newTreeItemStruct.item = newTreeItem;

newTreeItemStruct.DUMMYUNIONNAME.item = newTreeItem;

Your last option is to change to C++ as C doesn't allow anon. unions.

Michael

unread,
Apr 15, 2004, 11:16:53 PM4/15/04
to

Bob Gonder <no...@notmindspring.invalid> wrote:
>Do what Remy and Ed have suggested, then you could also always do this
>too...
>
>> newTreeItemStruct.item = newTreeItem;
>
> newTreeItemStruct.DUMMYUNIONNAME.item = newTreeItem;

Thank you so much, this worked perfectly,
I can't beleve I overlooked this when it now seems so obvious

Cheers
-- Michael

0 new messages