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
> 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
> 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
> 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]
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
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
> 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.
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...
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.
Thank you so much, this worked perfectly,
I can't beleve I overlooked this when it now seems so obvious
Cheers
-- Michael