|
Do you think that it's right? ~A() will be called after A() immediately.
|
|
|
|
|
yu-jian wrote: why the c plus plus allow defining a variable without name?
It isn't doing that.
You are confusing 'variable' with 'expession'.
In the following the left 'x' is a varible while the right side is an expression. The execution of the expression is not dependent upon the variable. The variable is just where the result of the expression is stored.
x = doSomething();
|
|
|
|
|
Your line with "CTempLock (&(this->m_Lock));" will create an unnamed variable of type CTempLock, call the destructor specified, and then call the destructor and destroy the object.
As another poster pointed out, using a constructor reference in this way, is supported as a means to pass temporary objects to a function.
The temporary object only exists on the stack, long enough to make a function call, that is intended to use the temporary object as a reference.
modified 16-Jan-13 17:28pm.
|
|
|
|
|
Right. Perhaps, it can use this way to do something in the constructor function of CTempLock.
|
|
|
|
|
Yes.
1. The object is created on the stack.
2. The constructor is called.
3. The destructor is called.
4. The object is then forgotten.
The example you provided is a good demo of how you can introduce locking bugs. Because the object goes out of scope right away, it doesn't really do anything useful.
The proper way to do it is:
CTempLock Lock(&(this->m_Lock));
If you do something like this...
void ProcessLock(const CTempLock & TempLock)
{
}
ProcessLock(CTempLock(&(this->m_Lock)));
Then the temporary object will exist for the lifetime of the call.
|
|
|
|
|
{
CTempLock tempLock(&m_FrameListLock);
if (m_FrameQueue.size() == 0) return 0L;
pFrameData = m_FrameQueue.front();
m_FrameQueue.pop_front();
}
if (WaitForSingleObject(this->m_hCloseEvent, 0) == WAIT_OBJECT_0)
{
return ZMD_OK;
}
try
{
if (pFrameData != NULL)
{
if (pFrameData->lpData != NULL)
{
try
{
this->DistributeFrame(pFrameData->lpData, pFrameData->iSize);
byte* pBuf = reinterpret_cast<byte*>(pFrameData->lpData);
delete[] pBuf;
}
catch (CException* e)
{
e->Delete();
}
}
delete pFrameData;
pFrameData = NULL;
}
}
catch (CException* e)
{
e->Delete();
}
}
There is a error that happens in the following code.
byte* pBuf = reinterpret_cast<byte*>(pFrameData->lpData);
<b>delete[] pBuf;</b>
Just as the image, here.
https://www.dropbox.com/s/ckqkz88qnifus4g/Error.png
I find that the pFrameData->lpData is a wild buffer point. I do not know when the buffer is released? Or this deque has some problem?
The class is here.
class CStreamProcess
{
HRESULT ProcessFrames();
void DistributeFrame(const LPVOID const lpBuf, int dwSize);
HANDLE m_hCloseEvent;
HANDLE m_hFrameProcessEvent;
std::deque<SZMDFrameData> m_FrameQueue;
CCriticalSection m_FrameListLock;
};
--------------------
I have resolved this problem. Its a mistake of using CCriticalSection.
modified 15-Jan-13 3:35am.
|
|
|
|
|
|
Hi CPallini,
Thank you very much. You help me greatly.
|
|
|
|
|
Not this problem, I made a test that has a temporary class. CMyClass. When pop_front() the desconstructor function of class CMyClass will not be called.
|
|
|
|
|
Hello,
I need to add a string on top / on bottom of a few drown GDI objects on printing. So far i override the OnPrint function.The problem i am facing is to decide where the text should be added in the CDC (i cant find the coordinates needed for TextOut)
I tried with CDC::GetBoundsRect(&dcRect, 0); but in dcRect i get nothing but zeros and the function returns 1. I think its returning DCB_RESET but i am not sure.
I tried with GetCurrentBitmap and GetBitmapDimension but still i get CSize variable with nothing but zeros.
All help is welcome 
|
|
|
|
|
The best thing i found is in the Microsoft Superpad example on the next link
Superpad
You can see how to put Header / Footer in it.
|
|
|
|
|
Using API In MFC OnDraw
TextOut(pDC->GetSafeHdc(),1, 20, "HELLO HELLO", 11);
I am not sure if that will print alligned properly.
|
|
|
|
|
My problem is finding the right coordinates for the TextOut function but after a talk with my Team manager we decided its better to be done as a header / footer.
Before that i just wanted to get the BoundRectangle with the hopes that it will be describing only the part in the page where the elements will be drown not the whole page itself.
I was wondering if there is a way to get out of the CDC member information about the position of the elements or something like that but i couldn't find any.
|
|
|
|
|
I want to use the function DhcpRequestParams() to get some information from the DHCP Server,but failes.
Any can help me?
Examples are best.
|
|
|
|
|
|
<pre lang="text">Found this very useful piece of code to get bitmap info from handle and would like to know HOW it works.
I think if I get how the LPBITAMPINFO gets filled I probably will also understand why using global handle is necessary. Or maybe not.</pre>
// a DIB is in the clipboard, draw it out
GLOBALHANDLE hGMem ;
LPBITMAPINFO lpBI ;
void* pDIBBits;
OpenClipboard() ;
hGMem = GetClipboardData(CF_DIB) ;
ASSERT(hGMem);
TRACE("\nfills LPBITMAPINFO");
lpBI = (LPBITMAPINFO)GlobalLock(hGMem) ;
Appreciate any help.
CHeers Vaclav
-- modified 15-Jan-13 15:54pm.
|
|
|
|
|
GLOBALHANDLE hGMem ; LPBITMAPINFO lpBI ; void* pDIBBits;
OpenClipboard() ; hGMem = GetClipboardData(CF_DIB) ; ASSERT(hGMem); TRACE("\nfills LPBITMAPINFO");
lpBI = (LPBITMAPINFO)GlobalLock(hGMem) ;
At this point you can copy the memory block pointed to by lpBI into your program's address space and process it as required. You should then unlock and release hGMem (which is a system resource), and release the clipboard so other applications can use it.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard,
thanks for adding the comments.
I am still unclear how you get from HANDLE (pointer) - returned by GetClipboardData to BITMAPINFO (pointer).
I guess I still do not get the casting.
This may be to stupid , but why this would not work?
lpBI = (LPBITMAPINFO) GetCLipboardData(CF_DIB)
Maybe the key is really in usage of GLOBALHANDLE.
|
|
|
|
|
Vaclav_Sal wrote: Maybe the key is really in usage of GLOBALHANDLE. Exactly so. The GetCLipboardData() function returns a global handle, and you then need to use the GlobalLock() function to get a pointer to addressable memory. Remember that HANDLE s are 'opaque' types which you cannot use directly, even though they may at times point to some real memory. This is because they are owned by the Windows system and their contents at any one time is not guaranteed to be useful in user space.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
When I use ATL in MFC Application(Don't ask me why, just because I like), sometimes I got the error code: E_FAIL. However, it's almost useless for me to locate the specific reason.
I have googled so many times, but found nothing related. I thought there should be something like try{} catch{} in ATL.
Here's some sample code:
CAxWindow m_wndView; CComPtr<IWMPPlayer> m_spWMPPlayer;
AtlAxWinInit();
CComPtr<IAxWinHostWindow> spHost;
HRESULT hr;
CRect rcClient;
GetClientRect(&rcClient);
m_wndView.Create(m_hWnd, rcClient, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
hr = m_wndView.QueryHost(&spHost);
|
|
|
|
|
Use the _com_error class.
Construct an object of this class by passing in the HRESULT value and then use its WCode or ErrorMessage methods to get the error code mapped to the HRESULT value.
|
|
|
|
|
Thank you for your reply.
I have did as what you said, but I only get the error message:
Unspecified error.
Here is my code:
_com_error err(hr);
auto d = err.WCode();
auto s = err.Description();
auto msg = err.ErrorMessage();
|
|
|
|
|
'Unspecified error' is the english error message for E_FAIL . There is no more information available.
|
|
|
|
|
You can try with GetLastError and see if you can get better description of the error . The number returned from the function you can check in msdn.
Good luck 
|
|
|
|
|
Hi,
I have developed an application which captures video stream using DirectShow. While capturing, video is displayed on the canvas area. This works fine for the first time. But when again clicking on Start capturing button, video is getting captured, it doesn't display in the canvas area. Don;t know whether actually the camera is capturing the video or not.
Anybody have any idea regarding this.?
Any help will be appreciated.!
Regards,
mbatra
|
|
|
|