|
kuphryn wrote: operator []
This application is straight 'C', not C++.
'til next we type...
HAVE FUN!! -- Jesse
|
|
|
|
|
krmed wrote: pMyDouble,300
Aha! You've won yourself a cupie doll! That's the Watch Window notation I had forgotten. Thanks a bunch!
'til next we type...
HAVE FUN!! -- Jesse
|
|
|
|
|
You should be able to use either the [] operator or write it as *(myVar + index) -- where myVar is the array and index is the number of the element you want to view.
If you need/want to see the entire array, you might want to open a file and have its output saved to it at various points in time.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: use either the [] operator or write it as *(myVar + index)
and
Zac Howland wrote: want to see the entire array, you might want to open a file
I need the entire array at once, preferably in a file, but I'd like to get it without adding more code to the app.
Another CP user mentioned the myArray,300 notation which display the first 300 members of an array. That should work if I can find a way to capture that to a file.
'til next we type...
HAVE FUN!! -- Jesse
|
|
|
|
|
You can enter the address of the start of the array in the memory window, then cycle through the display formats with Alt+F11 until you come to the right one (there are 14 views - just try them until you see double values )
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I think I got writing the files to the database to work it taking the file out which seems to be the problem. It doesn't give me any errors after the write and when I look into the database I see that a row was correctly inserted and I see under the file field (OLE Object Type) it says "Long binary data". Here is the code I use for that...
struct RS_FILE
{
long m_l_FileID;
CString m_cs_FileName;
CLongBinary m_lb_FileData;
Any Ideas?
bool DB_File_Insert(CDatabase* db, RS_FILE& rs_file, const std::string& s_file_fullname, CErrorHandler& eh)
{
bool b_ret = true;
HGLOBAL hGlobal = NULL;
try
{
CRecordSetFile rs(db);
if (rs.Open() == FALSE)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to open the file record set to insert a new record.");
return false;
}
rs.AddNew();
rs.m_rs_file = rs_file;
CFile cf;
CFileStatus fileStatus;
if (cf.Open(s_file_fullname.c_str(), CFile::modeRead) == FALSE)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to open the file '%s' for inserting into the database.",s_file_fullname.c_str());
b_ret = false;
goto LabelRecordSetFileClose;
}
if (cf.GetStatus(fileStatus) == FALSE)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to get the status of the file '%s' after opening it to insert into the database.",s_file_fullname.c_str());
b_ret = false;
goto LabelFileClose;
}
rs.m_rs_file.m_cs_FileName = cf.GetFileName();
rs.m_rs_file.m_lb_FileData.m_dwDataLength = fileStatus.m_size;
hGlobal = GlobalAlloc(GPTR,fileStatus.m_size);
if (hGlobal == NULL)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to allocate the specified number of bytes '%ld' for copying the file '%s' into for storing into the database.",fileStatus.m_size,s_file_fullname.c_str());
b_ret = false;
goto LabelFileClose;
}
rs.m_rs_file.m_lb_FileData.m_hData = GlobalLock(hGlobal);
cf.ReadHuge(rs.m_rs_file.m_lb_FileData.m_hData,fileStatus.m_size);
rs.SetFieldDirty(&rs.m_rs_file.m_lb_FileData, TRUE );
rs.SetFieldNull(&rs.m_rs_file.m_lb_FileData, FALSE );
if (rs.Update() == FALSE)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to insert the new record into the database.");
b_ret = false;
}
GlobalUnlock(hGlobal);
LabelFileClose:
cf.Close();
LabelRecordSetFileClose:
rs.Close();
}
catch(CDBException* e1)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Database Error: %s",e1->m_strError);
return false;
}
catch(CException* e2)
{
eh.Initialize();
char sz_error [MAX_PATH] = "";
e2->GetErrorMessage(sz_error,sizeof(sz_error));
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Database Error: %s",sz_error);
return false;
}
catch(...)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Database Error: Unknown.");
return false;
}
return b_ret;
}
Now here it the code where I try to get the file and write it to a folder....
bool DB_File_GetID(CDatabase* db, const long& l_id, RS_FILE& rs_file, CErrorHandler& eh)
{
try
{
CRecordSetFile rs(db);
rs.m_strFilter.Format("[FileID] = %ld",l_id);
if (rs.Open() == FALSE)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to open the record set to get the file id '%ld'.",l_id);
return false;
}
rs_file = rs.m_rs_file;
rs.Close();
}
catch(CDBException* e1)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Database Error: %s",e1->m_strError);
return false;
}
catch(CException* e2)
{
eh.Initialize();
char sz_error [MAX_PATH] = "";
e2->GetErrorMessage(sz_error,sizeof(sz_error));
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Database Error: %s",sz_error);
return false;
}
catch(...)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Database Error: Unknown.");
return false;
}
return true;
}
bool RS_FILE::WriteFile(const std::string& s_folder, CErrorHandler& eh)
{
std::string s_temp_folder = s_folder;
if(s_temp_folder.length() == 0)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to write the file to a folder because the folder is not specified.");
return false;
}
if (s_temp_folder[s_temp_folder.length()-1] != '\\')
s_temp_folder += "\\";
std::string s_file = ssprintf("%s%s",s_temp_folder.c_str(),m_cs_FileName);
CFile cf;
if (cf.Open(s_file.c_str(),CFile::modeCreate|CFile::modeWrite) == FALSE)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to open and create the file '%s' to write data to.",s_file.c_str());
return false;
}
LPSTR buffer = (LPSTR)GlobalLock(m_lb_FileData.m_hData);
cf.WriteHuge(buffer,m_lb_FileData.m_dwDataLength);
GlobalUnlock(m_lb_FileData.m_hData);
cf.Close();
return true;
}
The failure is occurring in the CFile look below....
void CFile::Write(const void* lpBuf, UINT nCount)
{
ASSERT_VALID(this);
ASSERT(m_hFile != (UINT)hFileNull);
if (nCount == 0)
return;
ASSERT(lpBuf != NULL);
Any help is greatly appreciated. I know this post is a little long be I am not sure where the error is.
Chris
|
|
|
|
|
chris175 wrote: CFile cf;
if (cf.Open(s_file.c_str(),CFile::modeCreate|CFile::modeWrite) == FALSE)
{
eh.Initialize();
eh.Set(__FUNCTION__,__FILE__,__LINE__,EHTYPE_ERROR,"Failure to open and create the file '%s' to write data to.",s_file.c_str());
return false;
}
LPSTR buffer = (LPSTR)GlobalLock(m_lb_FileData.m_hData);
cf.WriteHuge(buffer,m_lb_FileData.m_dwDataLength); // Failure here.
GlobalUnlock(m_lb_FileData.m_hData);
cf.Close();
The failure is actually happening on the bold line. If GlobalLock fails, it returns NULL. When that happens, you should call GetLastError to see what the problem is.
How big is this block of memory you are writing out?
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
You are right. The function did return NULL. It returned a 6 which is Handle is invalid. I then checked m_lb_FileData.m_hData and it is NULL? I dont know why this is because m_l_FileID = 3 and m_cs_FileName = "Temp.txt"
I know I have the code right in my record set class....I think...
The .h File....
class CRecordSetFile : public CRecordset
{
public:
CRecordSetFile(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(CRecordSetFile)
RS_FILE m_rs_file;
The .cpp File....
RFX_Long(pFX, _T("[FileID]"), m_rs_file.m_l_FileID);
RFX_Text(pFX, _T("[FileName]"), m_rs_file.m_cs_FileName ,RS_FILE_MAX_FILENAME ,SQL_CHAR);
RFX_LongBinary(pFX, _T("[FileData]"), m_rs_file.m_lb_FileData);
|
|
|
|
|
Check the database table and make sure the filename isn't null. If it isn't, make sure that your recordset actually has valid data in it when you get to that point (you might have to call MoveNext or MoveFirst to get it properly initialized).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I checked the other fields and they are not null. The file id is 3 and the filename is "temp.txt". But for some reason the CLongBinary Field is null?
Chris
|
|
|
|
|
The LongBinary data is null in your program or in the actual database? Check to make sure there is actually data in that field in the database (if it is null in the database, your program has no hope of having a non-null value :P).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thank you for all your responses. I really appreciate the help...
I don’t think the data in the database is null. If I try to store a null value into the database I get an error because the field is required and will not allow null values to be stored in the database in this field. Have any other possibilities?
Chris
|
|
|
|
|
The only other thing I can suggest is to search for issues with ADO and BLOBs. I don't remember having issues with them in the past, but it has been a while since I used them.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks for all the help....
Chris
|
|
|
|
|
I have great news. I finally figured it out. The problem was neither storing the file into the data nor getting the file out of the database. The problem was in my function to retreive the file out of the database I overloaded the = operator to copy RS_FILEs to each other and didn't copy a CLongBinary to the new CLongBinary. After doing this everything works perfectly.
Chris
|
|
|
|
|
Hello,
I'm having an issued figuring out how to use wininet to post form data to a website. So far I've been able to connect, send requests, and then read the result. However, I cannot seem to send form data to the website, and then read the resulting html the server sends back., (I.E. filling out the search form on the codeproject website.) I'm using the MFC version of wininet.
I connect:
CHttpConnection* pHttpConnection = sess.GetHttpConnection("www.codeproject.com");
sess is the CInternetSession object.
Then I create a request:
CHttpFile* pFile = pHttpConnection->OpenRequest("POST", "/");
CString header = _T("Content-Type: application/x-www-form-urlencoded");
CString mdata = _T("Search=wininet help");
pFile->SendRequest(header, header.GetLength(), (LPVOID)(LPCTSTR)mdata, mdata.GetLength());
When I do a pFile->Read() however, all i have received is the codeproject homepage, not the result from entering "wininet help" into the search form. Do I need to format the header differently? Or am I not requesting the correct object with OpenRequest? What am I missing?
Any help on this would be much appriciated. I'm new to wininet, and to writing internet client applications, so please bear with me, heh.
Thanks.
|
|
|
|
|
epicyeti wrote: CHttpFile* pFile = pHttpConnection->OpenRequest("POST", "/");
Last time I checked, there was no action associatd with the root/index for CP. I believe you want it to read:
CHttpFile* pFile = pHttpConnection->OpenRequest("POST", "/info/search.asp");
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Ok, so the object parameter(the second one) of OpenRequest should be the Action that is in the form. Do I need to parse the html to find this or is there an easier way to enter the form data? Also, how should the form data that i want to enter be formated? I tried:
CString mdata = _T("Search=wininet");
but it didn't seem to work.
btw, I like your sig.
|
|
|
|
|
The second parameter to OpenRequest will be an executable (cgi script, asp page, dll, etc). You will need to parse the HTML to see what fields they have (you can use a GET request on "/" to do that). Its been a while since I used POST in the raw form, but it should be something like "target=wininet" (the name of the form is "Search", but the field you are concerned with is named "target"). If there are multiple fields, they should be separated by a "&" (e.g. "field1=value&field2=another%20value ... etc").
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Sweet, thanks a lot man. I might have more questions, but i'm good for now.
|
|
|
|
|
|
I've created a Dialog that after some input collects data until the buffer is full or the user click on the Stop button.
The problem I'm having is I have a while loop the does the data collection code and once my gui has entered this loop all buttons in the dialog box have no functionality... (I can't click on anything). How would I check to see if the user has clicked on the "stop" button?
At 1st I thought maybe:
<br />
while( ... || ... || (m_nStopBtn.GetCheck() )<br />
{<br />
...<br />
}<br />
but that didn't work since the gui won't let me click on the stop button...
What could I be doing wrong?
Thanks,
Kitty5
|
|
|
|
|
you shouldn't put huge processes into the GUI thread...
move that loop into a worker thread to avoid the GUI to be frozen
|
|
|
|
|
You beat me to that answer :P
Also, make sure you use proper synchronization objects when doing this (do NOT just try to check a boolean variable each iteration of the loop to see if you should stop!).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
:->
Zac Howland wrote: NOT just try to check a boolean variable each iteration of the loop to see if you should stop!
of course
|
|
|
|
|