|
If I use map[key] = myClassObj1 then result is even more weird.
1. myClassObj2 is created by default constructor (constructor without arguments)
2. myClassObj3 is created by copy constructor from myClassObj2
3. myClassObj4 is created by copy constructor from myClassObj3
4. myClassObj3 is destroyed
5. myClassObj2 is destroyed
6. myClassObj4 call operator= myClassObj1
Hmmm... It's too much for me...
As Joaquín mentioned, there isn't simple way to prevent temporary object. But I have to, because I have collection of collections, so duplication of object will cost me too much. I think there is only one way to do it and it is creation of my own container.
Anyway, thanks a lot for all your answers, gents.
Life is good but it's better to live good.
|
|
|
|
|
think there is only one way to do it and it is creation of my own container.
I'd think twice before going into writing your home made container. Why not have containers of smart pointers to containers? Check Boost shared_ptr class template, which automagically gives you ref-counted access to dynamically allocated objects. The hassle of inserting this into your current code should be minimal.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hi,
the subject says all, i have a TCHAR, and i need convert it to managed string, i am using string.Copy(), but it does not works.
Any body knows any way?
Thanks in Advance
Salamanca 2002 Capital Cultural Europea, Visitala
|
|
|
|
|
I didn't understand your question completely.
why don't you use CString in MFC.
Thanks
--Maya
|
|
|
|
|
He probably wants to use the string in a managed environment, like .NET.
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
I thought the "to Managed String" part was a dead giveaway.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi,
I have an SDI project, My View is derived from CFormView which contain a list box and some other controls.
I would like to maximize (and not only to center) the list box and the other controls when the user maximize the application windows .
How can i do it ?
Thanks.
|
|
|
|
|
Add a handler for WM_SIZE in your CFormView derived class. Then use SetWindowPos(...) on your different controls. (You'll have to assure the controls have been created, cause this function will be called once before the controls have been attached to any window handles.)
|
|
|
|
|
Hi everybody,
I want to get the documents´ icon in a MDI application. When I try to use GetIcon() from CMDIChildWnd HICON is a null pointer. Also when I try to use GetIcon() from CMDIFrameWnd it returns NULL.
By the way I use this in my windows-recorder...
Any ideas?
Amar
|
|
|
|
|
Hi!
Maybe try to get CDocTemplate from CDocument, then access m_nIDResource attribute: LoadIcon(nIDResource). This attribute is not accessible, so You may need to derrive class from CDocTemplate (CMultiDocTemplate to be exact) in order to access this attribute.
Hope this helps
Mukkie
|
|
|
|
|
I want to make an ActiveX control with VC++ (MFC). This control should have a toolbar.
How can I do that ? I tried to create the toolbar like this:
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
This is how it is createed in an standard MFC (.exe) SDI project. This doesn't work. (no error, but the toolbar doesn't appear).
Tzoockee
|
|
|
|
|
|
|
strncpy does not append the terminating null character when the copy runs up to the maximum number of characters specified in the third parameter. Replace your last two lines with:
int nLen=strlen(strExePath) - strlen(pdest);
strncpy(strIniPath, strExePath, nLen);
strIniPath[nLen]='\0';
strcat(strIniPath, ".ini");
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you for your clear answer !
|
|
|
|
|
|
|
|
HOWTO: Iterate values/data inside a registry section?
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
DWORD status;
HKEY hKey;
DWORD dwIndex=0;
status=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Whatever\\Key",0,
KEY_ALL_ACCESS, &hKey);
if (status != ERROR_SUCCESS)
do {
status=RegEnumValue(hKey, dwValue,
dwIndex++;
} while (dwIndex != ERROR_NO_MORE_ITEMS);
RegCloseKey(hKey);
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Hi
if i allocate 2 new char arrays like:
char *pChars1 = new char[8];
char *pChars2 = new char[10];
can i be SURE (i.e. nothing other may happen) that when i use pChars1[8] get the first char of the second array (= pChars2[0])?
For example think of a string which is 7 chars long. Then i set pChars1[7] non-NULL. Then a string-read at the start of pChars1 would give the string consisting of the first and the second array?
If this is not possible, is there a compiler-switch to make this work?
Thanks
Dominik
|
|
|
|
|
No way, no how. Instead you'd need to do this:
char * pChars1 = new char[18];
memset(pChars, 0, 18);
char * pChars2 = pChars1+8;
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
To expand a little on Chris' answer:
When you ask for 8 char's of memory, thats all you get. You have no control over how the Runtime environment allocated that, and you don't need it. If you need two logical blocks of memory to be next to each other, then allocate one (bigger) block.
if you allocate a char[8], then referring to element 8 of that array (which you don't own, you own 0-7), is technically a protection fault. Whether or not it crashes your program is a matter of the alignment of the planets.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Hi,
I use VC++ 6.0 (SP5) (i use MFC), and wish to design a multithreaded application.
I have the following problem :
for (int i = 0; i < N; i++)
{
// Launch may be 4 or 5 threads
AfxBeginThread(thread1);
AfxBeginThread(thread2);
AfxBeginThread(thread3);
AfxBeginThread(thread4);
}
but i would like to execute ONLY ONE thread at time. (if i do not synchronize them, i will have 4*N threads at the same time !!!).
I am confused : what should i use : CSemaphore, CEvent, WaitForSingleObject(), WaitForMultipleObjects()....
Can you help me !
Thanks.
|
|
|
|
|
Have the ThreadFunc s of the threads synchronized with a CRITICAL_SECTION (the same for all of them). This post of mine shows a convenient way to do synchronization with these objects.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|