CMap Lookup not working (at least I cannot get it to work) 
Author Message
 CMap Lookup not working (at least I cannot get it to work)

I have the following code in the header:

CMap<LPTSTR, LPTSTR, pmf, pmf> myMap;
.
.
.
typedef void (CImageMarkupDialog::*pmf) ();

In the .cpp file I have this:

for(j = 0; j < TOTALELEMENTS; j++)
{
  myMap.SetAt(masz_LandmarkText[j],
&CMyClass::OnMyFunction)  //all the same function for now

Quote:
}

I then try to do a lookup like this:

CString sContents = getKey(...);

_bstr_t bStr = sContents.AllocSysString();
LPTSTR lpStr = bStr;

int nFound = myMap.Lookup(lpStr, functionPtr);

The Lookup NEVER works (nFound always 0).  I have walked
through the contents of the CMap and the key is there just
as I expect it to be and I also verified that lpStr is a
match.

Any ideas on what is wrong?  I figure it has something to
do with it being an LPTSTR.

Thanks.



Sat, 10 Sep 2005 00:46:01 GMT  
 CMap Lookup not working (at least I cannot get it to work)

Quote:
> I have the following code in the header:

> CMap<LPTSTR, LPTSTR, pmf, pmf> myMap;

You probably expect such a map to hold strings, and use string
comparisons to look up keys. In reality, it holds char* pointers and
looks up keys using pointer comparisons. Think of it this way: if the
map holds LPTSTR p1, p2, p3, and you are searching for LPTSTR q, it
would try to find such a p for which p == q. It lacks mind-reading
abilities that would allow it to guess you actually want a p for which
lstrcmp(p, q) == 0.

Why don't you use

CMap<CString, CString&, pmf, pmf>

?
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Sat, 10 Sep 2005 04:04:02 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. C++/ATL/ADO - Intellisense not working (statement completion options) not working

2. this code works on SGI does not work on linux

3. gets() and fgets() Not Working Properly - Source Included

4. BIG PROBLEM - GETS NOT WORKING

5. Program not work at release mode but work at debug mode

6. GetPrivateProfileSectionNames not working in 98 or ME but does work in 2000

7. Getting pointer to CMainFrame with AfxGetMainWnd not working ?

8. Window NT BitMap Works Windows95 BitMap Does not Work

9. CMap, why doesn't this work?

10. Visual Basic Collections vs c++ CMap Lookup

11. Visual Basic Collections vs c++ CMap Lookup

12. The Harder You Work, the Less You Will Earn

 

 
Powered by phpBB® Forum Software