Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: 'CommCtrl' is not a class or namespace name


This question is answered.


Permlink Replies: 3 - Last Post: Dec 6, 2016 7:28 AM Last Post By: Andy Stobirski
Andy Stobirski

Posts: 18
Registered: 6/12/16
'CommCtrl' is not a class or namespace name  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 7, 2016 1:40 AM
Hi Chaps

I'm working through some examples in C++ Builder 5.0, and have come across a code demo for TTreeView::CustomSort, which is as follows:

int __fastcall CompareFunc(TTreeNode *Node1,TTreeNode *Node2, int Reverse)
{
int GT = AnsiStrIComp(Node1->Text.c_str(), Node2->Text.c_str());
if (Reverse)
return -GT;
return GT;

}

This procedure can then be used as a parameter to CustomSort to sort the nodes of the tree view. To sort in ascending order, call

TreeView1->CustomSort((CommCtrl::TTVCompare)CompareFunc, 0);

To sort in descending order, call

TreeView1->CustomSort((CommCtrl::TTVCompare)CompareFunc, 1);

However, when I try this on a form with a treeview and a bunch of nodes, I get the following error on compile:

[C++ Error] EventViewerPlus.cpp(235): E2090 Qualifier 'CommCtrl' is not a class or namespace name

I'm rather stuck with this, and have tried adding the following includes

#include "CommCtrl.hpp"
#include "commctrl.h"

But to no avail. Can anyone help?

Cheers

Andy

Alex Belo

Posts: 626
Registered: 10/8/06
Re: 'CommCtrl' is not a class or namespace name  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 7, 2016 6:58 AM   in response to: Andy Stobirski in response to: Andy Stobirski
Andy Stobirski wrote:

[C++ Error] EventViewerPlus.cpp(235): E2090 Qualifier 'CommCtrl' is
not a class or namespace name

File Commctrl.hpp has the following (machine generated) declaration:

namespace Commctrl
{
...

C++ is case-sensitive language. Change CommCtrl to Commctrl in your
source and see if this helps.

--
Alex
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: 'CommCtrl' is not a class or namespace name
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 7, 2016 11:39 AM   in response to: Andy Stobirski in response to: Andy Stobirski
Andy wrote:

TreeView1->CustomSort((CommCtrl::TTVCompare)CompareFunc, 0);

As Alex stated, the correct namespace is "Commctrl", not "CommCtrl".

However, simply correcting the namespace will not fix your code, as it has
another error in it.

If you look at the actual declaration of TCustomTreeView::CustomSort(), it
is:

bool __fastcall CustomSort(PFNTVCOMPARE SortProc, int Data);


And if you look at the actual declarations of PFNTVCOMPARE and TTVCompare,
they are:

typedef int (CALLBACK *PFNTVCOMPARE)(LPARAM lParam1, LPARAM lParam2, LPARAM 
lParamSort);


typedef int __stdcall (*TTVCompare)(int lParam1, int lParam2, int lParamSort);


As you can see, the declaration of your CompareFunc() callback does not match
either of those declarations, so any type-casting is going to hide compiler
errors from you.

While your type-cast can account for your callback using the wrong parameter
types (since they are "compatible", as the LPARAM of each tree node is actually
a TTreeNode* pointer), what your type-cast will not account for is your callback
using the wrong calling convention. Your callback is using __fastcall, which
is not compatible with __stdcall.

If you declare your callback correctly, you won't need to type-cast it
at all when passing it to CustomSort(), eg:

int __stdcall CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    TTreeNode *Node1 = reinterpret_cast<TTreeNode*>(lParam1);
    TTreeNode *Node2 = reinterpret_cast<TTreeNode*>(lParam2);
    int GT = AnsiStrIComp(Node1->Text.c_str(), Node2->Text.c_str());
    if (lParamSort)
        return -GT;
    return GT;
}
 
...
 
TreeView1->CustomSort(&CompareFunc, 0);
TreeView1->CustomSort(&CompareFunc, 1);


Otherwise, if you want to use wrong-but-compatible parameter types, it needs
to look more like this instead:

int __stdcall CompareFunc(TTreeNode *Node1, TTreeNode *Node2, LPARAM Reverse)
{
    int GT = AnsiStrIComp(Node1->Text.c_str(), Node2->Text.c_str());
    if (Reverse)
        return -GT;
    return GT;
}
 
...
 
TreeView1->CustomSort((PFNTVCOMPARE)&CompareFunc, 0);
TreeView1->CustomSort((PFNTVCOMPARE)&CompareFunc, 1);


--
Remy Lebeau (TeamB)
Andy Stobirski

Posts: 18
Registered: 6/12/16
Re: 'CommCtrl' is not a class or namespace name  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 6, 2016 7:28 AM   in response to: Andy Stobirski in response to: Andy Stobirski
That's great guys! Thanks for taking the time to respond!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02