 |

|
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:28.
|
|
|
|

|
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:35.
|
|
|
|
|

|
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:54.
|
|
|
|

|
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 HANDLEs 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
|
|
|
|

|
You can debug to check if the code flow path is different from the first one in the second case.
If this doesn't help consider reinitialization of variables you are using before you display the video on the canvas.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|

|
Can you post some of your code? I am using VFW API and OpenCV and debugging real time video can be a challenge. What works for me is using temporary displays in step thru debug mode.
|
|
|
|

|
How to convert _uint64 into two _uint32 values and vice versa.
Regards,
Vishal
|
|
|
|

|
By shifting the high part and casting:
_uint64 ui64 = 1234;
_uint32 lo = (_uint32)ui64;
_uint32 hi = (_uint32)(ui64 >> 32);
ui64 = (_uint64)lo | ((_uint64)hi) << 32;
[EDIT:] Added code formatting.
|
|
|
|

|
does it take endianness into consideration, (Little/Big Endian)
Regards,
Vishal
|
|
|
|

|
Yes, because the endianess does not care for the used logical operations.
If you think of multiplication / division instead of the shift operations and of addition instead of the OR operation it should be clear. The operation values are just high or low parts where the internally used bit or byte order does not care. Casting is similar (extending with high zeroes upon up-casting and masking out the lower bits upon down-casting).
|
|
|
|

|
Thank you..
Regards,
Vishal
|
|
|
|

|
Here is another way to do it using the LARGE_INTEGER[^] union.
LARGE_INTEGER lint;
lint.QuadPart = 12345;
|
|
|
|

|
I too came across the union while using GetFileSize function.
does it produces same result in little endian and big endian systems.
as i want this for encryption section, where i had to convert 64bit unsigned integer to two 32 bit unsigned integer and vice versa,
So looking for results on little endian and big endian system result.
Regards,
Vishal
|
|
|
|

|
Yes, this will give you correct results irrespective of the endian-ness.
|
|
|
|

|
very very thank you sir.
Regards,
Vishal
|
|
|
|

|
I'm busy with my own http server implementation on an embedded platform. Technically the server is HTTP 1.0 compliant, and therefore it expects the the client to send the header "Connection: Keep-Alive" to keep the connection open.
The implementation looks like this. I removed the code that parses the HTTP header and performs the request, to keep the post as short as possible:
int Service_Request(int conn) {
struct ReqInfo reqinfo;
volatile int resource = 0;
int retval = 0;
Req_Result req_result = GOT_REQ;
InitReqInfo(&reqinfo);
while (req_result == GOT_REQ)
{
req_result = Get_Request(conn, &reqinfo);
if ( req_result == TIMEOUT_REQ)
{
retval = 0;
break;
}
else if (req_result == ERROR_REQ)
{
retval = -1;
break;
}
if (reqinfo.method == GET)
{
}
else if ((reqinfo.method == PUT) || (reqinfo.method == POST) )
{
}
else
{
reqinfo.status = 501;
Return_Error_Msg(conn, &reqinfo);
}
if(reqinfo.keep_alive == 0)
{
break;
}
reqinfo.keep_alive_max--;
if(reqinfo.keep_alive_max <= 0 )
{
break;
}
Writeline(conn,"\r\n",2);
FreeReqInfo(&reqinfo);
}
FreeReqInfo(&reqinfo);
return (retval);
}
The Get_Request function looks like this:
Req_Result Get_Request(int conn, struct ReqInfo * reqinfo) {
char buffer[MAX_REQ_LINE] = {0};
int rval;
fd_set fds;
struct timeval tv;
if(reqinfo->first_request == 1)
{
tv.tv_sec = 5;
tv.tv_usec = 0;
reqinfo->first_request = 0;
}
else
{
tv.tv_sec = reqinfo->keep_alive_timeout;
tv.tv_usec = 0;
}
do {
FD_ZERO(&fds);
FD_SET (conn, &fds);
rval = select(conn + 1, &fds, NULL, NULL, &tv);
if ( rval < 0 )
{
Diag_Msg("Error calling select() in get_request()");
return (ERROR_REQ);
}
else if ( rval == 0 ) {
return (TIMEOUT_REQ);
}
else {
memset(buffer,0,MAX_REQ_LINE - 1);
if(Readline(conn, buffer, MAX_REQ_LINE - 1) == -1)
{
return (ERROR_REQ);
}
if(reqinfo->clientRequest == NULL)
{
reqinfo->clientRequest = calloc(MAX_REQ_LINE - 1, sizeof(char));
strncpy(reqinfo->clientRequest,buffer,MAX_REQ_LINE - 1);
}
else
{
strncat(reqinfo->clientRequest,buffer,MAX_REQ_LINE - 1);
}
Trim(buffer);
if ( buffer[0] == '\0' )
break;
if ( Parse_HTTP_Header(buffer, reqinfo) )
break;
}
} while ( reqinfo->type != SIMPLE );
return (GOT_REQ);
}
To describe the workings of this server in English: The server receives the first request. It parses the headers, if it finds the "Connection: Keep-Alive" header, it sets a flag. The server proceeds to process this request. WHen it is done it checks the keep-alive flag. If it is cleared, the server closes the connection. If set the server performs a clean-up operation and the proceeds to wait for another request over the same connection. And so on.
I tested this with curl:
C:\curl>curl -v -H "Connection: Keep-Alive" --data-binary ( at )vid1.bin 10.84.67.129/s1p0:1/vid[1-2].bin
[1/2]: 10.84.67.129/s1p0:1/vid1.bin --> <stdout>
--_curl_--10.84.67.129/s1p0:1/vid1.bin
* About to connect() to 10.84.67.129 port 80 (#0)
* Trying 10.84.67.129...
* connected
* Connected to 10.84.67.129 (10.84.67.129) port 80 (#0)
> POST /s1p0:1/vid1.bin HTTP/1.1
> User-Agent: curl/7.28.1
> Host: 10.84.67.129
> Accept: **
> Connection: Keep-Alive
> Content-Length: 51200
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
* HTTP 1.0, assume close after body
< HTTP/1.0 100 Continue
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: DTSVU v0.1
< Content-Type: text/html
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Keep-Alive: timeout=5, max=10
<
* Connection #0 to host 10.84.67.129 left intact
* Closing connection #
As you can see, curl says: Connection #0 seems to be dead! after the first request is completed. It then proceeds to close the connection and opens a new one. I'm sure I implemented the HTTP 1.0 keep-alive functionality correctly. SO my question is: what does curl expect over the connection after the first request is completed? Why does it decide the connection is dead?
PS the above code was adapted from http://www.paulgriffiths.net/program/c/webserv.php
|
|
|
|

|
This does not really have anything to do with C/C++; you may get a better response in the Web Development forum[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
Sorry about about posting in the wrong forum. Could a moderator please move it?
I solved it myself. If the server replies with HTTP/1.1 and "Content-Length: 0", curl reuses the connection. My server reply lookes like this
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Server: DTSVU v0.1
Content-Type: text/html
Connection: Keep-Alive
Keep-Alive: timeout=1, max=95
Content-Length: 0
after the 5th reuse of the connection.
|
|
|
|

|
Hi
I'm having trouble trying to load a non-default .wab file (I know it's old hat but need to keep it going for my XP users). I'm running it on Vista and although I'm supplying a filename it keeps loading my Vista Contacts instead instead of the specific wab addresses.
It must be going wrong around here (mostly stock code from the msdn sample code):
// (pszFileName is const char *)
if(m_hinstWAB)
{
// if we loaded the dll, get the entry point
//
m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");
if(m_lpfnWABOpen)
{
HRESULT hr = E_FAIL;
WAB_PARAM wp = {0};
wp.cbSize = sizeof(WAB_PARAM);
wp.szFileName = (LPTSTR) (LPCTSTR) pszFileName;
// if we choose not to pass in a WAB_PARAM object,
// the default WAB file will be opened up
//
if(m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0)==S_OK)
m_bInitialized = TRUE;
}
As usual, any help much appreciated.
Greg
|
|
|
|

|
Why is this conversion needed:
Member 868926 wrote: wp.szFileName = (LPTSTR) (LPCTSTR) pszFileName; ?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|

|
Good point, well I'm now trying:
wp.szFileName = "C:\\Jim.wab";
as I know that wab exists there but it still isn't loading it.
G
|
|
|
|

|
Are you completely sure that is a correct WAB file and it is readable by the process (it has the required access rights and somesuch)?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|

|
Yes the wab is OK. If you doubleclick it Windows asks if you want to import the addresses.
Somehow the WabOpen bit just thinks I want the default Wab (although there isn't one in Vista) and isn't getting the filename. In the original code there was a 'GetNativePath()' call which isn't available - could it be to do with how I'm passing in the file location string?
G
|
|
|
|

|
As far as i remember the documentation says it will load the default if you pass NULL for the path, but you are not passing NULL but a seemingly correct path. Hmm...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|

|
If i check the documentation (http://msdn.microsoft.com/en-us/library/ms629458%28v=vs.85%29.aspx[^]) for WAB_PARAM, the szFileName member is declared to be LPTSTR. This suggests that depending on your target options, it might be a unicode or an ansii/mbcs string which then suggests that there might be a unicode and an ansii/mbcs version of the function (as with a lot of API methods throughout windows). When you query the function's pointer...are you sure you are getting the correct version?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|

|
I'm not sure - in the header file I can't see another version except WabOpenEx which I tried but didn't work.
I've noticed that my Contacts folder is actually receiving the wab addresses and getting bigger and bigger! So instead of opening the wab on its own it's adding them to the Contacts then opening those instead. Is this some undocumented Vista mechanism?
Thanks very much for everyone's conttributions so far.
G
|
|
|
|

|
Frankly, i don't know, sorry... > The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|

|
- Have you checked the actual error code returned from the
WABOpen Function?
- Have you checked the documentation[^] for compatibility?
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
It doesn't return an error, just loads my Vista Contacts instead. Compatability seems OK.
|
|
|
|

|
Have you tried removing the default contacts file to see if it works then? It's a long while since I used WAB and I never actually tried using the non-default file.
One of these days I'm going to think of a really clever signature.
|
|
|
|
 |