|
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!
|
|
|
|
|
jtasph wrote: I don't know what's the meaning of "0x33, 0xC0, 0xC2, 0x04, 0x00". Who does understand the code?
An assembly programmer might recognize those bytes as:
__asm
{
xor eax,eax
ret 0x4
}
But unfortunately its hard to find one these days. They are like the dinosaurs and are nearly extinct.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks Randor for your explanation. Do you know what's the meaning of these assembly codes and how the codes to disable the SetUnhandledExceptionFilter function called by CRT? Do these assembly codes depend on platform? Thanks!
|
|
|
|
|
jtasph wrote: Do you know what's the meaning of these assembly codes and how the codes to disable the SetUnhandledExceptionFilter function called by CRT?
Yes, it overwrites the instructions in memory with new instructions. This causes SetUnhandledExceptionFilter to immediately return.
jtasph wrote: Do these assembly codes depend on platform?
Yes, it is 32 bit assembly instructions.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: They are like the dinosaurs and are nearly extinct.
I thought the dinosaurs *are* extinct.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Some of us dinosaurs have survived. We are like the Coelacanth[^].
Best Wishes,
-David Delaune
|
|
|
|
|
Rajesh R Subramanian wrote: I thought the dinosaurs *are* extinct.
You're actually wrong. There's one of them, for instance, they call Norton-Antivirusex that grabs all the system resources making more damages the viruses could ever do. There is the Eclipsosaurus too, the name comes because it eclipses all your machine power.
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]
|
|
|
|
|
CPallini wrote: Norton
Excuse me? We aren't talking about pigs, are we?
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Yes pigs on the wings! Or maybe the great pig in the sky...
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]
|
|
|
|
|
jtasph wrote: I don't know what's the meaning of "0x33, 0xC0, 0xC2, 0x04, 0x00".
As David said, it is hex code for "return 0;" . So after you do that WriteProcessMemory (), the SetUnhandledExceptionFilter () will not work any maore it will simply reurn 0. Not only for CRT calls for you also( I am not sure when CRT calls this function. If it has called the SetUnhandledExceptionFilter() before you disable it, the CRT exception handler will work ).
However I suspect the necessity of supressing the CRT exception trough the above method. I guess the you can use the _set_abort_behavior () to control the exception handler of CRT.
More over there is AddVectoredExceptionHandler () function which will be executed before the exception handler specified in SetUnhandledExceptionFilter ().
|
|
|
|
|
Naveen wrote: However I suspect the necessity of supressing the CRT exception trough the above method. I guess the you can use the _set_abort_behavior() to control the exception handler of CRT.
I found out some introdution about exception handling mechanism in VS2005.
There're 3 kinds of checks in CRT code that pass around and invoke Dr.Watson directly.
1.One is when we have detected a buffer overrun (/GS failure). For security reasons in this case, we directly call the UnhandledExceptionFilter.
2.Another is when we detect an invalid parameter before a bad situation occurs.
3.A third are other abnormal terminations (purecall, unexpected, etc). These generally have their own handlers that you can set (_set_purecall, _set_terminate, _set_unexpected). These exist only in cases where we consider it safe to do so.
_set_abort_behavior, signal(SIGABRT, ...), and _set_invalid_parameter_handler(...) functions allow to intercept in case 2 and case 3. But for case 1, we can set api hook.
Is it right?
|
|
|
|
|
jtasph wrote: functions allow to intercept in case 2 and case 3. But for case 1, we can set api hook.
Hmm..Seems there is no way to control the first one. Did you check the AddVectoredExceptionHandler()? With that i guess there is no need to block any other SEH filters. Here [^]is an excellent article about vectored exception handing written by Matt Pietrek.
|
|
|
|
|
jtasph wrote: 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.
Add the following code to your project and tell me if your exception handler works:
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
Best Wishes,
-David Delaune
|
|
|
|
|
I added "SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);" but it does not work.
|
|
|
|
|
Thanks for all answerers. Here is my test code:
LONG WINAPI MyUnFilterA (struct _EXCEPTION_POINTERS *lpExceptionInfo)
{
AfxMessageBox(_T("11"));
return EXCEPTION_CONTINUE_SEARCH;
}
1.
void CExceptionDlg::OnBnClickedOk()
{
SetUnhandledExceptionFilter(MyUnFilterA);
DisableSetUnhandledExceptionFilter();
*(int *) 0 = 0;
}
2.
void CExceptionDlg::OnBnClickedOk()
{
SetUnhandledExceptionFilter(MyUnFilterA);
DisableSetUnhandledExceptionFilter();
abort();
}
3.
void CExceptionDlg::OnBnClickedOk()
{
AddVectoredExceptionHandler(1, MyUnFilterA);
*(int *) 0 = 0;
}
4.
void CExceptionDlg::OnBnClickedOk()
{
AddVectoredExceptionHandler(1, MyUnFilterA);
abort();
}
When I pressed button OK, an excepiton will occur. Case 1 and case 3 are the same result. That is,
MyUnFilterA will be be called and a messagebox will pop up and show the text "11". And after the messagebox is closed, the application exits. Case 2 and case 2 are the same result. An error dialog will pop up first and ask me "Abort", "Retry" or "Ignore". If select "Retry", the message box "11" will show. Otherwise, the application will exit.
I think it's better pop up my defined message box first. What should I do?
modified on Thursday, October 22, 2009 5:32 AM
|
|
|
|
|
Hi, can someone help me out with CFile Read mode. I want to read from a txt file and place it in the format below. My code give me error. Can't read at all.
My code
CStdioFile f1;
CString f1_txt;
f1.Open("C:/abc", CFile::modeRead);
int len = f1.GetLength();
f1.Read(f1_txt, len);
_tscanf(f1_txt, "%lf %lf %lf\n", &a, &b, &c);
....
....
....
f1.Close();
f1.Flush();
Can someone help me out with this? Need to read in this "%lf %lf %lf\n", &a, &b, &c) format.
Thanks alot.
|
|
|
|
|