|
I am using CInternetSession, CHttpConnection, and CHttpFile to get a file
from an HTTP server.
I am having a problem though determining if the initial connection succeeded
or not. If the server is 'off' then the code seems to execute despite my
'ifs' and produces an exception. If I put the statement throwing the
exception into a try-catch, it isn't caught, and crashes the program anyway.
CInternetSession net;
CHttpConnection* http = NULL;
CHttpFile* file = NULL;
http = net.GetHttpConnection("cabadam.homeip.net");
if (http == NULL)
{
status += "Failed to connect to server!\r\n";
dlg->edit_status.SetWindowText(status);
dlg->GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(1);
return 1;
}
file = http->OpenRequest(CHttpConnection::HTTP_VERB_GET,"version.txt");
try
{
file->SendRequest(); //THIS STATEMENT crashes the program even though it
is inside a try catch
}
catch (CInternetException pEx)
{
status += "Failed to connect to server!\r\n";
dlg->edit_status.SetWindowText(status);
dlg->GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(1);
return 1;
}
I have tried several different things, but I haven't been able to figure out
how to determine if it was unable to connect with the server.
Am I doing something wrong? Or is there an easier way to do this?
Thanks!
Adam
cabadam@houston.rr.com
|
|
|
|
|
try this:
try
{
http = net.GetHttpConnection("cabadam.homeip.net");
}
catch(CInternetException *ex)
{
...failed...
ex->Delete();
}
hope this helps
|
|
|
|
|
Oh duh!!
On the catch, I had the pEx as CInternetException, not CInternetException*
That did it...
thx
Adam
cabadam@houston.rr.com
|
|
|
|
|
When I fail to define a New Class correctly, how do I remove the New Clas from the project, si I can redifine it?
Richard
|
|
|
|
|
delete the files from the file view (highlight, press delete)
delete the actual files (from Explorer)
delete your .CLW file (from Explorer). this will be regenerated the next time you launch classwiz
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I'm done building my program, but I was just wondering what DLL to include with it. Some of my friend who doesn't own VC++ have trouble running it. Please help...
|
|
|
|
|
Use the Dependency Walker program that comes with MSVC++. It'll show you all the DLLs required to run your application; it's generally a good idea to package those into your installer, and have it install the DLLs if the ones present on the user's system are older.
You don't need to package them all, mind you -- you probably won't need to add Kernel32 into your installer, for example -- but MFC/OLE/COM DLLs should definitely be packaged.
|
|
|
|
|
just a tip: if its an MFC program goto Project>Options and on the combobox change "Debug" to "Release", then choose "Link MFC in static library" instead of "Link MFC dynamically" then click ok. goto Build(or run or comile whatever it says) and click "batch build" then select "Release" and click build. it will now build ur project in a folder called "Release" in ur main project folder, so in it you will find an executable which is linked statically and should contain everything you need.
Kuniva
Want, take, have.
(oh btw, best way of learning some language is by looking at examples, start large!) :p
|
|
|
|
|
Hello.
This portion of code works perfect in an aplication that conect to Access 2000 with a DSN ODBC.
CRecordset rs;
rs.Open(CRecordset::forwardOnly,"SELECT COUNT(*) FROM mytable",CRecordset::readOnly);
short nField=0;
CString str;
rs.GetFieldValue(nField,str);
long NumRecords = atol(LPCSTR(str));
Now I am porting the aplication to works with SQL Server 2000 and this portion of code give me the error: "State:S1002,Native ,Origin:[Microsoft][ODBC SQL Server Driver] Invalid column number".
In MSDN I have found "GetFieldValue calls the ODBC API function SQLGetData. If your driver outputs the value SQL_NO_TOTAL for the actual length of the field value, GetFieldValue throws an exception. For more information about SQLGetData, see the ODBC SDK Programmer's Reference"
I don't know if this is the problem. Anybody can tell me how can I solve this problem?.
Thanks in advance.
Tomás.
|
|
|
|
|
SQL automatically makes column 0 the bookmark column (which is useless unless you're using bookmarks). Start your column numbers at 1.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Thank you Bret.
This is not the solution.
I start with 1 and the error is "The index is not valid or the field name is incorrect".
I think the problem is another but I have no idea.
Tomás
|
|
|
|
|
Are you using a snapshot or dynaset recordset?
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
I am using...
In the constructor:
m_nDefaultType = dynaset;
And to open:
rs.Open(CRecordset::forwardOnly,_T("SELECT COUNT(*) FROM mytable"),CRecordset::readOnly);
|
|
|
|
|
Actually, the anonymous guy is correct. You should use GetRecordCount(). And I believe the reason the other doesn't work is because I think the GetFieldValue gets a column value rather than a returned recordset value. So just do a plain open with a NULL query in order to get the whole recordset then do a GetRecordCount.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Seems like you just want the number of records in the database, so why don't you use the CRecordset::GetRecordCount() function.
|
|
|
|
|
Yes this is a solution, but too slowly because you need to check all the recordset to know the number of records.
MoveFirst();
DoWhile(IsBof()) {
MoveNext();
count++;
}
Is more eficient to do a SELECT COUNT(*) rather a DoWhile().
Tomás
|
|
|
|
|
No. You don't check it like this.
For example:
let's say you have a class CMyRecordset derived from CRecordset, and you use the default SQL, once you open the your RS class all you have to do is this..
CMyRecordset rs(db);
long lNumOfRecords;
rs.Open();
// if opens without any problem..
// this should give you the number of records you are looking for..
lNumOfRecords = rs.GetRecordCount();
|
|
|
|
|
Good day,
Does anyone know what exactly GetSuperWndProc() does? I keep getting this as an unresolved external in my embeddedVC program even though I never call it. If I override it it will compile fine but crashes on execution. I was wondering if anyone knows what its supposed to do so that I can implement it. Thanks.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Are you using any thirdparty libraries?
I don't think it a standard API function. I have never seen it before, and a search on all of MSDN don't get anything...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Sorry, my bad, its GetSuperWndProcAddr(). But no, I'm not using any third party libraries. In MSDN it says its obsolete and I don't need to override it but for some reason eVC keeps telling me its an unresolved external in all of my View classes and in my FrameWnd.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Hmmm, strange...
Anyway, you can read a lot about errors with GetSuperWndProcAddr here
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi there,
I am trying to create a SQL Server DSN using SQLConfigDataSource. Everything
seems ok, except for I can't figure out how to set the password part, to Windows Authentication as opposed to SQL Server Authentication. It appears that the latter one is the default and everytime I run my code it gets set to SQL Server Authentication.
thanks
|
|
|
|
|
add
\0TRUSTED_CONNECTION
to your
SQLConfigDataSource attributes
|
|
|
|
|
I need to prevent my control's drawing while it is loading the page. I'm doing it this way:
In OnBeforeNavigate2():
LockWindowUpdate(); In OnDocumentComplete2():
UnlockWindowUpdate(); And in OnEraseBkgnd():
return true;
That works fine except the one moment: after the page was loaded - my desktop is redrawing. I don't understand why is it do this... It haven't web-style. The running ie doesn't redrawing it's page, but desktop is flickering.
How can I suppress it?
With the best regards, Vitaly.
|
|
|
|
|
I have a dialog box with many different controls and an ok button.
the ok button has focus when starting the dialog.
I have set focus to other controls in the init of the dialog.
the other controls get focus i can type in them but the ok button has focus also and if the enter key is pressed at anytime the dialog exists.
Is there a way that i can stop this from happening?
|
|
|
|