Click here to Skip to main content
15,909,897 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWMSyncReader Question Pin
Elbert Mai11-Dec-05 7:47
Elbert Mai11-Dec-05 7:47 
QuestionCString inside CMap Pin
udiraz11-Dec-05 4:23
udiraz11-Dec-05 4:23 
AnswerRe: CString inside CMap Pin
RChin11-Dec-05 4:53
RChin11-Dec-05 4:53 
GeneralRe: CString inside CMap Pin
udiraz11-Dec-05 5:03
udiraz11-Dec-05 5:03 
GeneralRe: CString inside CMap Pin
RChin11-Dec-05 5:42
RChin11-Dec-05 5:42 
AnswerRe: CString inside CMap Pin
JonEngle11-Dec-05 5:51
JonEngle11-Dec-05 5:51 
AnswerRe: CString inside CMap Pin
Christian Graus11-Dec-05 12:10
protectorChristian Graus11-Dec-05 12:10 
AnswerRe: CString inside CMap Pin
Jack Puppy11-Dec-05 16:39
Jack Puppy11-Dec-05 16:39 
If you look at the definition of CMap, you'll see the following:

<br />
CMap<KEY, ARG_KEY, VALUE, ARG_VALUE><br />


The KEY and VALUE are the data types you're mapping. In your case, KEY = CString and VALUE = int.

The ARG_ types are the types used in argument passing within CMap. The code that calculates the hash used for lookups is found in the GetAssocAt function of the CMap template:

<br />
CMap<KEY, ARG_KEY, VALUE, ARG_VALUE>::GetAssocAt(ARG_KEY key, UINT& nHashBucket, UINT& nHashValue) const<br />


The exact line of code that calcuates the hash is here:

<br />
nHashValue = HashKey<ARG_KEY>(key);<br />


With your map declaration, the line translates to:

<br />
nHashValue = HashKey<CString>(key);<br />


If you search for HashKey in the Visual Studio folder, you'll see that Microsoft has defined a handful of HashKey functions for various data types:

<br />
UINT HashKey(WORD key) const;<br />
UINT HashKey(void* key) const;<br />
UINT HashKey(void* key) const;<br />
UINT HashKey(WORD key) const;<br />
UINT HashKey(LPCTSTR key) const;<br />
UINT HashKey(LPCTSTR key) const;<br />
UINT HashKey(LPCTSTR key) const;<br />
<br />
etc...<br />
<br />


You'll also notice that there isn't a HashKey defined for CString. This is why you're getting the 'cannot convert' error. The compiler does not know how to convert from a CString to a DWORD_PTR, which is the default implementation of HashKey.

In the case of CString, there are two ways to solve the problem:

1) Define your own custom HashKey routine for CString, as described in the article http://support.microsoft.com/default.aspx?scid=kb;en-us;158541

2) The simple solution - use LPCTSTR (which has a HashKey provided by Microsoft, and has a casting operator defined in the CString class) as your argument key in your CMap declaration:

<br />
CMap<CString, LPCTSTR, int, int> myMap;<br />




Bernie (Boom Boom) Geoffrion worked Atlanta Flames games in the 1970s with the splendid Jiggs McDonald. One night, Geoffrion said, "Jiggs, there are only three things to hockey: shooting and skating." McDonald said, "Right, Boomer. And what's the third?" The exasperated Geoffrion replied," Jiggs, that's the three. Shooting. And. Skating."

AnswerRe: CString inside CMap Pin
ThatsAlok12-Dec-05 3:54
ThatsAlok12-Dec-05 3:54 
QuestionA Makefile to Visual c++ project converter Pin
winecad11-Dec-05 3:21
winecad11-Dec-05 3:21 
AnswerRe: A Makefile to Visual c++ project converter Pin
winecad11-Dec-05 3:22
winecad11-Dec-05 3:22 
GeneralRe: A Makefile to Visual c++ project converter Pin
tom_dx11-Dec-05 3:58
tom_dx11-Dec-05 3:58 
GeneralRe: A Makefile to Visual c++ project converter Pin
winecad11-Dec-05 6:03
winecad11-Dec-05 6:03 
QuestionListcontrol scrolling problem Pin
FarPointer11-Dec-05 2:25
FarPointer11-Dec-05 2:25 
QuestionButtons in CListCtrl icon style Pin
RoyceF10-Dec-05 16:25
RoyceF10-Dec-05 16:25 
AnswerRe: Buttons in CListCtrl icon style Pin
Rajesh R Subramanian11-Dec-05 17:31
professionalRajesh R Subramanian11-Dec-05 17:31 
GeneralRe: Buttons in CListCtrl icon style Pin
RoyceF12-Dec-05 4:44
RoyceF12-Dec-05 4:44 
Questionabout the CPictureEx Pin
blackeye200410-Dec-05 15:10
blackeye200410-Dec-05 15:10 
Questiongetting disk throughput Pin
T1TAN10-Dec-05 11:54
T1TAN10-Dec-05 11:54 
QuestionRe: getting disk throughput Pin
David Crow10-Dec-05 16:38
David Crow10-Dec-05 16:38 
AnswerRe: getting disk throughput Pin
T1TAN11-Dec-05 21:32
T1TAN11-Dec-05 21:32 
GeneralRe: getting disk throughput Pin
David Crow12-Dec-05 3:28
David Crow12-Dec-05 3:28 
GeneralRe: getting disk throughput Pin
T1TAN12-Dec-05 3:39
T1TAN12-Dec-05 3:39 
GeneralRe: getting disk throughput Pin
David Crow12-Dec-05 5:51
David Crow12-Dec-05 5:51 
GeneralRe: getting disk throughput Pin
T1TAN12-Dec-05 20:36
T1TAN12-Dec-05 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.