|
minkowski wrote: But I was messing around with it and I am able to modify the const return value .
Because you probably copied the return of the function into a local non-const variable. Something like this:
const int Fun()<br />
{<br />
return 10;<br />
}<br />
<br />
int main()<br />
{<br />
int Temp = Fun();<br />
Temp++;<br />
}
It is perfectly legal because you don't modify the return value of the function but you modify a copy of it (which is non-const).
|
|
|
|
|
Thank you. Also is the same true for user defined objects? And also for returned references?
Thanks again.
|
|
|
|
|
minkowski wrote: Also is the same true for user defined objects?
Yes, if you store it into another instance (the same way as in my previous example), you still make a copy of your object. And you can of course modify the copy without any problem (as it is constant).
minkowski wrote: And also for returned references?
A reference lets you return a member variable directly (for example in a function from a class, you return a reference to another member of your class). That lets you modify this variable directly. If you return a const reference, then you won't be able to modify the variable directly. Of course, you can still assign it into another variable (results in a copy of your member variable) that you can modify (it's a copy, so you can modify it, if it's non-const)
|
|
|
|
|
minkowski wrote: But I was messing around with it and I am able to modify the const return value
Thats because, you must have removed its constness by assigning it to non-const variable.
OOps ! already answered by Cedric.
Same old thing, need to refresh frequently.
|
|
|
|
|
Ok thanks guys. It makes sense now. I forgot about returning values makes a copy of the object (providing the return type is not a ptr or ref).
|
|
|
|
|
Hi
How to print bitmaps in VC++ ?
thanks
KK
|
|
|
|
|
One way is you can use of CreateDC or see StartDoc
|
|
|
|
|
Hi everyone,
Now, if i will create a new MDI Child Window, i add a Template in the App
So, if i have 3 Child-Windows i must add 3 Templates ...
i add a template like this :
pDocTemplate = new CMultiDocTemplate(IDR_FCustomerSearch,
RUNTIME_CLASS(CMyProjectDoc), // I dont use Doc's
RUNTIME_CLASS(FCustomerSearch),
RUNTIME_CLASS(FCustomerSearchView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
and i open the window like this:
void CMainFrame::OpenWindow(CString Name)
{
CString Cur;
CDocTemplate *Selected;
POSITION pos = theApp.GetFirstDocTemplatePosition();
while(pos != NULL) {
Selected = (CDocTemplate*)theApp.GetNextDocTemplate(pos);
ASSERT(Selected != NULL);
ASSERT(Selected->IsKindOf(RUNTIME_CLASS(CDocTemplate)));
Selected->GetDocString(Cur,CDocTemplate::docName);
if(Name == Cur) {
Selected->OpenDocumentFile(NULL);
}
}
}
Is it correct? or exists another, better possibility ?
Because if i have f.ex. 25 Child frames, i have a very long list of
Templates-Additions ...
Thanks
|
|
|
|
|
Are you confusing multiple documents with child frames ? Can you explain ?
|
|
|
|
|
Thats possible LOL
Because i have all the programmation in my CFormView ( which is raccorded with a Dialog (
plus simplement) )
CMDIChildWnd with a CFormView and a CDocument ( not used )
So i have different CFormView's ... The CMDIChildWnd Object doesn't change normally
If i want open a new Child window, i need to do what?
Big thanks
-- modified at 7:15 Friday 20th October, 2006
|
|
|
|
|
Hi,
I'm using the pdh library to monitor the allocated private bytes in order to find memory leaks in a big project. Now I realized that my class isn't leakfree itself, the constructor of my class does use up 104k, but the destructor only releases about 82k.
I copied the sources for my class to a new project and investigated the problem with Purify, and Purify tells me that there is a potentially memory leak of 16834 in one block allocated at the line
if(PdhAddCounter(m_hQuery,szCounterLine,0,&m_hCounter) != ERROR_SUCCESS)
and a memory leak of 2 blocks (I think that's for the 2 counters I monitor) for 314 bytes in the same line.
The help files of Visual C++ tell me that PdhCloseQuery(m_hQuery), which is called in the destructor, should free all resources belonging to the query and its contained counters, but even adding a loop with PdhRemoveCounter to remove the Counters (and freeing their memory) manually doesn't help. Purify still tells me of an potential memory leak of 16834 bytes in that line.
Now my question: what is causing this big amount of memory allocated at PdhAddCounter? I would have thought, that, if there's such a big amount associated to PdhQuery, it would be allocated at PdhOpenQuery. And how can this big memory block be freed again?
Hope anyone can help
Martin Dietz
|
|
|
|
|
how to trim database items?
(trim left , right) or if you have any ideea please tell me !
Bravoone
|
|
|
|
|
Did you ask this question on sql forum?
|
|
|
|
|
Bravoone_2006 wrote: ...if you have any ideea please tell me !
We do, but they usually fall upon deaf ears.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Is it possible to make calling process's windows invalidate when WaitForSingleObject was called? The scenario is that when the calling process start an installation package thread the package will take the portion of the process' windows, this portion will only be repainted when the install thread exit. But I still want the process' window irresponsive while the package is installing.
|
|
|
|
|
What are you doing exactly ? You start an 'instalation'package in a separate thread and in the main thread, you directly use WaitForSingleObject ? That is a bit useless. Because of course calling WaitForSingleObject will block the current thread until your instalation is finished, thus the GUI will freeze.
I think a better solution would be to have a timer that will check regularly if the process is still running, with GetExitCodeProcess[^]. If the function returns STILL_ACTIVE (259), the process is still running.
|
|
|
|
|
Cedric Moonen wrote: What are you doing exactly ? You start an 'instalation'package in a separate thread and in the main thread, you directly use WaitForSingleObject ? That is a bit useless
What I'm trying to do is to prevent the user from doing anything with main thread's windows while the package is installing, but this way the portion taken by the package window overlapped with main thread widow, when main thread windows removed that area appears blank. I don't want that blank.
|
|
|
|
|
LiYS wrote: but this way the portion taken by the package window overlapped with main thread widow, when main thread windows removed that area appears blank. I don't want that blank.
That is not because the window of the installation package overlap that your main thread window is blank. It is because you block the main thread with the call to WaitForSingleObject (as I explained in my previous post). If your main thread is blocked, that means your window cannot process any messages anymore (which include paint messages also). So, your window stay blank.
The way to do it is to start your installation in another thread so that you can safely call WaitForSingleObject and then inform you main thread (by posting a message) when the process is finished.
LiYS wrote: What I'm trying to do is to prevent the user from doing anything with main thread's windows while the package is installing
You need to manage that yourself: for example disable the controls on your window or things like that. I don't think there is an easy way to do that (but I might be wrong).
|
|
|
|
|
Cedric Moonen wrote: That is not because the window of the installation package overlap that your main thread window is blank. It is because you block the main thread with the call to WaitForSingleObject (as I explained in my previous post). If your main thread is blocked, that means your window cannot process any messages anymore (which include paint messages also). So, your window stay blank.
I think that way too.
Cedric Moonen wrote: The way to do it is to start your installation in another thread so that you can safely call WaitForSingleObject and then inform you main thread (by posting a message) when the process is finished.
That's the way I adopted now. But the question is before the main thread informed about the sub thread completion how can the main thread process WM_PAINT message, I provide WaitForSing.. with INFINITE.
Cedric Moonen wrote: You need to manage that yourself: for example disable the controls on your window or things like that. I don't think there is an easy way to do that (but I might be wrong).
It is a method, but not suitable in my scenario.
|
|
|
|
|
LiYS wrote: That's the way I adopted now. But the question is before the main thread informed about the sub thread completion how can the main thread process WM_PAINT message, I provide WaitForSing.. with INFINITE.
What I meant is that where you start your installation package (I suppose it is an external app and you start a new process right ?) you put there the WaitForSingleObject. Thus you will have the WaitForSingleObject that blocks a separate thread and not the main thread.
|
|
|
|
|
Dear all
how to resolve this function does not take 1 parameters"? it is "ZhiFangTu(midu2)",". urgent!!!!!!!!!!
Li Zhiyuan
19/10/2006
|
|
|
|
|
li zhiyuan wrote: how to resolve this function does not take 1 parameters"? it is "ZhiFangTu(midu2)",". urgent!!!!!!!!!!
pardon!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I think the error message was clear enough, no ?
This simply means that you passed 1 parameter to your function (ZhiFangTu) and it doesn't take 1 parameters (check your function to see how many parameters you need to pass).
li zhiyuan wrote: urgent!!!!!!!!!!
This is a forum. People won't answer you faster just because you scream 'urgent'. Be polite and patient.
|
|
|
|
|
li zhiyuan wrote: urgent!!!!!!!!!!
Don't let your emergency become someone else's problem. Or, to borrow a related quote, "A lack of planning on your part does not constitute an emergency on mine."
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I want to write a game program can support two joystick(USB head)
Now I success to control player one's joystick.
But how to I control player two's joystick.
What I should set DirectInput to support two joystick?
Do any webs have any sample or book mentioned it?
My Source Code as below:
case JOYSTICK:
if(FAILED(m_Input->GetDirectInputCOM()->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticks, this, DIEDFL_ATTACHEDONLY)))
return FALSE;
if(m_pDIDevice == NULL)
return FALSE;
DataFormat = (DIDATAFORMAT*)&c_dfDIJoystick;
break;
// Set the windowed usage
m_Windowed = Windowed;
// Set the data format of keyboard
if(FAILED(m_pDIDevice->SetDataFormat(DataFormat)))
return FALSE;
// Set the cooperative level - Foreground & Nonexclusive
if(FAILED(m_pDIDevice->SetCooperativeLevel(m_Input->GethWnd(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
return FALSE;
// Set the special properties if it's a joystick
if(Type == JOYSTICK) {
// Set the special properties of the joystick - range
DIprg.diph.dwSize = sizeof(DIPROPRANGE);
DIprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
DIprg.diph.dwHow = DIPH_BYOFFSET;
//DIprg.diph.dwHow = DIPH_BYID;
DIprg.lMin = -1024;
DIprg.lMax = +1024;
// Set X range
DIprg.diph.dwObj = DIJOFS_X;
if(FAILED(m_pDIDevice->SetProperty(DIPROP_RANGE, &DIprg.diph)))
return FALSE;
// Set Y rangine
DIprg.diph.dwObj = DIJOFS_Y;
if(FAILED(m_pDIDevice->SetProperty(DIPROP_RANGE, &DIprg.diph)))
return FALSE;
// Set the special properties of the joystick - deadzone 12%
DIpdw.diph.dwSize = sizeof(DIPROPDWORD);
DIpdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
DIpdw.diph.dwHow = DIPH_BYOFFSET;
DIpdw.dwData = 128;
// Set X deadzone
DIpdw.diph.dwObj = DIJOFS_X;
if(FAILED(m_pDIDevice->SetProperty(DIPROP_DEADZONE, &DIpdw.diph)))
return FALSE;
// Set Y deadzone
DIpdw.diph.dwObj = DIJOFS_Y;
if(FAILED(m_pDIDevice->SetProperty(DIPROP_DEADZONE, &DIpdw.diph)))
return FALSE;
|
|
|
|