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