|
Please use your debugger to check where it crashes. Then, if you are not able to correct the problem, give us detailed information about the crash (where it crashes, what the problem is, ...)
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
When you trying to read:
...
UINT nRead = pFile->Read(szBuff, 1023);
...
your szBuff is NULL - initialize this buffer (i.e.: szBuff = new BYTE[1023]).
-----------
Mila
|
|
|
|
|
{
ShowBanner();
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << _T("MFC Failed to initialize.\n");
return 1;
}
if (argc < 2 || !ParseOptions(argc, argv) || pszURL == NULL)
ShowUsage();
int nRetCode = 0;
CTearSession session(_T("TEAR - MFC Sample App"), dwAccessType);
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
try
{
// check to see if this is a reasonable URL
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
if (!AfxParseURL(pszURL, dwServiceType, strServerName, strObject, nPort) ||
dwServiceType != INTERNET_SERVICE_HTTP)
{
cerr << _T("Error: can only use URLs beginning with http://") << endl;
ThrowTearException(1);
}
if (bProgressMode)
{
cerr << _T("Opening Internet...");
VERIFY(session.EnableStatusCallback(TRUE));
}
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(szHeaders);
pFile->SendRequest();
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
// if access was denied, prompt the user for the password
if (dwRet == HTTP_STATUS_DENIED)
{
DWORD dwPrompt;
dwPrompt = pFile->ErrorDlg(NULL, ERROR_INTERNET_INCORRECT_PASSWORD,
FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL);
// if the user cancelled the dialog, bail out
if (dwPrompt != ERROR_INTERNET_FORCE_RETRY)
{
cerr << _T("Access denied: Invalid password\n");
ThrowTearException(1);
}
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
}
CString strNewLocation;
pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
// were we redirected?
// these response status codes come from WININET.H
if (dwRet == HTTP_STATUS_MOVED ||
dwRet == HTTP_STATUS_REDIRECT ||
dwRet == HTTP_STATUS_REDIRECT_METHOD)
{
CString strNewLocation;
pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
int nPlace = strNewLocation.Find(_T("Location: "));
if (nPlace == -1)
{
cerr << _T("Error: Site redirects with no new location") << endl;
ThrowTearException(2);
}
strNewLocation = strNewLocation.Mid(nPlace + 10);
nPlace = strNewLocation.Find('\n');
if (nPlace > 0)
strNewLocation = strNewLocation.Left(nPlace);
// close up the redirected site
pFile->Close();
delete pFile;
pServer->Close();
delete pServer;
if (bProgressMode)
{
cerr << _T("Caution: redirected to ");
cerr << (LPCTSTR) strNewLocation << endl;
}
// figure out what the old place was
if (!AfxParseURL(strNewLocation, dwServiceType, strServerName, strObject, nPort))
{
cerr << _T("Error: the redirected URL could not be parsed.") << endl;
ThrowTearException(2);
}
if (dwServiceType != INTERNET_SERVICE_HTTP)
{
cerr << _T("Error: the redirected URL does not reference a HTTP resource.") << endl;
ThrowTearException(2);
}
// try again at the new location
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(szHeaders);
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
if (dwRet != HTTP_STATUS_OK)
{
cerr << _T("Error: Got status code ") << dwRet << endl;
ThrowTearException(2);
}
}
cerr << _T("Status Code is ") << dwRet << endl;
TCHAR sz[1024];
while (pFile->ReadString(sz, 1023))
{
if (bStripMode)
StripTags(sz);
cout << sz;
}
// NOTE: Since HTTP servers normally spit back plain text, the
// above code (which reads line by line) is just fine. However,
// other data sources (eg, FTP servers) might provide binary data
// which should be handled a buffer at a time, like this:
#if 0
while (nRead > 0)
{
sz[nRead] = '\0';
if (bStripMode)
StripTags(sz);
cout << sz;
nRead = pFile->Read(sz, 1023);
}
#endif
pFile->Close();
pServer->Close();
}
catch (CInternetException* pEx)
{
// catch errors from WinINet
TCHAR szErr[1024];
pEx->GetErrorMessage(szErr, 1024);
cerr << _T("Error: (") << pEx->m_dwError << _T(") ");
cerr << szErr << endl;
nRetCode = 2;
pEx->Delete();
}
catch (CTearException* pEx)
{
// catch things wrong with parameters, etc
nRetCode = pEx->m_nErrorCode;
TRACE1("Error: Exiting with CTearException(%d)\n", nRetCode);
pEx->Delete();
}
if (pFile != NULL)
delete pFile;
if (pServer != NULL)
delete pServer;
session.Close();
return nRetCode;
}
alantop
|
|
|
|
|
shuchigo_jane wrote: it gives me a "debug assertion failed" message...
Knowing what line of what file would go a long way towards solving the problem.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Hi Friend,
I am creating very basic C++ checklist for developer. I have include lots of comments however I am looking for more..... Can you please let me know some of your valuable comments.
Thanks
|
|
|
|
|
itkid wrote: very basic C++ checklist for developer.
Such as?! Would you mind listing one or two samples for us to get clearer what the check list is about? Then I can add some of mine.
Maxwell Chen
|
|
|
|
|
itkid wrote: I am creating very basic C++ checklist for developer
1. coding guidelines (formatting, naming, constructs to avoid, etc.)OK
2. comments (redundant, missing, consistency with code)OKNOK(function comments)
3. function/procedure/method sizeOK
4. defensive programming (memory management, exception handling, variable initialization, floating point calculations)OKNOK(exception handling )
5 correctness (program logic)OK.
6. maintainability OK
7. efficiency OK
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thank Alok,
You have given few very good point to think.
Regards
|
|
|
|
|
|
Hi,
I am using USB development kit and i have installed corresponding driver in my system to communicate with that Kit. From my program how can send and receive data. Is it like serial port communication or will it be differed? Is there any specific ports for this?
|
|
|
|
|
sivaprakashshanmugam wrote: Is it like serial port communication or will it be differed?
It's completely different. Basically, what you'll have to do is open the driver (with CreateFile function) and then, once you get the handle of your driver, you can send commands to the driver with DeviceIOControl.
If you get a USB development kit, then all the documentation should be supplied with the kit. Take a look at it.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
hi all,
I have created a diretory using CreateDirectorey function.
If i open a file rocky,then directory is created with the same name.
Everything is working fine.
But my problem is,If file name has space(Ex.Race car),then the directory is not created.
1.how to trim the space in between filename?
2.also it is taking only 10 characters.so if the filename is "AA000017060102021015",then directory is not created.
help me
cheers
sangeet
-- modified at 1:54 Wednesday 17th May, 2006
|
|
|
|
|
ramyasangeet wrote: But my problem is,If file name has space(Ex.Race car),then the directory is not created.
It works well in my code as:
if(!CreateDirectory("Race car", NULL)) {
AfxMessageBox("Error CreateDirectory.");
}
Maxwell Chen
|
|
|
|
|
I use the same coding.
if(!CreateDirectory("Race car", NULL)) { AfxMessageBox("Error CreateDirectory.");}
This is not creating directory with name Race car.
just i need to remove the space and i have to create directory with name like Racecar.
how to do that??
cheers
sangeet
|
|
|
|
|
Show me the error code.
if(!CreateDirectory("Race car", NULL)) {
DWORD ErrorCode = GetLastError();
CString sTxt;
sTxt.Format("Error code: 0x%08X", ErrorCode);
AfxMessageBox(sTxt);
}
Maxwell Chen
|
|
|
|
|
but it work
CreateDirectory("c:\\AA000017060102021015",NULL);
whitesky
|
|
|
|
|
i have mentioned my prgoram under and i am tryin to read the path where the acrobat reader is installed from the registry. though RegQueryInfoKey is returnin a positive result for the key, but when i query for Value 'Path' in the key the return value(szProductType) is empty
HKEY hKey = NULL;
LONG lRet = NULL;
char szProductType[1024] = { '\0' };
DWORD dwBufLen=1024;
LPDWORD Path;
int size = 8192;
LONG appExist;
TCHAR regPath[] = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppPaths\\AcroRd32.exe");
appExist = RegQueryInfoKey(HKEY_LOCAL_MACHINE,NULL,NULL,NULL,NULL,NULL,NULL,Path,NULL,NULL,NULL,NULL);
lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, (LPCWSTR)regPath, 0, KEY_ALL_ACCESS, &hKey );
lRet = RegQueryValueEx( hKey, (LPCTSTR) "Path", NULL, NULL, (LPBYTE) szProductType, &dwBufLen);
|
|
|
|
|
|
Hi
I want to add a contect menu on the right click of Recycle Bin Folder.
Please guide me how to do this.
Thanks
|
|
|
|
|
How To make Icon Background transperent.
|
|
|
|
|
in the windows desktop... which is possible in windows 2000 and above only. u just have to set the appearance of the desktop. in case u are makin the icon then u have to specify the area that u want to be transparent with a paricular color and add that color at the left top corner.
|
|
|
|
|
I want Mycomputer type of Icon,even After Changing background of the desktop the icon is visible in same fashion.
I am using VC++6,Is there any utility for making this type of custom icons.
With my Icons they are transperent with perticular color scheme only,otherwise
they are showing white square along with icon.
|
|
|
|
|
In VC++6, there is an image that looks like a computer monitor filled with cyan (it's in between the current color selections and black/white.
Left or right click on this, and then you can paint the pixels that should be transparent in your icon with the current tool.
Hope that helps.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
but what if I want to have a custom icon.
|
|
|
|
|
Maybe I'm mis-understanding your question.
Are you talking about customizing your application icon when your .exe is on the desktop? Just edit the IDR_MAINFRAME icon (or the first one on the list, I believe).
You can add different sizes and color depths of icons by clicking on the button to the right of the "Device" combobox. It should pull up a dialog box telling you what type of icon you can add, like 32x32 (256 colors), etc. Is that what you're looking for?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|