|
ravi 12 wrote: can you please give me the whole correct code ?
No because that wouldn't serve any purpose. Instead, I'll point you to some good articles about STL, you can check this section[^] on codeproject.
Of course, that will require some time to learn but it is definitively something that you will use a lot in the future, so the time investement will pay back later.
I suggest you document yourself about std::string and std::list, that's what you will need for this project. Don't forget that google is your friend and you can search for tutorials on the net.
|
|
|
|
|
thanks Cedric Moonen.....for your suggestion
|
|
|
|
|
Cedric Moonen wrote: Of course, that will require some time to learn
He seems to have lots of time considering he spent 11 days figuring out that he's unable to use FindFirstFile()/FindNextFile(). See his previous posts.
|
|
|
|
|
This has been painful to watch. On the flip side, it has given me an idea for an article.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
unsigned long i;
short s;
signed char c;
i = (s<<15) + (c <<9);
How will type conversion take place in this case?
Is it that:
1. s will remain short(2 bytes) thus shifting the LSB into the MSB and remaining bits turn 0; c is promoted to short then left-shift 9 performed. The final R-value is promoted to unsigned long and saved into i.
or
2. s and c both get converted to unsigned long before performing the shift operation (thus we do not lose any of the left-shifted bits)
or something else happens.
I tried it in VS6.0 and the result seem to indicate that in both s and c I did not lose any bit upon left-shifting as if s and c acted as if they were a 4-byte data type (long or int)
|
|
|
|
|
All shifts take place in a register.
The registers are 32-bit in a 32-bit OS.
So even though the shift overflows the variable, it will still remain in the register.
That's the reason you don't loose any bits.
|
|
|
|
|
I understand that the shifts take place in registers but then the evaluated values have to be stored back into their respective variables, which are of type short and char, which cannot hold 4-byte values.
|
|
|
|
|
Ralph_2 wrote: but then the evaluated values have to be stored back into their respective variables
Nope. Why do you think that?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
If I have a char variable and I perform left-shift 4 times I lose the 4 MSB bits
For instance,
unsigned char c = 4;
c= c<<2;
c= c<<4;
So here 1 gets shifted outof the MSB
|
|
|
|
|
Do you mean to say that since these are R-values they themselves do not get modified.
Well, yes, my mistake. R-values will not be altered. My statement is incorrect. So now that we are talking at register-level then where and how does C's rules of type conversion come into picture?
|
|
|
|
|
Without talking about registers, types promotion occurs because of (in the original expression) the assignment was done to an integer.
[edit]
actually, running the following code
unsigned int u = 0xFFFFFFFF;
unsigned long long ul = (u << 8);
make me think the above expression cannot be true
[/edit]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Thursday, October 22, 2009 4:08 AM
|
|
|
|
|
In the book C-The Complete Reference by Herbert Schildt theree is an example
char ch;
int i;
float f
double d;
result=(ch/i)+(f*d)-(f+i)
Here it does not talk about the data type of the variable "result". In any case, the conversion here is as follows: First ch is converted to int since i is int, then ch/i is performed. The result of ch/i is then converted to double as f*d is double. The final value is a double.
Now if "result" is type float then the final value will be truncated to float and stored in "result", isnt it?
CPallini wrote: types promotion occurs because of (in the original expressio) the assignment was done to an integer.
As we see in the above example the variable to which the final value is assigned, its type matters only when we have solved the expression on the right side.
Please correct me if wrong anywhere.
The mentioned book also says:
"First, all char and short int values are automatically elevated to int"
This seems to be the reason why I don't lose the shifted out bits and also because I store the value back in an unsigned long
modified on Thursday, October 22, 2009 4:51 AM
|
|
|
|
|
Ralph_2 wrote: Now if "result" is type float then the final value will be truncated to float and stored in "result", isnt it?
Yes (and the compiler warns about).
Ralph_2 wrote: As we see in the above example the variable to which the final value is assigned, its type matters only when we have solved the expression on the right side.
Yes. As I added in my previous post, you're right and looks like registers matter...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ralph_2 wrote: "First, all char and short int values are automatically elevated to int"
Yes, and it is also explained here [^].
I didn't know int had such a special role.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for your assistance.
So the answer to my question is "Integral promotion"
Now, if only int were 2-bytes then I lose the left-shifted bits and will have a different result for unsigned long = (short<<15) + (char<<9) .....Ahem, i hope this is right now
|
|
|
|
|
This is the assembly output for the statement i = (s << 15) + (c << 9);
movsx eax, WORD PTR _s$[ebp]
shl eax, 15 ; 0000000fH
movsx ecx, BYTE PTR _c$[ebp]
shl ecx, 9
add eax, ecx
mov DWORD PTR _i$[ebp], eax
So as you can see nothing is stored back into any variable.
The two shifts happen in the eax and ecx registers.
It is then added together and the stored into the variable i, which is also 4 bytes in length.
|
|
|
|
|
please have look on the msdn [^]
Величие не Бога может быть недооценена.
|
|
|
|
|
It's little strange for me. I m using CInternetSession, CHttpConnection, CHttpFile classes to make an http request.
It works fine most of time and response comes with status code 200.
But few times response comes with status code -1 (a negative value)
When this happens then it continue to happen for some time so I get -1 for some time.
Can any one tell me when -1 comes, so that I can handle it accordingly.
|
|
|
|
|
Hi,
Negative 1 is not a valid HTTP response code. I would be willing to bet that SendRequest or OpenURL is failing beforehand.
Best Wishes,
-David Delaune
|
|
|
|
|
Thats why I am also surprised. I know, it is not a valid response. I will try to give more info when it will be available. I am currently digging that. This happens occasionally so it is hard to debug and detect.
|
|
|
|
|
Hi,
Did you solve this issue? I would suggest wrapping your CInternetSession code in a try/catch block.
<pre>try
{
}
catch (CInternetException* pEx)
{
switch(pEx->m_dwError)
{
case ERROR_INTERNET_TIMEOUT:
break;
case ERROR_INTERNET_NAME_NOT_RESOLVED:
break;
case ERROR_INTERNET_CANNOT_CONNECT:
break;
default:
break;
}
pEx->Delete();
}</pre><br />
<br />
<br />
Best Wishes,<br />
-David Delaune
|
|
|
|
|
Thanks Randor! I will sure do that. Currently I am not getting that -1.
My new problem is that my program(exe) in not able to connect to internet if it is inside a proxy. How can I deal with proxy?
|
|
|
|
|
Hi,
You can use the InternetCheckConnection Function[^] to check if internet access is available. If you need to connect through a proxy then you can use the INTERNET_OPEN_TYPE_PROXY flag in your CInternetSession constructor. The following documentation may be useful to you:
Enabling Internet Functionality[^]
Best Wishes,
-David Delaune
|
|
|
|
|
 Hi Randor,
I am getting http response code = 407 while using proxy. I know it is for proxy authentication. I wrote the following code. Can you tell me where is my mistake.
std::string responseData("");
DWORD statusCode;
CInternetSession iSession = CInternetSession(L"My Application",1,INTERNET_OPEN_TYPE_PROXY, L"http://proxy.mycompany.com:8080");
CHttpConnection *httpConnection = NULL;
CHttpFile *httpFile = NULL;
char userName[] = "myUsername", password[] = "myPassword";
try
{
iSession.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_CONTROL_SEND_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_DATA_SEND_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_SEND_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_PROXY_USERNAME, userName, strlen(userName) + 1);
iSession.SetOption(INTERNET_OPTION_PROXY_PASSWORD, password, strlen(password) + 1);
httpConnection = iSession.GetHttpConnection(CString("subdomain.maindomain.com"), (INTERNET_PORT) 443);
httpFile = httpConnection->OpenRequest(L"POST", CString("/somepage/"), 0, 1, 0, 0, INTERNET_FLAG_SECURE);
httpConnection->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, (int)1000000000);
CString strHeader;
int contentLength =0;
strHeader = "Content-Type: application/x-amf";
httpFile->AddRequestHeaders(strHeader);
strHeader.Format(L"Content-Length: %d", contentLength);
httpFile->AddRequestHeaders(strHeader);
BOOL x = httpFile->SendRequest(NULL, 0, NULL, contentLength);
httpFile->QueryInfoStatusCode(statusCode);
if(statusCode != 200)
{
responseData = "";
}
char fileData[1024];
int len;
while((len = httpFile->Read(fileData, 1024)) > 0)
responseData.append(fileData, len);
}
catch(CException *ex)
{
WCHAR str[500];
DWORD errorCode = GetLastError();
ex->GetErrorMessage(str, GetLastError());
}
I am using AMF so I specified 443 port while my proxy is using 8080 port.
|
|
|
|
|
I want to log some information before the application crashes. I find the function SetUnhandledExceptionFilter() in MSDN, which enables an application to supersede the top-level exception handler of each thread and process. I'm not sure whether it can catch all exception in a MFC application or not.
I also found some articles about SetUnhandledExceptionFilter in VS2005. It seems that we need to disable the SetUnhandledExceptionFilter function called by CRT. The code is as follows:
void DisableSetUnhandledExceptionFilter()
{
void *addr = (void*)GetProcAddress(LoadLibrary(_T("kernel32.dll")),
"SetUnhandledExceptionFilter");
if (addr)
{
unsigned char code[16];
int size = 0;
code[size++] = 0x33;
code[size++] = 0xC0;
code[size++] = 0xC2;
code[size++] = 0x04;
code[size++] = 0x00;
DWORD dwOldFlag, dwTempFlag;
VirtualProtect(addr, size, PAGE_READWRITE, &dwOldFlag);
WriteProcessMemory(GetCurrentProcess(), addr, code, size, NULL);
VirtualProtect(addr, size, dwOldFlag, &dwTempFlag);
}
}
I don't know what's the meaning of "0x33, 0xC0, 0xC2, 0x04, 0x00". Who does understand the code?
In addition, when I debug the code to catch exception, a exception dialog will ask me "Abort, Retry or Ignore". If I select "Abort" or "Ignore', my defined exception funciton will not call. Instead I want it will be called in any case.
So is there some solution for my requirement? Thanks!
|
|
|
|
|