|
Try a better one:
#include <vector>
std::vector<CString> vec;
Maxwell Chen
|
|
|
|
|
Probably you need to post more deteails and code:
(1) the statement
Eranga Thennakoon wrote: m_pMainWnd = &dlg;
generates an exception only since you added the CStringArray ?
(2) how did you define and initialise the CStringArray ?
(3) how did you define and initialise dlg ?
...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
CPallini wrote: (1) the statement
Eranga Thennakoon wrote:
m_pMainWnd = &dlg;
generates an exception only since you added the CStringArray?
Yes, and that code line is not added by me, it's generated when I add the CStringArray variable.
CPallini wrote: (2) how did you define and initialise the CStringArray?
private:
CStringArray m_pszTimeZones;
Like this on .h file, and use IDE operations. Not write on the .h file at all.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: it's generated when I add the CStringArray variable
Sure? It's hard to believe that CStringArray needs that statement...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Yes it is defined in InitInstance()
I appreciate your help all the time...
Eranga
|
|
|
|
|
Honestly, I haven't enough elements to give useful help to you.
Can you post bigger chunks of code?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
It's work. What I have done is after use the array clear it up as follows.
m_pszTimeZones.RemoveAll();
I appreciate your help all the time...
Eranga
|
|
|
|
|
Hi
How to open a file in Append mode using CFile
thanx in advance
-RisKhan-
|
|
|
|
|
open the file setting nOpenFlags parameter either to CFile::modeNoTruncate | CFile::modeCreate or CFile::modeWrite (depending on your needs) and then seek to the end before the very first write operation.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
I'm unfamiliar to CListCtrl::SetItemData.
I've got help from here, understanding that first you should CListCtrl::SetItemData then you can use CListCtrl::GetItemData to retrieve.
My codes:
<br />
CMyClass data;<br />
CListCtrl::SetItemData(nItem, data);<br />
But I got compilation error, "data is not a DWORD_PTR type".
How should I write the correct code?
modified on Monday, January 07, 2008 7:44:41 PM
|
|
|
|
|
You can store a pointer to the object (supposing m_pMyListCtrl is declared as CListCtrl * ):
CMyClass data;
m_pMyListCtrl->SetItemData(nItem, (DWORD_PTR) &data);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
You should also state that this is dangerous to do if data is local to the function: the instance will be deleted when the function terminates and your pointer will point to an invalid memory location.
A better way to do this would be to:
1) have data be a member of the class. But then, that doesn't make a lot of sense in the current scenario (why would you need to store it in the data pointer of the list control then ?)
2) to create it on the heap (using new). But in that case, you must not forget to delete the pointer once you don't need it anymore (typical place would be in the class destructor and whenever you change an existing pointer).
(That was just a complement to your answer for the OP).
|
|
|
|
|
Cedric Moonen wrote: 1) have data be a member of the class. But then, that doesn't make a lot of sense in the current scenario (why would you need to store it in the data pointer of the list control then ?)
What class? I can't see any class (other than CMyClass & CLIstCtrl) in the current scenario.
(just kidding)
Of course you're right with your observations since
fantasy1215 wrote: I'm unfamiliar to CListCtrl::SetItemData.
and I guess he is also unfamiliar with object lifetime management.
Thank you.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Cedric Moonen wrote: 1) have data be a member of the class. But then, that doesn't make a lot of sense in the current scenario (why would you need to store it in the data pointer of the list control then ?)
To separate the order of the items in the control from that of the data in the control class. The control may display the items in numerous ways (alphabetical, numerical, ascending, descending, etc.) The data may not be ordered that way or convienient to do so. Nor does the data need to be a part of the list control class. It may be passed into the list control class to be acted upon but not reordered.
It mostly saves constantly looking up the item data.
However, I'm not sure if the CListCtrl item data value is guaranteed to be large enough to hold a pointer for all platforms.
YMMV
|
|
|
|
|
Thanks very much. After your reply, I know CListCtrl::SetItemData should store the Data which have the lifetime at least as long as your ListCtrl class(So you should make the data a class member of your ListCtrl class, or a heap data).
|
|
|
|
|
I'm writing a program with a login screen. In the login screen, a login and password has to be filled in. Now I want to read the login and password of the user the is logged in into windows (because the login and password giving into the program have to be exacly the same as those of windows)
|
|
|
|
|
sujtha wrote: Now I want to read the login and password of the user the is logged in into windows...
For the former, see GetUserName() .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
(Sorry my system is having trouble pasting URLs)
http://msdn2.microsoft.com/en-us/library/kewsb8ba(vs.71).aspx
According to what it says, it will call ::operator new(size_t, char*, int) , but actually it gives a compilation error C2660: 'operator new' function does not take 3 arguments .
A* pa2 = new(__FILE__, __LINE__) A(20);
Maxwell Chen
|
|
|
|
|
At least they are honests
(It is at the top of the code snippet):
Anyway, it is also stated:
placement
Provides a way of passing additional arguments if you overload new.
hence you probably have to overload the operator to use additional placement argument.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
CPallini wrote: At least they are honests
// C2660 expected
Yes I have seen it.
If it gets a C2660, there wouldn't be a successful build and no chance to execute the call.
CPallini wrote: hence you probably have to overload the operator to use additional placement argument.
In the comment, it specifies the global operator new . I guess MSDN didn't intend to ask user implement an operator overload.
Anyway, it's fun to see a junk sample in MSDN.
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote: In the comment, it specifies the global operator new. I guess MSDN didn't intend to ask user implement an operator overload.
If the placement usage is for overloading, then overload is probably needed.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
If I remember rightly this is implemented in the STL so you need to include the right STL header to make this work #include <memory>
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Matthew Faithfull wrote: If I remember rightly this is implemented in the STL so you need to include the right STL header to make this work #include <memory>
Not working.
Maxwell Chen
|
|
|
|
|
Have you tried #include< new > ?
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|