|
But what if there were multiple map key's (department number's) that are the same? It would only show the first occurance, right? Is there a way I can show all objects of that same key?
Thanks,
Jason
|
|
|
|
|
Do you mean that there are multiple departments with the same number, or that there are multiple employees in the same department?
If the former, then you cannot use department number as a key, since you cannot be sure which distinct department you should be referring to.
If the latter, that's why the data is a vector, so you can add multiple employees.
Steve S
Developer for hire
|
|
|
|
|
The latter, multiple employees in the same department. How would I use a vector inside of a map? I tried the following example but received an error C2665 'std::pair<_Ty1,_Ty2>::__ctor' : none of the 3 overloads can convert parameter 2 from type 'const char [5]'
<code>
typedef map<int, vector<string> > EmployeeType;
void MapVectorTest()
{
EmployeeType theMap;
EmployeeType::iterator theIterator;
theMap.insert(EmployeeType::value_type(0, "Zero")); // error C2665
}
</code>
-- modified at 14:43 Friday 2nd March, 2007
Thanks,
Jason
-- modified at 14:48 Friday 2nd March, 2007
|
|
|
|
|
A multimap will allow you to have multiple values per key.
Dave
|
|
|
|
|
I am reading from a file after opening using this command
ReadFile(hFile,&strData, 300, &dwbytes, NULL); in a C++ dll
strData is defined as a std::string
say std::string test = strData;
After executing the above command, i get an error .. something about misaligned string. I am not sure what could be going on here. When i debug and watch the values i see strData as {???} but then when i drill down, i actually see the correct data read from the file, but it seems like something is wrong such that strData cannot be accessed
|
|
|
|
|
Windows APIs know nothing about C++ objects. You have to pass ReadFile() an array of BYTE s, then take that data and put it in a string .
|
|
|
|
|
I want to write a specialization of the map-class. I just want to synchronize access to the map in memory, the rest should stay the same. Is there any way to achieve that without completely rewriting the class ? Maybe something like accessing the 'base-class'-method ?
|
|
|
|
|
Got it ! I just have to create a custom map that internally keeps a STL-map. Then i can implement all the functions i need and wrap synchronization around them. It's just too simpel.
|
|
|
|
|
Hi All
I m working on a ATL project. There are a lot of warnings as
warning C4653: compiler option 'Optimizations (one or more of /Oawstgp[y]) or debug checks (one or more of /GZ, /RTCcsu)' inconsistent with precompiled header; current command-line option ignored
warning C4651: '/D__MSVC_RUNTIME_CHECKS' specified for precompiled header but not for current compile
Can anybody describe why it is?
Thanks
Pankaj Jain
|
|
|
|
|
Sounds like you've changed compiler options somehow - do a Build->Rebuild - that should do it.
|
|
|
|
|
Hi All
I m working on a ATL Project. I have to add string in a multi column List box using SendDlgItemMessage() but I dont get any idea about that.
I m using it like this
SendDlgItemMessage(IDC_LIST1, LB_INSERTSTRING, (WPARAM) 0, (LPARAM)"Hi");
SendDlgItemMessage(IDC_LIST1, LB_INSERTSTRING, (WPARAM) 1, (LPARAM)"All");
But it is not working. I want to Add "Hi" in one column and "All" other.
If u have any Idea Please suggest me
Thanks & Regards
Pankaj Jain
|
|
|
|
|
PK Jain wrote: But it is not working.
What is exact problem ?
PK Jain wrote: I want to Add "Hi" in one column and "All" other.
WPARAM value refers to item index, not column index.
|
|
|
|
|
Thanks,
But my query is not solved
How to Add String in MultiColumn ListBox using SendDlgItemMessage
Pankaj Jain
|
|
|
|
|
PK Jain wrote: But my query is not solved
For that you need to answer questions asked. I asked, what do you mean by not working ?
PK Jain wrote: How to Add String in MultiColumn ListBox using SendDlgItemMessage
Same as you written in in your original post.
I think you mistaken multicolumn with number of columns as in list box. In case of list box, multi column means, there will be no vertical scrolling as number of string keeps increasing.
Instead, string will be added to next column and so on, and horizontal scroll bar will appear.
I hope this clear your doubts.
|
|
|
|
|
Thanks Prasad,
Thanks to clear my doubts
Pankaj Jain
|
|
|
|
|
A MultiColumn ListBox doesn't give that functionality - you want a ListView instead. To add text to a ListView in the way you want, use something like:
LVCOLUMN col = {0};
SendDlgItemMessage(IDC_LIST2, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
col.iSubItem = 1;
SendDlgItemMessage(IDC_LIST2, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
LVITEM item = {0};
item.mask = LVIF_TEXT;
item.iSubItem = 0;
item.pszText = "Hi";
int itemIndex = (int)SendDlgItemMessage(IDC_LIST2, LVM_INSERTITEM, 0, (LPARAM)&item);
item.iSubItem = 1;
item.pszText = "All";
SendDlgItemMessage(IDC_LIST2, LVM_SETITEMTEXT, itemIndex, (LPARAM)&item);
SendDlgItemMessage(IDC_LIST2, LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE);
SendDlgItemMessage(IDC_LIST2, LVM_SETCOLUMNWIDTH, 1, LVSCW_AUTOSIZE);
[Updated to correct code, add column sizing]Last modified: 17mins after originally posted --
|
|
|
|
|
Hi All,
I use AllocSysString like this
1) - CString myStr="ABCD";
int i=SomeFunction(myStr.AllocSysString());
Later in the code I free the memory as SysFreeString(_com_util::ConversStringToBSTR(myStr));
After using a memory profiling tool now, I don't get a mem. leak in this manner.
Is this the correct approach or should I use
2) - CString myStr="ABCD";
BSTR myStrBSTR=myStr.AllocSysString();
int i=SomeFunction(myStrBSTR);
and then use SysFreeString. While googling I found out the use of CComBSTR.
Can someone here tell me if I am using the right approach or should I use the second one, or use CComBSTR that manages allocation/deallocation by itself.
|
|
|
|
|
Q2A wrote: 1) - CString myStr="ABCD";
int i=SomeFunction(myStr.AllocSysString());
Later in the code I free the memory as SysFreeString(_com_util::ConversStringToBSTR(myStr));
After using a memory profiling tool now, I don't get a mem. leak in this manner.
This approach will definitely cause memory leak, instead use CComBSTR .
CString str(_T("Some Value");
CComBSTR bsStr(str.AllocSysString());
int i=SomeFunction(bsStr);
or Use CComBSTR .
CComBSTR bsStr(_T("Some Value"));
int i=SomeFunction(bsStr);
Here, you dont need to worry about memory leak, CComBSTR will take care of those.
|
|
|
|
|
Hello,
What's the difference between these?
CComBSTR a[256]; //note: square brackets
CComBSTR b(256); //note: parenthesis
|
|
|
|
|
Like2Byte wrote: CComBSTR a[256]; //note: square brackets
It is array of CComBSTR . 256 elements.
Like2Byte wrote: CComBSTR b(256); //note: parenthesis
It is a single CComBSTR object, initialized to initial character size of 256.
|
|
|
|
|
Thanks, Prasad!
That makes things clearer for me.
|
|
|
|
|
Hi.
The application I coded is ATL/WTL windows app, now everything is fine in debug, when I compile it in release it compiles with no errors, however strings for label and other controls are cut off, it shows like only the first letter or nothing.
I get the strings from string table in the local resource, and it works fine in debug mode, I also checked the encoding and it is MBCS defined in both release and debug versions.
What can cause this behavior?
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
Check if you have missed any setting.
Have a look at difference betn debug and release[^] for possible cause. Though this article may not be very useful in this context, but may be you get some idea.
|
|
|
|
|
Thanks, but nothing to help me there, as it pertains mainly to MFC programming. I think I will have to go through Michael Dunn's article about string encodings, hope to find something useful there.
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
It's likely that you've not initialised a variable - when I've had Release/Debug issues, that's what it's usually been.
I always make sure that I include Debug information in Release builds - that way I can use the debugger with Release builds reasonably meaningfully - as long as you keep optimisations turned on and you use the Release version of the C run-time, you've still got a Release build.
|
|
|
|