|
Hi there,
The following example ist intended to transfer the data of a structure SKupParam from a uC to the PC. How can I reset the pointer *pKupParam to its orginal value after I have received the data, if this has to be in another method? Or how can I declare the pointer global?
<br />
LONG CKupDlg::OnCommunication(WPARAM ch, LPARAM port) {
static unsigned char *pKupParam = (unsigned char *) &gKupParam; <br />
*pKupParam++ = ch;<br />
return 0;<br />
}<br />
<br />
|
|
|
|
|
I'm having a bit of an issue with sending data through HTTPS via wininet in a C++ test app:
I can download any page through HTTP with:
InternetOpen( ..., dwFlags )
InternetOpenUrl( ..., "http://...", ..., dwFlags, 0 )
InternetReadFile( ... )
I can download a secured page through HTTPS with the same code with the following changes:
InternetOpen( ..., dwFlags | INTERNET_FLAG_SECURE )
InternetOpenUrl( ..., "https://...", ..., dwFlags | INTERNET_FLAG_SECURE, 0 )
InternetReadFile( ... )
At that point my buffer contains the plain/decrypted text, while a packet sniffer only shows encrypted data, telling me that indeed the encryption/decryption happens transparently as far as my program knows.
I can upload a binary file through HTTP with:
(read file content in some buffer, lpvBuffer)
InternetOpen( ..., dwFlags )
dwPort = INTERNET_DEFAULT_HTTP_PORT
InternetConnect( ..., lpszServer, dwPort, NULL, NULL, INTERNET_SERVICE_HTTP, dwFlags, ... )
HttpOpenRequest( ..., "POST", lpszPage, ..., dwFlags, 0 )
HttpSendRequest( ...,
NULL, // no custom header
0, // so its size isn't needed
lpvBuffer, // content of my file
dwSizeOfBuffer ) // size of my file/buffer
lpvBuffer is the content of my binary file, and dwSizeOfBuffer is its size. I've confirmed that the server correctly receives the file at the other end, and saves it back into a binary file--windiff says they're identical. Great. Everything so far works.
Now...my ultimate goal...after all these successful tests...is to upload a binary file through HTTPS...
I thought it would be a simple matter of setting the INTERNET_FLAG_SECURE flags again, setting dwPort to INTERNET_DEFAULT_HTTPS_PORT, and going through the same code as shown above (the last snippet)--but it doesn't work. My client appears to send the data and then sits on HttpSendRequest(), waiting for it to return, and eventually times out (ERROR_INTERNET_TIMEOUT).
I suspect that the size of the data being actually transmitted over the wire doesn't match the size I specify (dwSizeOfBuffer--the size of my file), since it's now being sent through HTTPS (and not plain HTTP), so--? this is speculation on my part ?--the server is waiting for more data to be sent than I specify in dwSizeOfBuffer, while the client's actually done, so it's also waiting on the server...eventually the client times out.
My initial assumption was that as far as my program is concerned, I shouldn't even have to worry about specifying the size of the *encrypted* buffer, and I should only have to specify the size of my actual file (the fact that it's now going through HTTPS should be transparent to the layer I'm working at). If that's the case...then I don't understand why HttpSendRequest() returns only after timing out...
It doesn't make sense to me that I'd have to even *know* the size of the encrypted data that would follow the HTTP header. I don't even have any idea what that size is, so I can't accurately set dwSizeOfBuffer myself (HttpSendRequest()'s last parameter). The API lets you specify -1 for the size of the custom header buffer (parameters 2 and 3), and it'll figure out the actual size by looking for a terminating NULL, but this won't work here because my stream (lpvBuffer) is a binary file and NULLs (ASCII-0) can appear anywhere. Besides, the documentation doesn't imply that the API can figure out the size of lpvBuffer on its own, which makes sense because whatever follows the HTTP header could be anything, not just NULL-terminated strings...
On the server side...I have a simple .ASP page that saves whatever's returned in Request.ReadBinary() into a file. As mentioned, that works fine for plain HTTP.
Any thoughts?
|
|
|
|
|
You should have a custom header. eg
Content-Length: <plain-data length="">
HttpSendRequest will not generate the content-length for you.
|
|
|
|
|
> You should have a custom header. eg Content-Length:
>
> HttpSendRequest will not generate the content-length for you.
Are you sure about this? I'm not setting a content-length header, and in HTTP mode, my packet sniffer (Ethereal) shows that a Content-Length header has indeed been generated, with the length I specified in HttpSendRequest()'s dwOptionalLength parameter. The file gets there and a binary comparison shows that it's identical to the one I sent.
I just need to do the same with HTTPS. I'm not sure why the header would be required in this case but not the former. Regardless, I tried to do it explicitely with HttpAddRequestHeaders(), and got the exact same results...
-- modified at 8:44 Thursday 23rd March, 2006
|
|
|
|
|
"MF",
I hate to answer my own post, but I got it to work.
Turns out it's got nothing to do with Content-Length headers.
I was specifying the IP address of my server instead of its domain name. Since the certificate, apparently, is considered by the client to be valid only if it *exactly* matches the domain name (www.whatever.com), *something* just sat there until my client timed out. If you do the same with IE, it warns you that the name doesn't match, but asks you whether you want to continue anyway. If you specify the exact name matching what the certificate was issued for, IE doesn't give you the warning--that's what clued me in.
I now consider myself slightly more educated. Thanks for your assistance, even though it didn't turn out to be the root cause of the problem (I *still* don't specify any length besides the size of the Optional parameter, and it works fine)...
|
|
|
|
|
Hi,
I am using a MCC object in my MFC program which receives input from the serial port. An event on the port occurs whenever it receives buffer of length 5. The port settings are - RThreshold=5, SThreshold=0,InputLen=5. In this setting, I can read only 5 characters at a time at max and till now our requirements are fullfilled. But now, we want to receive a string of characters of length say 25 and at the same time it should be able to receive and read 5 character length strings from input buffer. So, atlast I have to make the port as dynamic so that it can read any length of strings (i.e. strings of 5 characters and also strings of more than 5 characters). I am thinking of using a delimiter and setting the InputLen to say 25 and reading the input buffer untill I see a delimiter. But I am not sure about the settings of 'Buffers' attributes (namely RThreshold, SThreshold and InputLen).
It would be great if someone can help me out in this issue.
thanks,
-Pav
|
|
|
|
|
Hi everyone,
I have a quite misterous problem. I am developing a windows application which is using the serial port for data transfere. I have developed a serial class based on the MSDN article Serial Communications in Win32. My application uses asnychron communication with overlapped structure.
The communication at the first sight is OK. But if there are more copies of my applications are running on the same PC using DIFFERNET serial ports, after few day of running and receiving datas suddenly appears the following messagebox by each one of the application at the same time:
Runtime Error! Program: myapp.exe This application has requested the Runtime to terminate it in an unusual way.
Each one of the applications stops receiving datas through the serial port, but their GUI is still active. As soon as I press the OK button on the dialog, each application closes.
I have succeed to figure out, that there is some kind of memory leak. The memory grows slowly and when it comes to certain point the Runtime error messagebox appears. Since the messagebox is on the the command returns an error:
OVERLAPPED osReader = {0};
osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
I guess I have to have some problem in the receiving routine. I went through my code several times but I couldn't find the error. There are 3 threads running 1 for the GUI, 1 for the serial data receiving and 1 for the serial data processing. The data are transfered between threads with deques.
What is very strange this error only happens if more than 1 of my applications are running. By 1 application everything is OK and the memory also stays at the same level.
Here is the receiving routine:
int UModulSerial::ReceiveVoid(LPVOID Buffer, int &NumberOfBytesToRead)
{
if (m_bOverlapped)
{
CMutex mutRead;
CSingleLock lock(&mutRead,TRUE);
m_sError = "";
m_iErrNumber = 0;
DWORD NumberOfBytesReceived=0;
OVERLAPPED osReader = {0};
osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (osReader.hEvent == NULL)
{
SetErrorMessage(ERROR_CREATING_EVENT);
return -1;
}
int Read_Error = ReadFile
(
m_hSerPort,
Buffer,
NumberOfBytesToRead,
&NumberOfBytesReceived,
&osReader
);
if (!Read_Error)
{
DWORD LastErrorCode = GetLastError();
if (LastErrorCode == ERROR_IO_PENDING)
{
DWORD dwRes = WaitForSingleObject(osReader.hEvent, m_Comtimeout.ReadTotalTimeoutConstant);
switch(dwRes)
{
case WAIT_OBJECT_0:
if (!GetOverlappedResult(m_hSerPort, &osReader, &NumberOfBytesReceived, FALSE))
{
SetErrorMessage(GetLastError());
CloseHandle(osReader.hEvent);
return -1;
}
else
{
if(NumberOfBytesToRead != NumberOfBytesReceived)
{
NumberOfBytesToRead = NumberOfBytesReceived;
SetErrorMessage(ERROR_TIMEOUT);
CloseHandle(osReader.hEvent);
return -1;
}
}
break;
case WAIT_TIMEOUT:
SetErrorMessage(ERROR_TIMEOUT);
CancelIo(m_hSerPort);
GetOverlappedResult(m_hSerPort, &osReader, &NumberOfBytesReceived, FALSE);
if (NumberOfBytesToRead != NumberOfBytesReceived)
{
CloseHandle(osReader.hEvent);
NumberOfBytesToRead = NumberOfBytesReceived;
return -1;
}
else
break;
break;
default:
SetErrorMessage(-1);
CloseHandle(osReader.hEvent);
return -1;
break;
}
}
else
{
SetErrorMessage(GetLastError());
CloseHandle(osReader.hEvent);
return -1;
}
}
CloseHandle(osReader.hEvent);
if(NumberOfBytesToRead != NumberOfBytesReceived)
{
NumberOfBytesToRead = NumberOfBytesReceived;
SetErrorMessage(ERROR_TIMEOUT);
return -1;
}
return 0;
}
Any help or comments are highly appriciated.
Greetings
Attila
|
|
|
|
|
I have finaly (after blood sweating) found the problem. There was a Handler overflow, that's why my program crashed.
The problems was with the CreateEvent(NULL, TRUE, FALSE, NULL) for the overlapped structure.
Each time I was calling the receiving function I wasa allocating a handler for the Overlapped hevent:
OVERLAPPED osReader = {0};
osReader.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
Each time I created an event for the ovrelapped.hevent structure the handle was allocated but not deallocated. Don't ask me why. I was correctly using the CloseHandle function to the handle but it didn't work (maybe I have an additional bug in my code).
So my (ugly) solution is that I allocate the handle osReader as a member variable of my Serial class, create it in only once in the constructor and now it seems to work.
|
|
|
|
|
Hi all,
I want to work with WINDOWS DDK. Where can I download it?
For Windows XP SP2
Cheers,
Thanks.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
You can purchase a CD here:
http://www.microsoft.com/whdc/devtools/ddk/orderddkcd.mspx[^]
Alternatively, MSDN subscribers can download it. From the Microsoft WHDC website:
Note: The current DDK is not offered as a download on the WHDC Web site, but it is part of the standard MSDN Subscriber Downloads and is included with MSDN subscriptions.
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
I am writing a program that uses a file that is opened by another process
for writing in shared mode. I open the file for read-only, shared access
and periodically check the file to see if it has changed. If it has, I read
in the new data and do something with it. I'd like to know when the other
process closes its handle to the file so that I can stop my periodic
processing and then delete the file, because I don't need it anymore. Is
there a way to know when the other process closes the file?
Barry
|
|
|
|
|
I'd suggest that when the file hasn't changed, to then close your handle and try to delete. If it works, great, if it fails, check to see if its a share violation. When it is, then sleep and upon wakeup try the delete again. Repeat as required. This is polling oriented instead of notification oriented, but it should work. I don't think there is a notification event for a file handle being closed. (But I'm sure a wiser one will point this out )
Chris Meech
I am Canadian. [heard in a local bar]
When I want privacy, I'll close the bathroom door. [Stan Shannon]
BAD DAY FOR: Friendly competition, as Ford Motor Co. declared the employee parking lot at its truck plant in Dearborn, Mich., off limits to vehicles built by rival companies. Workers have to drive a Ford to work, or park across the street. [CNNMoney.com]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
I want to add the desktop folder in the treeview.For that I think ShGetDesktopFolder function should be used.I searched in online MSDN but no help for this function is given.
Please help me.
Thanks
|
|
|
|
|
there are too few informations in your question to understand well what you want.
however, why did you put VC.NET 1.1 in the title ? are you using managed C++ ? is so, ask your question in the Managed C++ forum[^]
|
|
|
|
|
|
I am writing a program in c++ and I want to use a struct to group together some information but I don't need to make a full class for it since it only has 4 primitive fields in it and doesn't need data hiding or methods. I was wondering if it would be more efficient to use C linkage rather than just declaring a struct in c++ because I don't want the overhead of constructors destructors, methods, etc. The two ways I could do this are listed below. can you tell me if the one with C linkage will be smaller. My program needs to be as efficient as possible.
extern "C" {<br />
typedef struct<br />
{<br />
float velX;<br />
float velY;<br />
float velZ;<br />
float b;<br />
} FluidInfo;<br />
}
or
struct FluidInfo<br />
{<br />
float velX;<br />
float velY;<br />
float velZ;<br />
float b;<br />
};
pplshero54 gives his most thanks
|
|
|
|
|
i doubt that C linkage will change anything to the size, but you could do the test by yourself using the operator sizeof()
FluidInfo fi;
int structSizeInBytes = sizeof(fi);
moreover, do you know that you can make a class without data hiding ?
just add a public declarator before declaring your data members...
|
|
|
|
|
|
hi,(sorry if this is in wrong forum)
i am from bangalore,india.
i am applying for steady job in different companies.they ask me my expectation.i dont know.
please help me.also please tell me what ctc means and also other jargons.
i have been freelance sw developer for 4 years in vc++ and have done around 4 software packages,for engineering applications, all alone, for govt orgs.
i am very good in sw development and know several languages.i also heve exp in embedded systems.
although i am be mech,i am equally good in all the 3 domains.
-thanx.
-vmmt
|
|
|
|
|
|
v2.0,
You're working too cheap :p
|
|
|
|
|
oh maybe it's because i'm not an exp developer yet...
(actually i am, but not for my office )
|
|
|
|
|
Er zit een korstje op mijn aars.
|
|
|
|
|
I'm not interested in that certain piece of your body
No hurries, no worries.
|
|
|
|
|
it wasn't for you though
|
|
|
|
|